I had to write a Rockstar program. FizzBuzz was done so I decided to try the Rainfall Problem:
Write a program that will read in integers and output their average. Stop reading when the value 99999 is input.
Here’s my program:
My hopes are nothing The future is nothing without my hopes Listen to the sky Until the sky is decimated, destroyed; sparkling, sinuously perfected Build my hopes up My dreams are the sky with the future They are my dreams Listen to the sky If my hopes ain't nothing shout the future over my hopes If my hopes are nothing whisper the future of my hopes
It’s damn tricky! The first block initialised the counter (my hopes
) and the sum (the future
) to zero (nothing
). I subtracted zero from zero for the second line to add a little variation.
Getting 99999
so it would scan and make sense was very hard. I don’t think it quite worked, but it’s not an unbearable stretch. Rather too much alliteration.
The averaging sounds a bit odd. I did guard against no input, yay!
Unfortunately the Python transpiler isn’t very complete. Here’s the raw output:
my_hopes are False the_future = False - my_hopes the_sky = input() while not the_sky == decimated, destroyed; sparkling, sinuously perfected: my_hopes += 1 my_dreams are the_sky + the_future They are my_dreams the_sky = input() if my_hopes != False: shout the_future / my_hopes if my_hopes are False: whisper False
So, it doesn’t understand are
or nothing
properly and doesn’t handle poetic number literals. Easy enough to hand fix:
my_hopes = 0 the_future = 0 - my_hopes the_sky = int(input()) while not the_sky == 99999: my_hopes += 1 my_dreams = the_sky + the_future the_future = my_dreams the_sky = int(input()) if my_hopes != 0: print(the_future / my_hopes) if my_hopes == 0: print(0)
Note that since Python 3.x replaced input
with raw_input
(and threw away Python 2.x’s input
, I had to add a manual cast around the read. I think the semantics of Rockstar’s listen
has to be more like old input
otherwise you couldn’t input numbers.
Anyway! There you go!
(I didn’t filter negative numbers since the problem as stated in the linked paper puts that as an elaboration. That would be a PITA to handle :))
It’s clear that there needs to be more synonyms and esp “null” words i.e., words which just get dropped.
Poetic literals only work when initialising a variable. Try splitting the assignment and comparison:
A nightmare is decimated, destroyed; sparkling, sinuously perfected
…
Until the sky is a nightmare
🙂
Doh! Thanks! Will fix.