I made this Go one that might be cheating because instead of the ("al") call returning a string, you get a value that implements the String method. Works with fmt.Println :) http://play.golang.org/p/zrp2sO6ZLU
G()('al')
21–30 of 49 posts
Re: G()('al')
#22I made this Go one that might be cheating because instead of the ("al") call returning a string, you get a value that implements the String method. Works with fmt.Println :) http://play.golang.org/p/zrp2sO6ZLU
Re: G()('al')
#23Earlier quoted context omitted.
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
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).
Re: G()('al')
#24I made this Go one that might be cheating because instead of the ("al") call returning a string, you get a value that implements the String method. Works with fmt.Println :) http://play.golang.org/p/zrp2sO6ZLU
This is close to identical to what I did, but the use of a global just felt too dirty. Still trying to figure out the use of a closure on it.
Re: G()('al')
#25https://github.com/kylecronin/goal/commit/70c9277ec99f80dca2...
Re: G()('al')
#26Easy in Lua. You can even write G()'al'
Great! Can you submit a pull request?
function goal(n)
return function(al)
if al then
return "G" .. string.rep("o", n) .. al
else
return goal(n+1)
end
end
end
G = goal(0)
print( G()()('al') )
Also note that G()'al' is just syntactic sugar for G()('al') in LuaRe: G()('al')
#27 #!/bin/sh
grep -e "g\(()\)*('al')" $0 | sed 's/()/o/g' | sed "s/('al')/al/"
exit
g()('al')
On its own, g()('al') is valid but g()()('al') is a syntax error. Also, bash and sh don't have non-numeric return values, so regardless of the solution you're stuck with printing.Re: G()('al')
#28Re: G()('al')
#29I'm pretty sure this is cheating, but... #!/bin/sh grep -e "g\(()\)*('al')" $0 | sed 's/()/o/g' | sed "s/('al')/al/" exit g()('al') On its own, g()('al') is valid but g()()('al') is a syntax error. Also, bash and sh don't have non-numeric return values, so regardless of the solution you're stuck with printing.
Re: G()('al')
#30Easy in Lua. You can even write G()'al'
Great! Can you submit a pull request?
function g(o)
if o then return "gal" end
o = "o"
local function go(al)
if al then
return "g"..o..al
else
o = o .. "o"
return go
end
end
return go
end
print(g()('al'))
More amusing and hackish solution: setmetatable(_G, -- or _ENV, but maintain 5.1 compatibility
{ __index = function(_, g)
local o = ""
local function go(al)
if al then
return g..o..al
end
o = o.."o"
return go
end
return go
end})
print(g()('al'))
print(G()'al')
print(Wh()()'pdedo')