SlideShare a Scribd company logo
 
 
 
 
 
 
 
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] ​#store the first pair  
4.         ​print​(​"First stored pair:"​,genList[i])  
5.         recurse(arr, 1, genList) ​# recurse to the next line  
6.   
7. def​ recurse(arr, ind, genList):  
8.     ​if​ ind == 40:  
9.         ​print​ (​"Solution is: "​,genList)  
10.    ​else​:  
11.        ​#print("hit else")  
12.        ​for​ i ​in​ xrange(len(arr[ind])):  
13.            ​#print("i is ",i)  
14.            ​#print ("array pair: ",arr[ind][i])  
15.            pair = arr[ind][i] ​#select a pair  
16.            ​for​ i ​in​ xrange(ind): ​#select each previous line in genList  
17.                ​#print("current genList is: ")  
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.                    ​#no problem, check other item  
23.                    ​if​ pair[1] != genList[i][1]:  
24.                        ​#no problem, add pair  
25.                        genList[i+1] = pair  
26.                        ​#print("Recursed")  
27.                        recurse(arr, ind+1, genList)  
28.                    ​else​:  
29.                        ​#problem, don't add  
30.                        c = 0  
31.                    ​#endif  
32.                ​else​:  
33.                    ​#problem, don't add  
34.                    c = 0  
35.                ​#endif  
36.            ​#endfor  
37.        ​#endfor  
38.    ​#endif  
39.#end recurse  
 
 
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

class portfolio
class portfolioclass portfolio
class portfolio
Hayley Bagwell
 
Odpowiedź godziny włączania latarni
Odpowiedź godziny włączania latarniOdpowiedź godziny włączania latarni
Odpowiedź godziny włączania latarni
marcingermanek
 
Pismo do starosty pszczyńskiego ws. ścieżki rowerowej w Gminie Miedźna
Pismo do starosty pszczyńskiego ws. ścieżki rowerowej w Gminie MiedźnaPismo do starosty pszczyńskiego ws. ścieżki rowerowej w Gminie Miedźna
Pismo do starosty pszczyńskiego ws. ścieżki rowerowej w Gminie Miedźna
marcingermanek
 
Moreno navarrete
Moreno navarreteMoreno navarrete
Moreno navarrete
UAM AZC
 
Gzgk odpowiedź
Gzgk odpowiedźGzgk odpowiedź
Gzgk odpowiedź
marcingermanek
 
Workshop MAKING SUCCESSFUL PRESENTATION
Workshop MAKING SUCCESSFUL PRESENTATIONWorkshop MAKING SUCCESSFUL PRESENTATION
Workshop MAKING SUCCESSFUL PRESENTATION
Macom Digital Studio
 
Esquema comparativo del rol del docente y el estudiante tradicional y actual.
Esquema comparativo del rol del docente y el estudiante tradicional y actual.Esquema comparativo del rol del docente y el estudiante tradicional y actual.
Esquema comparativo del rol del docente y el estudiante tradicional y actual.
Fe Maria Holguin Bencosme
 
POとPOじゃない人の勉強会 第14回
POとPOじゃない人の勉強会 第14回POとPOじゃない人の勉強会 第14回
POとPOじゃない人の勉強会 第14回
pepabo-po
 

Viewers also liked (8)

class portfolio
class portfolioclass portfolio
class portfolio
 
Odpowiedź godziny włączania latarni
Odpowiedź godziny włączania latarniOdpowiedź godziny włączania latarni
Odpowiedź godziny włączania latarni
 
Pismo do starosty pszczyńskiego ws. ścieżki rowerowej w Gminie Miedźna
Pismo do starosty pszczyńskiego ws. ścieżki rowerowej w Gminie MiedźnaPismo do starosty pszczyńskiego ws. ścieżki rowerowej w Gminie Miedźna
Pismo do starosty pszczyńskiego ws. ścieżki rowerowej w Gminie Miedźna
 
Moreno navarrete
Moreno navarreteMoreno navarrete
Moreno navarrete
 
Gzgk odpowiedź
Gzgk odpowiedźGzgk odpowiedź
Gzgk odpowiedź
 
Workshop MAKING SUCCESSFUL PRESENTATION
Workshop MAKING SUCCESSFUL PRESENTATIONWorkshop MAKING SUCCESSFUL PRESENTATION
Workshop MAKING SUCCESSFUL PRESENTATION
 
Esquema comparativo del rol del docente y el estudiante tradicional y actual.
Esquema comparativo del rol del docente y el estudiante tradicional y actual.Esquema comparativo del rol del docente y el estudiante tradicional y actual.
Esquema comparativo del rol del docente y el estudiante tradicional y actual.
 
POとPOじゃない人の勉強会 第14回
POとPOじゃない人の勉強会 第14回POとPOじゃない人の勉強会 第14回
POとPOじゃない人の勉強会 第14回
 

Similar to InstantInsanityProgrammingAssignment

Np completeness
Np completeness Np completeness
Np completeness
tusharKanwaria
 
Limits of Computation
Limits of ComputationLimits of Computation
Limits of Computation
Joshua Reuben
 
The Limits of Computation
The Limits of ComputationThe Limits of Computation
The Limits of Computation
Joshua Reuben
 
Time andspacecomplexity
Time andspacecomplexityTime andspacecomplexity
Time andspacecomplexity
LAKSHMITHARUN PONNAM
 
DAA UNIT 3
DAA UNIT 3DAA UNIT 3
DAA UNIT 3
SURBHI SAROHA
 
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
Animesh Chaturvedi
 
An Inductive inference Machine
An Inductive inference MachineAn Inductive inference Machine
An Inductive inference Machine
Aly Abdelkareem
 
Academic paper - Final
Academic paper - FinalAcademic paper - Final
Academic paper - Final
Shadrack Mwaniki
 
2.03.Asymptotic_analysis.pptx
2.03.Asymptotic_analysis.pptx2.03.Asymptotic_analysis.pptx
2.03.Asymptotic_analysis.pptx
ssuser1fb3df
 
the halting_problem
the halting_problemthe halting_problem
the halting_problem
Rajendran
 
Into to prob_prog_hari
Into to prob_prog_hariInto to prob_prog_hari
Into to prob_prog_hari
Hariharan Chandrasekaran
 
DISMATH_Part2
DISMATH_Part2DISMATH_Part2
DISMATH_Part2
Melvin Cabatuan
 
class23.ppt
class23.pptclass23.ppt
class23.ppt
AjayPratap828815
 
Lesson 29
Lesson 29Lesson 29
Lesson 29
Avijit Kumar
 
AI Lesson 29
AI Lesson 29AI Lesson 29
AI Lesson 29
Assistant Professor
 
Introduction to Bayesian Analysis in Python
Introduction to Bayesian Analysis in PythonIntroduction to Bayesian Analysis in Python
Introduction to Bayesian Analysis in Python
Peadar Coyle
 
Dismath part2 2013
Dismath part2 2013Dismath part2 2013
Dismath part2 2013
Melvin Cabatuan
 
Preemptive RANSAC by David Nister.
Preemptive RANSAC by David Nister.Preemptive RANSAC by David Nister.
Preemptive RANSAC by David Nister.
Ian Sa
 
2009 CSBB LAB 新生訓練
2009 CSBB LAB 新生訓練2009 CSBB LAB 新生訓練
2009 CSBB LAB 新生訓練
Abner Huang
 
The Complexity Of Primality Testing
The Complexity Of Primality TestingThe Complexity Of Primality Testing
The Complexity Of Primality Testing
Mohammad Elsheikh
 

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
 
Lesson 29
Lesson 29Lesson 29
Lesson 29
 
AI Lesson 29
AI Lesson 29AI Lesson 29
AI 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