#Python 2, 486 bytes
Python 2, 486 bytes
This is the reference solution which I golfed more (currently -98 bytes).
import sys;sys.setrecursionlimit(2000)
def r(s):
n=s[0]
if n in A:f=lambda i:r([s[int(t)]if'0'<t[0]<':'else t for t in A[n][i]]);return f(1+(f(0)or 0))
k=s[1]
if'i'<n:print k,'=',V.get(k,0)
elif'd'<n:V[k]=-~V[k]if k in V else 1
elif'a'<n:
if~-(k in V)or V[k]<1:return 1
V[k]-=1
else:A[k]=s[2:]
A={};V={};c=filter(bool,([l,l[:l.find('#')]]['#'in l]for l in input().split('\n')))
while c:
s=c[0].split();c=c[1:]
if'a'!=s[0]:r(s)
else:r(['a',s[1]]+map(str.split,c[:3]));c=c[3:]
Changes (that I recall):
- automatic boolean-integer conversion (
[l,l[:l.find('#')]]['#'in l]). - set or increment in one statement (
V[k]=-~V[k]if k in V else 1) - more aliases to longer expressions (
k=s[1]) - no counter in the main loop, clearing the input list instead
printautomatically adding spaces (print k,'=',V.get(k,0))- checking digits 1-9 (
'0'<t[0]<':') - flipping the return values of
raround to savereturns - removing repetition of slicing and splitting (
map(str.split,c[:3])))
#Python 2, 486 bytes
This is the reference solution which I golfed more (currently -98 bytes).
import sys;sys.setrecursionlimit(2000)
def r(s):
n=s[0]
if n in A:f=lambda i:r([s[int(t)]if'0'<t[0]<':'else t for t in A[n][i]]);return f(1+(f(0)or 0))
k=s[1]
if'i'<n:print k,'=',V.get(k,0)
elif'd'<n:V[k]=-~V[k]if k in V else 1
elif'a'<n:
if~-(k in V)or V[k]<1:return 1
V[k]-=1
else:A[k]=s[2:]
A={};V={};c=filter(bool,([l,l[:l.find('#')]]['#'in l]for l in input().split('\n')))
while c:
s=c[0].split();c=c[1:]
if'a'!=s[0]:r(s)
else:r(['a',s[1]]+map(str.split,c[:3]));c=c[3:]
Changes (that I recall):
- automatic boolean-integer conversion (
[l,l[:l.find('#')]]['#'in l]). - set or increment in one statement (
V[k]=-~V[k]if k in V else 1) - more aliases to longer expressions (
k=s[1]) - no counter in the main loop, clearing the input list instead
printautomatically adding spaces (print k,'=',V.get(k,0))- checking digits 1-9 (
'0'<t[0]<':') - flipping the return values of
raround to savereturns - removing repetition of slicing and splitting (
map(str.split,c[:3])))
Python 2, 486 bytes
This is the reference solution which I golfed more (currently -98 bytes).
import sys;sys.setrecursionlimit(2000)
def r(s):
n=s[0]
if n in A:f=lambda i:r([s[int(t)]if'0'<t[0]<':'else t for t in A[n][i]]);return f(1+(f(0)or 0))
k=s[1]
if'i'<n:print k,'=',V.get(k,0)
elif'd'<n:V[k]=-~V[k]if k in V else 1
elif'a'<n:
if~-(k in V)or V[k]<1:return 1
V[k]-=1
else:A[k]=s[2:]
A={};V={};c=filter(bool,([l,l[:l.find('#')]]['#'in l]for l in input().split('\n')))
while c:
s=c[0].split();c=c[1:]
if'a'!=s[0]:r(s)
else:r(['a',s[1]]+map(str.split,c[:3]));c=c[3:]
Changes (that I recall):
- automatic boolean-integer conversion (
[l,l[:l.find('#')]]['#'in l]). - set or increment in one statement (
V[k]=-~V[k]if k in V else 1) - more aliases to longer expressions (
k=s[1]) - no counter in the main loop, clearing the input list instead
printautomatically adding spaces (print k,'=',V.get(k,0))- checking digits 1-9 (
'0'<t[0]<':') - flipping the return values of
raround to savereturns - removing repetition of slicing and splitting (
map(str.split,c[:3])))
#Python 2, 486 bytes
This is the reference solution which I golfed more (currently -98 bytes).
import sys;sys.setrecursionlimit(2000)
def r(s):
n=s[0]
if n in A:f=lambda i:r([s[int(t)]if'0'<t[0]<':'else t for t in A[n][i]]);return f(1+(f(0)or 0))
k=s[1]
if'i'<n:print k,'=',V.get(k,0)
elif'd'<n:V[k]=-~V[k]if k in V else 1
elif'a'<n:
if~-(k in V)or V[k]<1:return 1
V[k]-=1
else:A[k]=s[2:]
A={};V={};c=filter(bool,([l,l[:l.find('#')]]['#'in l]for l in input().split('\n')))
while c:
s=c[0].split();c=c[1:]
if'a'!=s[0]:r(s)
else:r(['a',s[1]]+map(str.split,c[:3]));c=c[3:]
import sys;sys.setrecursionlimit(2000)
def r(s):
n=s[0]
if n in A:f=lambda i:r([s[int(t)]if'0'<t[0]<':'else t for t in A[n][i]]);return f(1+(f(0)or 0))
k=s[1]
if'i'<n:print k,'=',V.get(k,0)
elif'd'<n:V[k]=-~V[k]if k in V else 1
elif'a'<n:
if~-(k in V)or V[k]<1:return 1
V[k]-=1
else:A[k]=s[2:]
A={};V={};c=filter(bool,([l,l[:l.find('#')]]['#'in l]for l in input().split('\n')))
while c:
s=c[0].split();c=c[1:]
if'a'!=s[0]:r(s)
else:r(['a',s[1]]+map(str.split,c[:3]));c=c[3:]
Changes (that I recall):
- automatic boolean-integer conversion (
[l,l[:l.find('#')]]['#'in l]). - set or increment in one statement (
V[k]=-~V[k]if k in V else 1) - more aliases to longer expressions (
k=s[1]) - no counter in the main loop, clearing the input list instead
printautomatically adding spaces (print k,'=',V.get(k,0))- checking digits 1-9 (
'0'<t[0]<':') - flipping the return values of
raround to savereturns - removing repetition of slicing and splitting (
map(str.split,c[:3])))
#Python 2, 486 bytes
This is the reference solution which I golfed more (currently -98 bytes).
import sys;sys.setrecursionlimit(2000)
def r(s):
n=s[0]
if n in A:f=lambda i:r([s[int(t)]if'0'<t[0]<':'else t for t in A[n][i]]);return f(1+(f(0)or 0))
k=s[1]
if'i'<n:print k,'=',V.get(k,0)
elif'd'<n:V[k]=-~V[k]if k in V else 1
elif'a'<n:
if~-(k in V)or V[k]<1:return 1
V[k]-=1
else:A[k]=s[2:]
A={};V={};c=filter(bool,([l,l[:l.find('#')]]['#'in l]for l in input().split('\n')))
while c:
s=c[0].split();c=c[1:]
if'a'!=s[0]:r(s)
else:r(['a',s[1]]+map(str.split,c[:3]));c=c[3:]
Changes (that I recall):
- automatic boolean-integer conversion (
[l,l[:l.find('#')]]['#'in l]). - set or increment in one statement (
V[k]=-~V[k]if k in V else 1) - more aliases to longer expressions (
k=s[1]) - no counter in the main loop, clearing the input list instead
printautomatically adding spaces (print k,'=',V.get(k,0))- checking digits 1-9 (
'0'<t[0]<':') - flipping the return values of
raround to savereturns - removing repetition of slicing and splitting (
map(str.split,c[:3])))
#Python 2, 486 bytes
This is the reference solution which I golfed more (currently -98 bytes).
import sys;sys.setrecursionlimit(2000)
def r(s):
n=s[0]
if n in A:f=lambda i:r([s[int(t)]if'0'<t[0]<':'else t for t in A[n][i]]);return f(1+(f(0)or 0))
k=s[1]
if'i'<n:print k,'=',V.get(k,0)
elif'd'<n:V[k]=-~V[k]if k in V else 1
elif'a'<n:
if~-(k in V)or V[k]<1:return 1
V[k]-=1
else:A[k]=s[2:]
A={};V={};c=filter(bool,([l,l[:l.find('#')]]['#'in l]for l in input().split('\n')))
while c:
s=c[0].split();c=c[1:]
if'a'!=s[0]:r(s)
else:r(['a',s[1]]+map(str.split,c[:3]));c=c[3:]
Changes (that I recall):
- automatic boolean-integer conversion (
[l,l[:l.find('#')]]['#'in l]). - set or increment in one statement (
V[k]=-~V[k]if k in V else 1) - more aliases to longer expressions (
k=s[1]) - no counter in the main loop, clearing the input list instead
printautomatically adding spaces (print k,'=',V.get(k,0))- checking digits 1-9 (
'0'<t[0]<':') - flipping the return values of
raround to savereturns - removing repetition of slicing and splitting (
map(str.split,c[:3])))
#Python 2, 486 bytes
This is the reference solution which I golfed more (currently -98 bytes).
import sys;sys.setrecursionlimit(2000)
def r(s):
n=s[0]
if n in A:f=lambda i:r([s[int(t)]if'0'<t[0]<':'else t for t in A[n][i]]);return f(1+(f(0)or 0))
k=s[1]
if'i'<n:print k,'=',V.get(k,0)
elif'd'<n:V[k]=-~V[k]if k in V else 1
elif'a'<n:
if~-(k in V)or V[k]<1:return 1
V[k]-=1
else:A[k]=s[2:]
A={};V={};c=filter(bool,([l,l[:l.find('#')]]['#'in l]for l in input().split('\n')))
while c:
s=c[0].split();c=c[1:]
if'a'!=s[0]:r(s)
else:r(['a',s[1]]+map(str.split,c[:3]));c=c[3:]
Changes (that I recall):
- automatic boolean-integer conversion (
[l,l[:l.find('#')]]['#'in l]). - set or increment in one statement (
V[k]=-~V[k]if k in V else 1) - more aliases to longer expressions (
k=s[1]) - no counter in the main loop, clearing the input list instead
printautomatically adding spaces (print k,'=',V.get(k,0))- checking digits 1-9 (
'0'<t[0]<':') - flipping the return values of
raround to savereturns - removing repetition of slicing and splitting (
map(str.split,c[:3])))