AlexisTM
: AlexisTM
AlexisTM |
this documentation is autogenerated. Add a README.adoc
to your solution to take over the control of this :-)
Demons wants entertainment 'n' hatred 'n' souls
Cast souls into souls
Cast hatred into hatred
Cast entertainment into entertainment
Put souls plus hatred plus entertainment into the destiny
Give back the destiny
Listen to the entertainment
Listen to the hatred
Listen to the souls
Put Demons taking the entertainment, the hatred, and the souls into Hell
My soul is nowhere
While the entertainment ain't mysterious
Put Demons taking the entertainment, the hatred, and the souls into Heaven
If Heaven is greater than Hell
Build my soul up
Put the hatred in the entertainment
Put the souls in the hatred
Put Heaven in Hell
Listen to the entertainment
Whisper my soul
My soul is nowhere
Listen to the wind
Listen to the fire
While the fire ain't mysterious
If the fire is greater than the wind
Build my soul up
Put the fire into the wind
Listen to the fire
Whisper my soul
this documentation is autogenerated. Add a README.adoc
to your solution to take over the control of this :-)
The pirate is BlackBeard
Black Beard is degenerated
Pirates are delinquent
Captain Seadog is recidivist
Red Beard is despiteful
Strength was for me
Cast strength into my fist
Listen to the rules
While the rules ain't nothing
Shatter the rules with my fist
Put the rules at The pirate in Command
Put the rules at Black Beard in the sea
Cast the sea
If Command is "forward"
Let Captain Seadog be Captain Seadog with the sea
Let Pirates be Pirates with Red Beard of the sea
If Command is "down"
Let Red Beard be Red Beard with the sea
If Command is "up"
Let Red Beard be Red Beard without the sea
Listen to the rules
Say Captain Seadog of Pirates
this documentation is autogenerated. Add a README.adoc
to your solution to take over the control of this :-)
(Compute for an initial number, the final number of fishes)
Aquarium Shop wants Nemo
Rock the aquarium with Nemo
Dory is carefree
Free is shabby
Errors are pufferfishs
The dirt is possibly disgusting
While the dirt ain't nothing
Knock the dirt down
Let the goal be the aquarium
The fishes are developing
While the fishes are smaller than the goal
If The aquarium at the fishes ain't nothing
Let the aquarium at the fishes be the aquarium at the fishes minus errors
Else
Let the aquarium at the fishes be free
Rock the aquarium with Dory
Build the fishes up
Give back the aquarium
(Precompute 1, 2, 3, 4, 5, possible values of the input)
Shop Preparation wants something
Rock the Shop
The owners are ready
While the owners ain't nothing
Put Aquarium Shop taking the owners into the shop at the owners
Knock the owners down
Give back the Shop
Put Shop Preparation taking nothing into Beautiful Aquarium
A brick is real hard
Cast a brick
Listen to the glass
Shatter the glass with a brick
Let sharks be the glass
Deb is damselfish
The characters are clownfishs
While Deb is weaker than sharks
Put the glass at Deb into the temp
Cast the temp
Let the characters be Beautiful Aquarium at the temp with the characters
Build Deb up
Say the characters
# Rockstar
There are multiple implementations, increasing speed for the very slow rockstar
## Naive implementation: naive.rock
The naive implementation is writting down the problem as it is exposed, with a list simulating all states at once, following the rules.
This provides the result in 2 minutes for the first step so few years for the second, with an horrible memory complexity (Playing with an array of 360k elements, dynamically pushing to it)
## Slightly optimized: precompute.rock
The slightly optimized solution is based out of the following two observations:
- All inputs are in the `[1-5]` range
- The result equals to the sum of the individual inputs
Therefore, we can precompute an array for each possible input, then simply sum the precomputed result, which executes in one second.
## Hashtable optimization: rock.py
While the naive implementation just works in Python, even the basic optimization is not enough for rockstar.
Starting from the slightly optimized, we are using those observations:
- All inputs are in the `[1-5]` range
- The result equals to the sum of the individual inputs
- The individual steps can be fast forwarded as a number will always give the same result N iterations later
- We can reach half of the problem then simply double the number of iteration without having the full memory complexity
The steps are:
- Make an hashtable for 16 iterations: "For each number, what would be the fish state after 16 iterations"
- Apply the hashtable 8 times over the input => Equivalent to 128 iterations
- Double the iterations (Reflect) by using the result at 128 iterations and computing the final size it would have, without doing the iterations
Additional optimization possible: We don't have to compute the hashtable for each iterations, we could simply compute it for the value 5, then value 4 is 5 + one iteration etc.
## Best method
The best method is to express mathematically the problem so you can precompute the contribution of each input without doing any iterations.
## Hashtable 16
| Input | Day for input 0 | Result after 16 days for input |
|-------|-----------------|--------------------------------|
| | 0 | 0 |
| | 1 | 68 |
| | 2 | 57 |
| | 3 | 46 |
| | 4 | 35 |
| | 5 | 24 |
| | 6 | 13 |
| | 7 | 02 |
| 8 | 8 | 618 |
| 7 | 9 | 507 |
| 6 | 10 | 4668 |
| 5 | 11 | 3557 |
| 4 | 12 | 2446 |
| 3 | 13 | 1335 |
| 2 | 14 | 0224 |
| 1 | 15 | 61138 |
| 0 | 16 | 50027 |
James Cameroun is some fool
Cast James Cameroun
Listen to the movie
The skill is possibly primordial
Shatter the movie with James Cameroun
While the skill ain't nothing
Knock the skill down
Let the actors be the movie
The realisator is convincing
While The realisator is weaker than the actors
If the movie at The realisator ain't nothing
Let the movie at The realisator be the movie at The realisator minus 1
Else
Let the movie at The realisator be 6
Rock the movie with 8
Build The realisator up
Say the movie
Say "Hashtable for 16 iterations"
Rock Hashy with "50027", "61138", "0224", "1335", "2446", "3557", "4668", "507", "618"
(Do 16 iterations at once)
QuickChange wants the array
Rock Quickiter One
While the array ain't nothing
Roll the array into Val
If Hashy at Val is mysterious
Cast Val
Rock Quickiter One with Hashy at Val
Join Quickiter One
Shatter Quickiter One
Give back Quickiter One
Say "Precomputation up to 128"
(Precompute 0, 1, 2, 3, 4, 5, 6, 7, 8 possible values of the number)
the max is 8
Count is 0
Rock the taxes
Rock a reduction
While Count is not as great as the max plus 1
The iteration is nothing
Rock the iteration with 1
Roll the iteration
Roll the iteration
Rock the iteration with Count
Put QuickChange taking the iteration into the iteration
Put QuickChange taking the iteration into the iteration
Put QuickChange taking the iteration into the iteration
Put QuickChange taking the iteration into the iteration
Put QuickChange taking the iteration into the iteration
Put QuickChange taking the iteration into the iteration
Put QuickChange taking the iteration into the iteration
Put QuickChange taking the iteration into the iteration
Rock the taxes with the iteration
Build Count up
Say "Reflection from 128 to 256"
(Reflection for 1-5)
the reflection is 5
Rock Final Hashtable with 42
While the reflection is greater than nothing
The total is 0
Count is 0
Let Size be the taxes at the reflection of 1
Let Array be the taxes at the reflection
While Count is less than Size
Let Val be Array at Count
Cast Val
Let the total be the total with the taxes at Val of 1
Build Count up
Let Final Hashtable at the reflection be the total
Knock the reflection down
Say "Solving input..."
The comma is four four
Cast the comma
Final Result is 0
Listen to the problem
Shatter the problem with the comma
While the problem ain't nothing
Roll the problem into Val
Cast Val
Let Final Result be with Final Hashtable at Val
Say Final Result
# (After 16 iterations hashtable)
HashTable16 = [
"50027",
"61138",
"0224",
"1335",
"2446",
"3557",
"4668",
"507",
"618"
]
file = open("input.txt", "r")
val_input = [int(num) for num in file.readline().split(",")]
def QuickChange(array):
iter = []
for val in array:
# while len(array) > 0:
# val = array.pop()
iter.append(HashTable16[int(val)])
iter = "".join(iter)
return iter
def ShopPreparation(max=8):
shop = [0]*(max+1)
while max >= 0:
iteration = [max]
iteration = QuickChange(iteration)
iteration = QuickChange(iteration)
iteration = QuickChange(iteration)
iteration = QuickChange(iteration)
iteration = QuickChange(iteration)
iteration = QuickChange(iteration)
iteration = QuickChange(iteration)
iteration = QuickChange(iteration)
shop[max] = iteration
max = max - 1
return shop
def Reflect(shop, max):
final_hashtable = [0]*(max+1)
while max > 0:
total = 0
array = shop[max]
for val in array:
ival = int(val)
total = total + len(shop[ival])
final_hashtable[max] = total
max = max - 1
return final_hashtable
shop = ShopPreparation(8)
final_hashtable = Reflect(shop, 5)
total = 0
for val in val_input:
total = total + final_hashtable[val]
print(total)
4,3,4,5,2,1,1,5,5,3,3,1,5,1,4,2,2,3,1,5,1,4,1,2,3,4,1,4,1,5,2,1,1,3,3,5,1,1,1,1,4,5,1,2,1,2,1,1,1,5,3,3,1,1,1,1,2,4,2,1,2,3,2,5,3,5,3,1,5,4,5,4,4,4,1,1,2,1,3,1,1,4,2,1,2,1,2,5,4,2,4,2,2,4,2,2,5,1,2,1,2,1,4,4,4,3,2,1,2,4,3,5,1,1,3,4,2,3,3,5,3,1,4,1,1,1,1,2,3,2,1,1,5,5,1,5,2,1,4,4,4,3,2,2,1,2,1,5,1,4,4,1,1,4,1,4,2,4,3,1,4,1,4,2,1,5,1,1,1,3,2,4,1,1,4,1,4,3,1,5,3,3,3,4,1,1,3,1,3,4,1,4,5,1,4,1,2,2,1,3,3,5,3,2,5,1,1,5,1,5,1,4,4,3,1,5,5,2,2,4,1,1,2,1,2,1,4,3,5,5,2,3,4,1,4,2,4,4,1,4,1,1,4,2,4,1,2,1,1,1,1,1,1,3,1,3,3,1,1,1,1,3,2,3,5,4,2,4,3,1,5,3,1,1,1,2,1,4,4,5,1,5,1,1,1,2,2,4,1,4,5,2,4,5,2,2,2,5,4,4