Hoon101/101/week3/week3.txt
2019-09-26 14:47:30 +12:00

37 lines
912 B
Plaintext

:: Hoon 101: Assignment 3a. Comment each line of code to tell the reader what the code is doing.
:: Comments should be written as "breathing comments" as suggested in the Hoon Style Guide: https://urbit.org/docs/learn/hoon/style/
:: create a gate, with the sample @ud, given the face n
::
|= n=@ud
:: attach a 't' faced @ud to the subject, with the value 1
::
=/ t=@ud 1
:: create and execute a gate, such that we can recurse back to this point
::
|-
:: if n is 1, return the next child, otherwise the one after
::
?: =(n 1)
:: at the end, return our total
::
t
:: otherwise recurse with n minus one,
:: and t multiplied by n. note t is
:: not reset with the recurse, as it
:: is attached before our recurse point
::
$(n (dec n), t (mul t n))
:: Hoon 101 - Week 3 Assignment
:: ~bannum-magtus | s@p7.co.nz
::
|= a=(list *)
=/ n=@ud 1
|-
?~ a
%napoleonesque-list
?: =(3 n)
i.a
$(n +(n), a t.a)