Skip to main content
Print as we go
Source Link
Bruno Le Floch
  • 1.3k
  • 10
  • 13

Python 2 (195236), Python 3 (198?)

from __future__ import print_function
def d(i):
 t=0;p=['']*3+[1]
 while i:
  if'/'==i[0]:t+=1
  else:
   if'\\'==i[0]:i=i[1:]
   p[t]+=i[0]
  i=i[1:]
  print(end=p[0]);p[0]=''
  if t>2:
   while p[1]in i:i=i.replace(*p[1:])
   t=0;p[1:]=['','',1]
 print p[0]d(i);i=0

Called as d(r"""/foo/Hello, world!//B\/\\R/foo/B/\R"""). The triple quotes are only needed if the /// program contains newlines: otherwise simple quotes are ok. This

EDIT: This interpreter does not print anything untilnow prints stuff as expected (previously it exitsonly printed at the very end, cf. comments). For Python 3, remove the first line (but I don't have Python 3 on my ancient install, so in this sensecannot be sure there is not compliantno other change).

Python (195)

def d(i):
 t=0;p=['']*3+[1]
 while i:
  if'/'==i[0]:t+=1
  else:
   if'\\'==i[0]:i=i[1:]
   p[t]+=i[0]
  i=i[1:]
  if t>2:
   while p[1]in i:i=i.replace(*p[1:])
   t=0;p[1:]=['','',1]
 print p[0]

Called as d(r"""/foo/Hello, world!//B\/\\R/foo/B/\R"""). The triple quotes are only needed if the /// program contains newlines: otherwise simple quotes are ok. This interpreter does not print anything until it exits, so in this sense is not compliant.

Python 2 (236), Python 3 (198?)

from __future__ import print_function
def d(i):
 t=0;p=['']*3+[1]
 while i:
  if'/'==i[0]:t+=1
  else:
   if'\\'==i[0]:i=i[1:]
   p[t]+=i[0]
  i=i[1:]
  print(end=p[0]);p[0]=''
  if t>2:
   while p[1]in i:i=i.replace(*p[1:])
   d(i);i=0

Called as d(r"""/foo/Hello, world!//B\/\\R/foo/B/\R"""). The triple quotes are only needed if the /// program contains newlines: otherwise simple quotes are ok.

EDIT: This interpreter now prints stuff as expected (previously it only printed at the very end, cf. comments). For Python 3, remove the first line (but I don't have Python 3 on my ancient install, so cannot be sure there is no other change).

Source Link
Bruno Le Floch
  • 1.3k
  • 10
  • 13

Python (195)

def d(i):
 t=0;p=['']*3+[1]
 while i:
  if'/'==i[0]:t+=1
  else:
   if'\\'==i[0]:i=i[1:]
   p[t]+=i[0]
  i=i[1:]
  if t>2:
   while p[1]in i:i=i.replace(*p[1:])
   t=0;p[1:]=['','',1]
 print p[0]

Called as d(r"""/foo/Hello, world!//B\/\\R/foo/B/\R"""). The triple quotes are only needed if the /// program contains newlines: otherwise simple quotes are ok. This interpreter does not print anything until it exits, so in this sense is not compliant.