Hacker News new | ask | show | jobs
by eatnumber1 4342 days ago
Resetting the state isn't one of the rules ;)

I'd make a solution which resets the state linked by the table though, so please submit one!

1 comments

Rule 7 says:

   g('al') must return "gal".
If you add

   assert g('al') == 'gal'
as the last line of solution 1, the assertion will not pass. I'm not saying there is a rule that mentions "resetting state". I'm saying that their failure to reset state is the bug leading to them not following the rules.
Thanks for pointing this out, it's now fixed.

https://github.com/eatnumber1/goal/pull/18

Nick,

That helps but doesn't completely solve the state problem. Try adding these two lines to the end of the program:

    g()()()()()
    print g('al')

I think 'gal' should be printed here. Rule 7 says that's what your function should return given 'al', and the fact that we've called it in some other way before doesn't change the fact that it is required to return 'gal' given 'al'.

The solution I posted above handles this scenario (and, as a bonus, is thus threadsafe in case multiple people were doing g()()()('al') simultaneously).