The Golfer Adventure
This is the first challenge ! There will be more challenges later that will require data from the previous challenge :)
Chapter 1 : The Vase
Let's imagine a minute.. You are a powerful God, your powers are limitless but require one thing : Souls. Each soul is here represented by a byte, each byte you use does sacrifice a soul. So the goal is obviously to save the biggest amount of people while sacrificing the least amount of souls.
Your first challenge is to save a little village, the devil is willing not to destroy the entire village if you resolve his challenge.
The Challenge :
You have a vertical vase which can contain exactly 10 things (Air included). If you put a thing in that vase, gravity will make that thing fall to the bottom. If the vase is already full (and it's always full if you consider it as "full of air"), the input will replace the element at the top of the vase.
Here is the set of allowed things :
- Air
0 /
- A Rock
1 / -
- A Leaf
2 / ~
- A Bomb
3 / x
If there is a rock or a leaf on top of "A Bomb", it will explode and destroy the thing on the top of it.
The input is the list of the things you'll put in the vase every turn.
Example : 11231 : You'll put 2 rocks, then a leaf, then a bomb and finally a last rock.
When the vase is static, you can begin to count with the following rule :
- Rock adds 1 unit to the accumulator
- Leaf multiplies the accumulator by 2
- Bomb decrement the accumulator by 1
- Air does nothing
(You need to start counting from the top of the vase)
Here is the simulation we get using "11231" as input :
|-| |-| |~| |x| |-| | | | | | | | | | | | |
| | |-| |-| |~| |x| |-| | | | | | | | | | |
| | | | |-| |-| |~| |x| |-| | | | | | | | |
| | | | | | |-| |-| |~| |x| |-| | | | | | |
| | | | | | | | |-| |-| |~| |x| |-| | | | |
| | | | | | | | | | |-| |-| |~| |x| |-| | |
| | | | | | | | | | | | |-| |-| |~| |x| | |
| | | | | | | | | | | | | | |-| |-| |~| |~|
| | | | | | | | | | | | | | | | |-| |-| |-|
| | | | | | | | | | | | | | | | | | |-| |-|
And the output will be 2 (calculated as ((0 x 2) + 1) + 1
)
No need to print all the states of the vase !
The base program (Python3)
You can execute it to understand how it works.
def printVase(vase):
for i in vase:
if i == 1:
print("|-|")
elif i == 2:
print("|~|")
elif i == 3:
print("|x|")
else:
print("| |")
def updateVase(vase):
changed = False
for i in range(len(vase), -1, -1):
if i < len(vase) - 1:
if vase[i+1] == 3 and vase[i] in [1,2]:
vase[i], vase[i+1] = 0, 0
changed = True
if not vase[i+1] and vase[i] in [1, 2, 3]:
vase[i], vase[i+1] = vase[i+1], vase[i]
changed = True
return changed
userInput = input("Vase : ")
vase = [0 for i in range(0, 10)]
oldVase = vase
while updateVase(vase) or userInput != "":
if userInput != "":
vase[0] = int(userInput[0])
userInput = userInput[1::]
printVase(vase)
input()
accumulator = 0
for i in vase:
if i == 1:
accumulator += 1
if i == 2:
accumulator *= 2
if i == 3:
accumulator -= 1
print(accumulator)
Golfed version (Python3, no Vase Display) : 360 bytes = 360 points
def u(v):
c=0
for i in range(len(v),-1,-1):
if i<len(v)-1:
if v[i+1]==3 and v[i]in[1,2]:v[i],v[i+1],c=0,0,1
if not v[i+1]and v[i]in[1,2,3]:v[i],v[i+1],c=v[i+1],v[i],1
return c
l,v=input(),[0 for i in range(0, 10)]
while u(v)or l!="":
if l!="":v[0],l=int(l[0]),l[1::]
a=0
for i in v:
if i==1:a+=1
if i==2:a*=2
if i==3:a-=1
print(a)
If you want to test if your program works correctly, you can test this input : 12122111131
Correct answer is 43 :) (Thanks Emigna)
Now for the points :
- (x) points where : x is the amount of bytes needed to write your program. If you answer after the next challenge is posted, points for this challenge won't be added to your total amount of points.
The goal is to keep a minimum amount of points during the whole challenge :) If you skip one of the part of the challenge, you'll have (wx + 1) points by default for the skipped part (where wx is the worst score for that challenge).
Data that will be required for the next challenge :
Output when input = 10100000200310310113030200221013111213110130332101
Current Champion : Emigna
Good luck everyone !
333
constructs a vase[0, 0, 0, 0, 0, 0, 0, 3, 3, 3]
in your golfed algorithm and hence a score of-3
, but shouldn't it be[0, 0, 0, 0, 0, 0, 0, 0, 0, 3]
and then a score of-1
according to your specification? \$\endgroup\$