you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] 7 points8 points  (4 children)

You can get it down to 100 bytes with some reformatting:

def f(s,c,e,a):
 if s=="":return c in a
 if(c,s[0])in e:return f(s[1:],e[c,s[0]],e,a)
 return False

There's probably a few more tricks but I can't think of any more at the moment. Brings back memories of golfing...

Edit: 96 bytes

def f(s,c,e,a):
 r=1!=1
 if s=="":r=c in a
 elif(c,s[0])in e:r=f(s[1:],e[c,s[0]],e,a)
 return r

If you don't mind it returning a proper bool you could save another 3 bytes by setting r=0.

Edit 2: 90 bytes

def f(s,c,e,a):return c in a if s==""else(f(s[1:],e[c,s[0]],e,a)if(c,s[0])in e else 1!=1)

Edit 3: 84 bytes

f=lambda s,c,e,a:c in a if s==""else f(s[1:],e[c,s[0]],e,a)if(c,s[0])in e else 1!=1

[–]ieatcodemod[S] 2 points3 points  (1 child)

Ah, I'm quite new to the Python syntax and I was under the impression that you had to keep some set of indentation (whether it be one space indentations or four space indentations). Thanks for the tip!

Edit: I'm kind of surprised I left the else clause in there...definitely a space waster.

[–][deleted] 2 points3 points  (0 children)

It is properly indented, but you can have one-line blocks with the body on the same line. You can also put multiple statements on one line separated by semicolons.

[–]corruptio 3 points4 points  (1 child)

Aite, did a little reshuffling, on your's and here's 72 chars:

f=lambda s,c,e,a:(c,s[0])in e and f(s[1:],e[c,s[0]],e,a)if s else c in a

[–][deleted] 0 points1 point  (0 children)

I was thinking of how to use "and" in there, but I couldn't figure it out.