SlideShare a Scribd company logo
1 of 5
Download to read offline
 
 
 
 
 
 
 
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

Viewers also liked

Omraam mikhael aivanhov reguli de aur
Omraam mikhael aivanhov   reguli de aurOmraam mikhael aivanhov   reguli de aur
Omraam mikhael aivanhov reguli de aurTraian Atanasiu
 
T.riggins finalslideshow
T.riggins finalslideshowT.riggins finalslideshow
T.riggins finalslideshowMrsRiggins
 
เศรษฐศาสตร์แนวพุทธ
เศรษฐศาสตร์แนวพุทธเศรษฐศาสตร์แนวพุทธ
เศรษฐศาสตร์แนวพุทธfhumtct
 
cdSummit Austin - The Future of Enterprise Service Mangagement in a DevOps Wo...
cdSummit Austin - The Future of Enterprise Service Mangagement in a DevOps Wo...cdSummit Austin - The Future of Enterprise Service Mangagement in a DevOps Wo...
cdSummit Austin - The Future of Enterprise Service Mangagement in a DevOps Wo...Miles Blatstein
 
cdSummit Austin - Jez Humble: CD Architecture
cdSummit Austin - Jez Humble: CD ArchitecturecdSummit Austin - Jez Humble: CD Architecture
cdSummit Austin - Jez Humble: CD ArchitectureMiles Blatstein
 

Viewers also liked (7)

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

Similar to InstantInsanityProgrammingAssignment

Similar to InstantInsanityProgrammingAssignment (20)

Np completeness
Np completeness Np completeness
Np completeness
 
Limits of Computation
Limits of ComputationLimits of Computation
Limits of Computation
 
The Limits of Computation
The Limits of ComputationThe Limits of Computation
The Limits of Computation
 
Time andspacecomplexity
Time andspacecomplexityTime andspacecomplexity
Time andspacecomplexity
 
DAA UNIT 3
DAA UNIT 3DAA UNIT 3
DAA UNIT 3
 
P, NP, NP-Complete, and NP-Hard
P, NP, NP-Complete, and NP-HardP, NP, NP-Complete, and NP-Hard
P, NP, NP-Complete, and NP-Hard
 
An Inductive inference Machine
An Inductive inference MachineAn Inductive inference Machine
An Inductive inference Machine
 
Academic paper - Final
Academic paper - FinalAcademic paper - Final
Academic paper - Final
 
2.03.Asymptotic_analysis.pptx
2.03.Asymptotic_analysis.pptx2.03.Asymptotic_analysis.pptx
2.03.Asymptotic_analysis.pptx
 
the halting_problem
the halting_problemthe halting_problem
the halting_problem
 
Into to prob_prog_hari
Into to prob_prog_hariInto to prob_prog_hari
Into to prob_prog_hari
 
DISMATH_Part2
DISMATH_Part2DISMATH_Part2
DISMATH_Part2
 
class23.ppt
class23.pptclass23.ppt
class23.ppt
 
AI Lesson 29
AI Lesson 29AI Lesson 29
AI Lesson 29
 
Lesson 29
Lesson 29Lesson 29
Lesson 29
 
Introduction to Bayesian Analysis in Python
Introduction to Bayesian Analysis in PythonIntroduction to Bayesian Analysis in Python
Introduction to Bayesian Analysis in Python
 
Dismath part2 2013
Dismath part2 2013Dismath part2 2013
Dismath part2 2013
 
Preemptive RANSAC by David Nister.
Preemptive RANSAC by David Nister.Preemptive RANSAC by David Nister.
Preemptive RANSAC by David Nister.
 
2009 CSBB LAB 新生訓練
2009 CSBB LAB 新生訓練2009 CSBB LAB 新生訓練
2009 CSBB LAB 新生訓練
 
The Complexity Of Primality Testing
The Complexity Of Primality TestingThe Complexity Of Primality Testing
The Complexity Of Primality Testing
 

InstantInsanityProgrammingAssignment