Programming Project 3 
Instant Insanity 
by 
 
Michael Briseno 
Sean Buckley 
Varatep Buranintu 
Dragos Guta 
David Wu 
 
 
 
 
 
 
 
 
 
 
 
 
 
Abstract 
For the notorious ​Instant Insanity​ problem, we decided to take a general approach that is 
slow, but sure to work. Dealing with instant insanity can be pretty difficult. However, if 
programmed correctly, we can continue to find faster ways to get this NP­Complete algorithm 
working faster. Solving algorithms that are np­complete can be extremely beneficial to the study 
of mathematics and computer science, seeing that there is a millennium prize problem including 
NP­Complete problems (prove or disprove ​P​ = ​NP​).  
 
 
Method 
Our recursive approach (using Python) was to check every pair on every line, and if the 
numbers on that line hadn’t already been counted twice, then add that pair and go to the next 
line (cube); otherwise go to the next pair. If all pairs have been checked, then we’ve reached a 
dead end and need to return to the previous line (cube) and try the next pair, and so on and so 
forth, recursively. 
 
Pseudocode 
Create an array of length 40 (from [0] to [39]) called countArray to store the counts of all 
numbers created; initialize each index to 0. 
 
//Recursion steps through each cube (line) and performs checks, starting with the first pair of the 
first cube 
 
Recursion(cubeArray, cubeIndex, generatedSolution): 
Base case​: 
if index == 40 
//then we’ve reached the end without any conflicts 
print generatedSolution 
return 
Recursive case: 
For each pair on the cube 
If pair number 1’s countArray index value != 2 
and if pair number 2’s countArray 
increment those indices in countArray 
make a note of which pair was chosen 
add that pair to the solution list 
Recurse(cubeArray, cubeIndex+1, generatedSolution) 
} 
} 
//if a pair was noted, decrement the indices of the noted pair in countArray 
//then loop back to the beginning and check the next pair 
} 
return 
Python implementation of pseudocode: 
1. def​compareIt(arr,genList):
2. ​for​i​in​xrange(len(arr[0])):
3. genList[i]=arr[0][i]​#storethefirstpair
4. ​print​(​"Firststoredpair:"​,genList[i])
5. recurse(arr,1,genList)​#recursetothenextline
6.
7. def​recurse(arr,ind,genList):
8. ​if​ind==40:
9. ​print​(​"Solutionis:"​,genList)
10. ​else​:
11. ​#print("hitelse")
12. ​for​i​in​xrange(len(arr[ind])):
13. ​#print("iis",i)
14. ​#print("arraypair:",arr[ind][i])
15. pair=arr[ind][i]​#selectapair
16. ​for​i​in​xrange(ind):​#selecteachpreviouslineingenList
17. ​#print("currentgenListis:")
18. ​for​r​in​xrange(ind):
19. ​print​(genList[r])
20. ​#print("pair[0]is",pair[0],"genList[i][0]is:",genList[i][0])
21. ​if​pair[0]!=genList[i][0]:
22. ​#noproblem,checkotheritem
23. ​if​pair[1]!=genList[i][1]:
24. ​#noproblem,addpair
25. genList[i+1]=pair
26. ​#print("Recursed")
27. recurse(arr,ind+1,genList)
28. ​else​:
29. ​#problem,don'tadd
30. c=0
31. ​#endif
32. ​else​:
33. ​#problem,don'tadd
34. c=0
35. ​#endif
36. ​#endfor
37. ​#endfor
38. ​#endif
39.#endrecurse
 
 
Analysis  
The time complexity of this algorithm is O(n^4). In order to reduce the actual execution 
time of the program, a Hadoop cluster could be used with an advanced message queue 
protocol such as RabbitMQ. RabbitMQ can be used to distribute bits and pieces of the required 
computation to separate machines in each cluster. Hadoop is used for distributing processing 
power and computations of a large data set throughout multiple clusters of computers. The 
execution time of an optimized algorithm then relies heavily on how much computational 
resources you can spare for the clusters. You would have a machine passing all of the data 
required to be processed to the messaging queue (in this case, RabbitMQ). The messaging 
queue then acknowledges this and distributes it to a machine within a cluster, making sure that 
each machine never receives the same computation again. Dynamic programming can also 
come into play with this advanced messaging queue protocol and clusters by storing solved 
puzzles or paths into a single data source, which we can then use as an acting filter to ensure 
that the same computations are never re­processed. If a chunk of data comes in which has 
already been computed, the “filter” will instantly spit back the already­computed data set. Aside 
from using distributed computing methods to solve something of high caliber like 40­cubed 
Instant Insanity​ problem with a much faster execution time, small adjustments to the time 
complexity in the algorithm can greatly reduce the execution time for the data set as a whole. 
 
For our solutions, we were able to find within the limited time and with limited computational 
resources as follows: 
 
Solution 1: 
[ 0, 2, 1, 2, 0, 2, 1, 1, 0, 0, 2, 2, 1, 1, 0, 0, 1, 0, 1, 2, 0, 1, 1, 1, 1, 0, 1, 2, 1, 0, 1, 2, 0, 2, 2, 1, 0, 1, 
1, 1 ] 
 
[ 1, 0, 2, 0, 2, 1, 0, 2, 1, 1, 0, 1, 0, 0, 2, 2, 2, 1, 0, 0, 1, 0, 0, 2, 2, 1, 2, 0, 2, 2, 0, 1, 2, 0, 1, 0, 2, 2, 
0, 0 ] 
 
Solution 2: 
[ 0, 2, 1, 2, 0, 2, 1, 1, 0, 0, 2, 2, 1, 1, 0, 0, 1, 0, 1, 2, 0, 1, 1, 1, 1, 0, 1, 2, 1, 0, 1, 2, 0, 2, 2, 1, 0, 1, 
1, 1 ] 
 
[ 2, 1, 0, 1, 1, 0, 2, 0, 2, 2, 1, 0, 2, 2, 1, 1, 0, 2, 2, 1, 2, 2, 2, 0, 0, 2, 0, 1, 0, 1, 2, 0, 1, 1, 0, 2, 1, 0, 
2, 2 ] 
 
Solution 3: 
[ 1, 0, 2, 0, 2, 1, 0, 2, 1, 1, 0, 1, 0, 0, 2, 2, 2, 1, 0, 0, 1, 0, 0, 2, 2, 1, 2, 0, 2, 2, 0, 1, 2, 0, 1, 0, 2, 2, 
0, 0 ] 
 
[ 2, 1, 0, 1, 1, 0, 2, 0, 2, 2, 1, 0, 2, 2, 1, 1, 0, 2, 2, 1, 2, 2, 2, 0, 0, 2, 0, 1, 0, 1, 2, 0, 1, 1, 0, 2, 1, 0, 
2, 2 ] 
 
These three different solutions represent the indexes of the original array that was 
provided for the problem. For example in the first thread, the 0 corresponds to index 0 of the 
problem array, followed by the colors at index 2, followed by the colors at index 1, then 2 and so 
on and so forth. Each solution also has two threads which represent the four total sides.  
 
 
 
Conclusion 
Our implementation in terms of the programming and algorithm for this problem was 
rather primitive. Our overall program took us a few hours to actually finish. We can further 
reduce the time by implementing some form of dynamic programming or distributed computing 
as mentioned earlier. The amount of time is directly related to the amount of cubes as well. 
Furthermore, we were also able to find a solver for N < 30 amount of cubes as well, 
implemented in JavaScript by Chris Reeser, published on his website at 
http://genxtao.com/insinstothen/solver.html​. 
 

More Related Content

PPTX
Naive string matching
PPT
Naive String Matching Algorithm | Computer Science
PPTX
String Match | Computer Science
PPT
Pattern matching
PPTX
Automatski - NP-Complete - TSP - Travelling Salesman Problem Solved in O(N^4)
PDF
P versus NP
PDF
27 NP Completness
PDF
9. chapter 8 np hard and np complete problems
Naive string matching
Naive String Matching Algorithm | Computer Science
String Match | Computer Science
Pattern matching
Automatski - NP-Complete - TSP - Travelling Salesman Problem Solved in O(N^4)
P versus NP
27 NP Completness
9. chapter 8 np hard and np complete problems

Viewers also liked (7)

PDF
Project1Math482
PDF
Omraam mikhael aivanhov reguli de aur
PPTX
T.riggins finalslideshow
DOCX
PDF
เศรษฐศาสตร์แนวพุทธ
PPTX
cdSummit Austin - The Future of Enterprise Service Mangagement in a DevOps Wo...
PDF
cdSummit Austin - Jez Humble: CD Architecture
Project1Math482
Omraam mikhael aivanhov reguli de aur
T.riggins finalslideshow
เศรษฐศาสตร์แนวพุทธ
cdSummit Austin - The Future of Enterprise Service Mangagement in a DevOps Wo...
cdSummit Austin - Jez Humble: CD Architecture
Ad

Similar to InstantInsanityProgrammingAssignment (20)

PPTX
Data structure and algorithms lecture22 presentation
PDF
Np completeness
PPTX
Limits of Computation
PPTX
The Limits of Computation
PPT
Time andspacecomplexity
PPTX
DAA UNIT 3
PDF
P, NP, NP-Complete, and NP-Hard
PDF
An Inductive inference Machine
PDF
Academic paper - Final
PPTX
2.03.Asymptotic_analysis.pptx
PPT
the halting_problem
PPTX
Into to prob_prog_hari
PDF
DISMATH_Part2
PPT
class23.ppt
PDF
AI Lesson 29
PDF
Lesson 29
PDF
Introduction to Bayesian Analysis in Python
PDF
Dismath part2 2013
KEY
Preemptive RANSAC by David Nister.
PPT
2009 CSBB LAB 新生訓練
Data structure and algorithms lecture22 presentation
Np completeness
Limits of Computation
The Limits of Computation
Time andspacecomplexity
DAA UNIT 3
P, NP, NP-Complete, and NP-Hard
An Inductive inference Machine
Academic paper - Final
2.03.Asymptotic_analysis.pptx
the halting_problem
Into to prob_prog_hari
DISMATH_Part2
class23.ppt
AI Lesson 29
Lesson 29
Introduction to Bayesian Analysis in Python
Dismath part2 2013
Preemptive RANSAC by David Nister.
2009 CSBB LAB 新生訓練
Ad

InstantInsanityProgrammingAssignment