Skip to main content

Timeline for Write an interpreter for 99

Current License: CC BY-SA 3.0

25 events
when toggle format what by license comment
Mar 16, 2015 at 23:34 history bounty ended Calvin's Hobbies
Mar 12, 2015 at 5:28 history edited Mac CC BY-SA 3.0
correct bug
Mar 10, 2015 at 22:54 comment added Timtech +1 for pastebin.com/nczmzkFs
Mar 10, 2015 at 22:20 history edited Mac CC BY-SA 3.0
Remove newlines from output
Mar 10, 2015 at 5:37 history edited Mac CC BY-SA 3.0
99 bottles!
Mar 10, 2015 at 2:14 comment added Mac @coredump: no worries!
Mar 10, 2015 at 2:13 comment added Mac @DLosc: thanks. I'm guessing the problem with the else is that a digit followed by a letter "E" is interpreted as the beginning of a scientific notation literal (e.g. 1e5), which then confuses the parser when it encounters the l in else when it was expecting a plus/minus sign or digit.
Mar 10, 2015 at 2:12 comment added coredump @Mac I just applied your trick about multiples of nine. Thanks again.
Mar 10, 2015 at 2:10 history edited Mac CC BY-SA 3.0
deleted 3 characters in body
Mar 10, 2015 at 2:02 comment added DLosc A couple more spaces to eliminate: ~- doesn't need a space before it; and since i is integer, you can replace while 0<=i with while-1<i.
Mar 10, 2015 at 1:58 comment added DLosc Odd--I tested on ideone.com and it worked, but you're right, it doesn't work in the actual Python3 interpreter (3.4.0 on Ubuntu). This tips post clarifies: a number followed by an alphabetical token works in general, but not for tokens starting with e or E, and (from the comments) not for 0or either.
Mar 10, 2015 at 1:54 history edited Mac CC BY-SA 3.0
Extended unpacking FTW
Mar 10, 2015 at 1:50 comment added Mac @DLosc: sorry, I misspoke - I did indeed mean the space, not the else. For example, I tried replacing print(w if L(e)%2 else chr(w%128)) with print(w if L(e)%2else chr(w%128)) and got a syntax exception.
Mar 10, 2015 at 1:46 comment added coredump @Mac That's nice, thanks for clarifying.
Mar 10, 2015 at 1:46 comment added DLosc Not the else itself, just the space before it. E.g. 3*n+1if n%2else n//2.
Mar 10, 2015 at 1:41 comment added Mac @coredump: the way the spec is written, each variable will always have a value that is divisible by nine. I found it more concise to allow the variables to take on any value, and to only multiply/divide by nine as needed (in particular, in the goto routine and when getting the default value of the variable). As far as a user of the language is concerned, it makes no difference.
Mar 10, 2015 at 1:29 comment added Mac @DLosc: regarding your first point: I too though that else after a number could be removed, but when I tried it earlier I got a syntax error. Your other tips are much appreciated though!
Mar 10, 2015 at 1:27 history edited Mac CC BY-SA 3.0
added 15 characters in body
Mar 10, 2015 at 1:18 comment added coredump If I am not mistaken, in the goto case, you multiply the target address by 9, which is unnecessary (see bold part in spec.)
Mar 10, 2015 at 1:08 comment added DLosc Also, to suppress the newline, Python3 lets you do print(x,end='')--"only" 7 bytes more. ;)
Mar 10, 2015 at 1:06 comment added DLosc Nice work! A few Python golfing pointers: 1) Spaces before else can be removed if preceded by a number; 2) elif not any can use ~- instead of not (see this tip); 3) replace [g(j)for j in d[1:]] with list(map(g,d[1:])) to save 2 bytes, and similarly for the genexp in any(). Also, instead of using \\1, I think you could just substitute a literal space.
Mar 10, 2015 at 0:52 history edited Mac CC BY-SA 3.0
Add ungolfed version
Mar 10, 2015 at 0:27 history edited Mac CC BY-SA 3.0
Shaved a couple more bytes
Mar 10, 2015 at 0:17 history edited Mac CC BY-SA 3.0
Save several bytes by moving around the division and multiplication by 9
Mar 9, 2015 at 23:58 history answered Mac CC BY-SA 3.0