Skip to content

Instantly share code, notes, and snippets.

@Lapin0t
Created August 24, 2016 15:34
Show Gist options
  • Save Lapin0t/22296ee1e79bcb9ff158174df47d1fab to your computer and use it in GitHub Desktop.
Save Lapin0t/22296ee1e79bcb9ff158174df47d1fab to your computer and use it in GitHub Desktop.
An implementation of McCulloch's machine from Smullyan's book "What Is the Name of This Book?"
from re import match as _m
calcule=(lambda n,machine='machi'
'ne-1': ( lambda m:(lambda
f:(lambda x: x(x))(lambda
x:f(lambda v: (x(x ))(v))))(
lambda f:lambda x:(lambda r:r
.group(1) if r else m[1][x[
0]](f(x[1:])) )(_m(m[0],x)
))(n) if _m( r'[{}]*{}'.
format( ''. join(m[1])
,m[0]),n) else None)({''
'machin' 'e-1': (r'2([1'
r'-9]+' r')$' , {'3''':
lambda y:y+'2'+y ,''
'4': lambda y:y[: :-1
], '5':lambda y:2* y}),
'machine-2':(r'2([1-9]+)2$',{'6':
lambda y:'2'+y,'4':lambda y:y[::-
1],'5':lambda y:y*2})}[machine]))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment