Skip to main content
We’ve updated our Terms of Service. A new AI Addendum clarifies how Stack Overflow utilizes AI interactions.
Code Golf

Return to Answer

Commonmark migration
Source Link

#Python 2, (削除) 600 (削除ここまで)(削除) 584 (削除ここまで)(削除) 397 (削除ここまで) 373 bytes

Python 2, (削除) 600 (削除ここまで)(削除) 584 (削除ここまで)(削除) 397 (削除ここまで) 373 bytes

This is my own golfed reference solution. Anyone is welcome to improve it or follow its logic in their own answer as long as attribution is given.

The neat part about it is that no recursion is done, so it will never have problems with Python's recursion limit. For example, Sp's Countup Prindeal program can run indefinitely.

p=filter(len,[l.split('#')[0].split()for l in input().split('\n')]);m={};v={};i=0
while i<len(p):
 s=p[i]
 if'('in`s`:s=s[f]
 n,f=s[0],0
 if n in m:a,b,c=([s[int(g)]if g.isdigit()else g for g in t]for t in m[n]);p=[a,(b,c)]+p[i+1:];i=0;continue
 s=s[1]
 q=v.get(s,0)
 if'd'>n:m[s]=p[i+1:i+4];i+=3
 elif'i'<n:print s,'=',q
 elif'd'<n:v[s]=q+1
 elif q:v[s]-=1
 else:f=1
 i+=1

It's a program that takes in the quoted program string with newlines escaped, e.g.
'p _MyVariable_321\np screaming_hairy_armadillo'.

I took various golfing cues from Sp's and Pietu's answers. Thanks guys :)

#Python 2, (削除) 600 (削除ここまで)(削除) 584 (削除ここまで)(削除) 397 (削除ここまで) 373 bytes

This is my own golfed reference solution. Anyone is welcome to improve it or follow its logic in their own answer as long as attribution is given.

The neat part about it is that no recursion is done, so it will never have problems with Python's recursion limit. For example, Sp's Countup Prindeal program can run indefinitely.

p=filter(len,[l.split('#')[0].split()for l in input().split('\n')]);m={};v={};i=0
while i<len(p):
 s=p[i]
 if'('in`s`:s=s[f]
 n,f=s[0],0
 if n in m:a,b,c=([s[int(g)]if g.isdigit()else g for g in t]for t in m[n]);p=[a,(b,c)]+p[i+1:];i=0;continue
 s=s[1]
 q=v.get(s,0)
 if'd'>n:m[s]=p[i+1:i+4];i+=3
 elif'i'<n:print s,'=',q
 elif'd'<n:v[s]=q+1
 elif q:v[s]-=1
 else:f=1
 i+=1

It's a program that takes in the quoted program string with newlines escaped, e.g.
'p _MyVariable_321\np screaming_hairy_armadillo'.

I took various golfing cues from Sp's and Pietu's answers. Thanks guys :)

Python 2, (削除) 600 (削除ここまで)(削除) 584 (削除ここまで)(削除) 397 (削除ここまで) 373 bytes

This is my own golfed reference solution. Anyone is welcome to improve it or follow its logic in their own answer as long as attribution is given.

The neat part about it is that no recursion is done, so it will never have problems with Python's recursion limit. For example, Sp's Countup Prindeal program can run indefinitely.

p=filter(len,[l.split('#')[0].split()for l in input().split('\n')]);m={};v={};i=0
while i<len(p):
 s=p[i]
 if'('in`s`:s=s[f]
 n,f=s[0],0
 if n in m:a,b,c=([s[int(g)]if g.isdigit()else g for g in t]for t in m[n]);p=[a,(b,c)]+p[i+1:];i=0;continue
 s=s[1]
 q=v.get(s,0)
 if'd'>n:m[s]=p[i+1:i+4];i+=3
 elif'i'<n:print s,'=',q
 elif'd'<n:v[s]=q+1
 elif q:v[s]-=1
 else:f=1
 i+=1

It's a program that takes in the quoted program string with newlines escaped, e.g.
'p _MyVariable_321\np screaming_hairy_armadillo'.

I took various golfing cues from Sp's and Pietu's answers. Thanks guys :)

replaced http://codegolf.stackexchange.com/ with https://codegolf.stackexchange.com/
Source Link

#Python 2, (削除) 600 (削除ここまで) (削除) 584 (削除ここまで) (削除) 397 (削除ここまで) 373 bytes

This is my own golfed reference solution. Anyone is welcome to improve it or follow its logic in their own answer as long as attribution is given.

The neat part about it is that no recursion is done, so it will never have problems with Python's recursion limit. For example, Sp's Sp's Countup Prindeal program can run indefinitely.

p=filter(len,[l.split('#')[0].split()for l in input().split('\n')]);m={};v={};i=0
while i<len(p):
 s=p[i]
 if'('in`s`:s=s[f]
 n,f=s[0],0
 if n in m:a,b,c=([s[int(g)]if g.isdigit()else g for g in t]for t in m[n]);p=[a,(b,c)]+p[i+1:];i=0;continue
 s=s[1]
 q=v.get(s,0)
 if'd'>n:m[s]=p[i+1:i+4];i+=3
 elif'i'<n:print s,'=',q
 elif'd'<n:v[s]=q+1
 elif q:v[s]-=1
 else:f=1
 i+=1

It's a program that takes in the quoted program string with newlines escaped, e.g.
'p _MyVariable_321\np screaming_hairy_armadillo'.

I took various golfing cues from Sp's Sp's and Pietu's Pietu's answers. Thanks guys :)

#Python 2, (削除) 600 (削除ここまで) (削除) 584 (削除ここまで) (削除) 397 (削除ここまで) 373 bytes

This is my own golfed reference solution. Anyone is welcome to improve it or follow its logic in their own answer as long as attribution is given.

The neat part about it is that no recursion is done, so it will never have problems with Python's recursion limit. For example, Sp's Countup Prindeal program can run indefinitely.

p=filter(len,[l.split('#')[0].split()for l in input().split('\n')]);m={};v={};i=0
while i<len(p):
 s=p[i]
 if'('in`s`:s=s[f]
 n,f=s[0],0
 if n in m:a,b,c=([s[int(g)]if g.isdigit()else g for g in t]for t in m[n]);p=[a,(b,c)]+p[i+1:];i=0;continue
 s=s[1]
 q=v.get(s,0)
 if'd'>n:m[s]=p[i+1:i+4];i+=3
 elif'i'<n:print s,'=',q
 elif'd'<n:v[s]=q+1
 elif q:v[s]-=1
 else:f=1
 i+=1

It's a program that takes in the quoted program string with newlines escaped, e.g.
'p _MyVariable_321\np screaming_hairy_armadillo'.

I took various golfing cues from Sp's and Pietu's answers. Thanks guys :)

#Python 2, (削除) 600 (削除ここまで) (削除) 584 (削除ここまで) (削除) 397 (削除ここまで) 373 bytes

This is my own golfed reference solution. Anyone is welcome to improve it or follow its logic in their own answer as long as attribution is given.

The neat part about it is that no recursion is done, so it will never have problems with Python's recursion limit. For example, Sp's Countup Prindeal program can run indefinitely.

p=filter(len,[l.split('#')[0].split()for l in input().split('\n')]);m={};v={};i=0
while i<len(p):
 s=p[i]
 if'('in`s`:s=s[f]
 n,f=s[0],0
 if n in m:a,b,c=([s[int(g)]if g.isdigit()else g for g in t]for t in m[n]);p=[a,(b,c)]+p[i+1:];i=0;continue
 s=s[1]
 q=v.get(s,0)
 if'd'>n:m[s]=p[i+1:i+4];i+=3
 elif'i'<n:print s,'=',q
 elif'd'<n:v[s]=q+1
 elif q:v[s]-=1
 else:f=1
 i+=1

It's a program that takes in the quoted program string with newlines escaped, e.g.
'p _MyVariable_321\np screaming_hairy_armadillo'.

I took various golfing cues from Sp's and Pietu's answers. Thanks guys :)

deleted 8 characters in body
Source Link
Calvin's Hobbies
  • 90.7k
  • 46
  • 348
  • 565

#Python 2, (削除) 600 (削除ここまで) (削除) 584 (削除ここまで) 397(削除) 397 (削除ここまで) 373 bytes

This is my own golfed reference solution. Anyone is welcome to improve it or follow its logic in their own answer as long as attribution is given.

The neat part about it is that no recursion is done, so it will never have problems with Python's recursion limit. For example, Sp's Countup Prindeal program can run indefinitely.

p=filter(len,[l.split('#')[0].split()for l in input().split('\n')]);m={};v={};i=0
while i<len(p):
 s=p[i]
 if'('in`s`:s=s[f]
 n,f=s[0],0
 if n in m:a,b,c=([s[int(g)]if g.isdigit()else g for g in t]for t in m[n]);p=[a,(b,c)]+p[i+1:];i=0;continue
 s=s[1]
 ifq=v.get(s,0)
 n<'d'if'd'>n:m[s]=p[i+1:i+4];i+=3
 elif n>'i'elif'i'<n:print s,'=',v.get(s,0)q
 elif n>'d'elif'd'<n:v[s]=1+v[s]if s in v else 1v[s]=q+1
 elif v.get(s)q:v[s]-=1
 else:f=1
 i+=1

It's a program that takes in the quoted program string with newlines escaped, e.g.
'p _MyVariable_321\np screaming_hairy_armadillo'.

I took various golfing cues from Sp's and Pietu's answers. Thanks guys :)

#Python 2, (削除) 600 (削除ここまで) (削除) 584 (削除ここまで) 397 bytes

This is my own golfed reference solution. Anyone is welcome to improve it or follow its logic in their own answer as long as attribution is given.

The neat part about it is that no recursion is done, so it will never have problems with Python's recursion limit. For example, Sp's Countup Prindeal program can run indefinitely.

p=filter(len,[l.split('#')[0].split()for l in input().split('\n')]);m={};v={};i=0
while i<len(p):
 s=p[i]
 if'('in`s`:s=s[f]
 n,f=s[0],0
 if n in m:a,b,c=([s[int(g)]if g.isdigit()else g for g in t]for t in m[n]);p=[a,(b,c)]+p[i+1:];i=0;continue
 s=s[1]
 if n<'d':m[s]=p[i+1:i+4];i+=3
 elif n>'i':print s,'=',v.get(s,0)
 elif n>'d':v[s]=1+v[s]if s in v else 1
 elif v.get(s):v[s]-=1
 else:f=1
 i+=1

It's a program that takes in the quoted program string with newlines escaped, e.g.
'p _MyVariable_321\np screaming_hairy_armadillo'.

I took various golfing cues from Sp's and Pietu's answers. Thanks guys :)

#Python 2, (削除) 600 (削除ここまで) (削除) 584 (削除ここまで) (削除) 397 (削除ここまで) 373 bytes

This is my own golfed reference solution. Anyone is welcome to improve it or follow its logic in their own answer as long as attribution is given.

The neat part about it is that no recursion is done, so it will never have problems with Python's recursion limit. For example, Sp's Countup Prindeal program can run indefinitely.

p=filter(len,[l.split('#')[0].split()for l in input().split('\n')]);m={};v={};i=0
while i<len(p):
 s=p[i]
 if'('in`s`:s=s[f]
 n,f=s[0],0
 if n in m:a,b,c=([s[int(g)]if g.isdigit()else g for g in t]for t in m[n]);p=[a,(b,c)]+p[i+1:];i=0;continue
 s=s[1]
 q=v.get(s,0)
 if'd'>n:m[s]=p[i+1:i+4];i+=3
 elif'i'<n:print s,'=',q
 elif'd'<n:v[s]=q+1
 elif q:v[s]-=1
 else:f=1
 i+=1

It's a program that takes in the quoted program string with newlines escaped, e.g.
'p _MyVariable_321\np screaming_hairy_armadillo'.

I took various golfing cues from Sp's and Pietu's answers. Thanks guys :)

deleted 68 characters in body
Source Link
Calvin's Hobbies
  • 90.7k
  • 46
  • 348
  • 565
Loading
added 3 characters in body
Source Link
mbomb007
  • 23.6k
  • 7
  • 66
  • 143
Loading
deleted 15 characters in body
Source Link
Calvin's Hobbies
  • 90.7k
  • 46
  • 348
  • 565
Loading
Source Link
Calvin's Hobbies
  • 90.7k
  • 46
  • 348
  • 565
Loading

AltStyle によって変換されたページ (->オリジナル) /