๐ฆ 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