Skip to main content
Process journal of learning by Attila Vajda

๐Ÿฆ„ Lean4 Puzzle, ๐Ÿข C Puzzle, ๐Ÿ Python Puzzle

๐Ÿฆ„ Lean4 Puzzle:

inductive ๐’ฒ where
| ฮฑ : ๐’ฒ
| ฮฒ : ๐’ฒ โ†’ ๐’ฒ

def ๐’ฎ (ฮถ : Type) := Unit โŠ• ฮถ

def ฯ† : ๐’ฎ ๐’ฒ โ†’ ๐’ฒ
| .inl _ => ๐’ฒ.ฮฑ
| .inr z => ๐’ฒ.ฮฒ z

#eval ฯ† (.inr (.ฮฒ (.ฮฒ ๐’ฒ.ฮฑ)))

โ“Guess: How deep is this number in Peano steps?

๐Ÿข C Puzzle:

typedef struct ฮฉ {
  int tag;
  struct ฮฉ* next;
} ฮฉ;

ฮฉ* ฮฆ(ฮฉ* x) {
  if (!x) return NULL;
  ฮฉ* y = malloc(sizeof(ฮฉ));
  y->tag = 1;
  y->next = x;
  return y;
}

โ“Guess: How many ฮฆ calls before NULL?

๐Ÿ Python Puzzle:

def ๐“•(x): return ("1", None) if x is None else ("+", x)

x = ๐“•(("+", ("+", None)))
print(x[1][1])

โ“Guess: What does x[1][1] yield?

I find it sort of fun, that this is a number, because it doesn't look like a number:

inductive ๐’ฒ where
| ฮฑ : ๐’ฒ
| ฮฒ : ๐’ฒ โ†’ ๐’ฒ

โœจ Keep puzzling! Every function is a tiny theorem you can prove or refactor โ€” functional code is mathematical art. ๐ŸŽจ๐Ÿ™

๐’ฎ ๐’ฒ := Unit โŠ• ๐’ฒ  
-- โˆ…       ๐Ÿพ something