Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/omega-rosetta/blob/main/tasks/towers-of-hanoi/towers-of-hanoi.om # omega-rosetta aien-dev/omega-rosetta Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `omega-rosetta / tasks / towers-of-hanoi / towers-of-hanoi.om` 51 lines ยท 937 bytes Raw Blame History 1 note Rosetta Code task "Towers of Hanoi": https://rosettacode.org/wiki/Towers_of_Hanoi 2 note SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 3 om2 4 text nl "\n" 5 text t1 "Move disk " 6 text t2 " from pole " 7 text t3 " to pole " 8 note emit writes every byte of a to stdout; a short write is retried, an error exits 1 9 fn emit a view uchar * to void 10 o = ulong 0 11 while lt o len a bound 4096 12 k = write 1 a o sub len a o 13 if le k 0 14 exit 1 15 end 16 o = add o ulong k 17 end 18 end 19 note emitu writes n in decimal; 20 digits hold every ulong 20 fn emitu n ulong to void 21 d = new uchar 20 0 22 i = ulong 20 23 v = n 24 while true bound 20 25 i = sub i 1 26 put d i uchar add rem v 10 48 27 v = div v 10 28 if eq v 0 29 break 30 end 31 end 32 emit part d i sub 20 i 33 end 34 fn hanoi n ulong src ulong dst ulong via ulong to void 35 if eq n 0 36 ret 37 end 38 hanoi sub n 1 src via dst 39 emit t1 40 emitu n 41 emit t2 42 emitu src 43 emit t3 44 emitu dst 45 emit nl 46 hanoi sub n 1 via dst src 47 end 48 fn main to int 49 hanoi 4 1 3 2 50 ret 0 51 end