Post History
Ahead, 20 bytes I>:2%r vn:/2\< >}KO@ Control flow goes like this: # orange path: init I # read number # green path: main loop > # go east (start of loop) : # dup inpu...
Answer
#2: Post edited
- # [Ahead], 20 bytes
I>:2%rvn:/2\<>}KO@- [Try it online!][TIO-kt28kj38]
- [Ahead]: https://github.com/ajc2/ahead
- [TIO-kt28kj38]: https://tio.run/##S8xITUz5/9/TzspItYirLM9K3yjGhsuu1tvf4f9/QyMA "Ahead – Try It Online"
- # [Ahead], 20 bytes
- ```ahead
- I>:2%r
- vn:/2\<
- >}KO@
- ```
- Control flow goes like this:
- ![Ahead program flow diagram](https://codegolf.codidact.com/uploads/qrN6dpACh2wVrWM5nTkZphtS)
- ```
- # orange path: init
- I # read number
- # green path: main loop
- > # go east (start of loop)
- : # dup input
- 2% # take mod 2 (get lowest bit)
- r< # half-turn right, go east (enter second line)
- \ # swap top two stack items (put bit under input)
- 2/ # divide input by 2 (right shift)
- : # dup input
- n # if input is nonzero, go north (continue loop)
- # else, keep going (enter red path)
- # red path: end
- v> # go south, then east (enter third line)
- } # right rotate stack (put input on bottom)
- K # stack reduce (do until <2 items)...
- O # output number
- @ # end
- ```
- [Try it online!][TIO-kt28kj38]
- [Ahead]: https://github.com/ajc2/ahead
- [TIO-kt28kj38]: https://tio.run/##S8xITUz5/9/TzspItYirLM9K3yjGhsuu1tvf4f9/QyMA "Ahead – Try It Online"