Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

I like doing codegolf in Python because it just feels so perverse. My golfed BF interpreter was way shorter than his :)


Python lends itself quite nicely to code-golfing, that's true. In fact I am constantly amazed of how terse Python code can be, despite the significant whitespace stuff.

  from os import*
  r='s=[0]*8**5'
  p=0
  for c in read(0,9**9):r+='\n'+' '*p+dict(zip("><+-.,[","p+=1|p-=1|s[p]+=1|s[p]-=1|write(1,chr(s[p]))|s[p]=ord(read(0,1))|while s[p]:".split('|'))).get(c,'');p+=c in'[]'and 92-ord(c)
  exec r
I know, it's a JIT compiler, not an interpreter, but still... :)


Man, that's slick - similar how I did it, but even shorter :)




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: