Mini Puzzle - β, β, normalization challenge
πΉβ΅πγΈγ£γΊ meets πTypeTheory #
Mini Puzzle: β, β, normalization challenge
π¬ Lean4
def ιΎπ (Ο:β) : β := match Ο with
| 0 => 8
| β.succ π§ => ιΎπ (π§ ) + 3
#eval ιΎπ 2
π Python
def πͺ(ζ): return 8 if ζ==0 else πͺ(ζ-1)+3
print(πͺ(2))
π§ C
int π₯(int ζ°΄){return ζ°΄==0?8:π₯(ζ°΄-1)+3;}
int main(){printf("%d",π₯(2));}
These puzzles are so cool! (in my experience)
You can see the visualisation here: https://pythontutor.com/render.html#mode=display
and learn a lot about recursion, abstract mathematics and coding
def πͺ(ζ): return 8 if ζ==0 else πͺ(ζ-1)+3
These puzzles are awesome! You can learn a LOT about recursion in fact understand it powerfully perhaps, and I can now visualise the algorithm on Python tutor. So I learnt that maybe πͺ(ζ-1)+3 goes ζ to 0 and then adds 3 at each step returning (is returning inverse arrows? It seems like a loop, going there, and back, going there steps two arrows -1 -1, then comes back +3 +3 ! Awesome, so there is categories here.
8 is the starting point yes? A
-1
or is 2
the starting point, whatever you input?
2 ---{-1}---> 1 ---{-1}---> 0 ---{return 8}---> 8 ---{+3}---> 11 ---{+3}---> 14
Go until 0 in -1s, then turn 8, and go as many steps it took you to get to 0 from 2 in 3s.
input βΆ base-case βΆ return-anchor βΆ output
n βΆ 0
return 8 + (n Γ 3)
π€πΏ π±Recursion = journey + rebuild = fold + unfold π§©
--β recursion : input βΆ base-case βΆ return-anchor βΆ output?
f(x) := if base(x) then anchor else step(f(prev(x)))
π€πΏ π Unfold + Refold π§©
#recursion
I got these puzzles from ChatGPT (thanks π€),
using the espansos:
matches:
- trigger: ":quests"
replace: "pls show quests π§©"
- trigger: ":pzl-a"
replace: "pls write puzzle to guess output, in Lean4 and a different style in Python, and another in C, with all gibberish/unicode-symbol/grapheme/kanji/greek for everything variable"
- trigger: ":l4a-a"
replace: "pls show the pareto quests of Lean4 architect craft, being able to build Lean4 core and mathlib4 from scratch, and refactor it with clean code practices."
- trigger: ":100"
replace: "pls respond in β€ 500 characters"
- trigger: ":300"
replace: "pls respond in β€ 500 characters"
- trigger: ":500"
replace: "pls respond in β€ 500 characters"
Reference: #
Christian Mayer's work on code puzzles:
- Python One-Liners
- https://app.finxter.com/learn/computer/science/