LoginSignup
1
3

More than 5 years have passed since last update.

whileとglobalsと短絡評価でPythonチューリング完全ワンライナーは簡単

Last updated at Posted at 2018-12-12

lambdaでPythonチューリング完全ワンライナーくらいは簡単なのはわかったので、lambda抜きでもいけるかなと思ったら行けた。

コード例

内容は上記記事と同じ。一対一対応ができるので、さっきのがチューリング完全ならこっちもチューリング完全。

while not (globals().update({'ln':0, 'ns':{}}) if 'ln' not in globals() else None) and not (
    (ln == 0 and (print(1) or globals().update({'ln':1}))) or
    (ln == 1 and (print(3) or globals().update({'ln':2}))) or
    (ln == 2 and (ns.update({'i':20}) or globals().update({'ln':3}))) or
    (ln == 3 and (globals().update({'ln':4}) if ns['i'] else globals().update({'ln':7}))) or
    (ln == 4 and (print(ns['i']) or globals().update({'ln':5}))) or
    (ln == 5 and (ns.update({'i':ns['i']-1}) or globals().update({'ln':6}))) or
    (ln == 6 and (globals().update({'ln':3}))) or
    (ln == 7 and True) or
    0):pass

例のごとく、改行抜きでも動きます。

現在の課題は、ワンライナーで変数を定義することができず、globals().updateを多用していることかな。

1
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
3