Advertisement
sanlyt-modbyt

assignment3.hoon

Jul 29th, 2019
40
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.16 KB | None | 0 0
  1.  
  2. :: Hoon 101: Assignment 3a. Comment each line of code to tell the reader what the code is doing.
  3. :: Comments should be written as "breathing comments" as suggested in the Hoon Style Guide: https://urbit.org/docs/learn/hoon/style/
  4.  
  5. |= n=@ud
  6. :: This is a gate that assigns the face n to an unsigned decimal
  7. ::
  8. =/ t=@ud 1
  9. :: This assigns a face to an unsigned decimal (ud) and sets its initial value to 1
  10. ::
  11. |-
  12. :: This creates a new one $ armed gate and call the gate
  13. ::
  14. ?: =(n 1)
  15. :: This is a boolean which branches on whether n is equal to 1
  16. ::
  17. t
  18. ::If n is equal to one, we print t.
  19. ::
  20. $(n (dec n), t (mul t n))
  21. ::If n is not equal to one, the recursion starts. We start by multiplying n by t, which produces a new value for t. We then decrement n by 1, and multiply this new n by our new t, which gives us an even newer t. We decrement our new n to find a newer n, and mulitply this by our even newer t. This goes on until n=1 and, will return n!.
  22. ::
  23.  
  24.  
  25. Assignment 3b
  26. :: This doesn't work, but I just got called in to emergency bar tend, and this is what I am currently tinkering with:
  27.  
  28. |= b=(list @)
  29. =/ a=@ud 3
  30. ?: =(a 0) i.b
  31. $(a (dec a), b t.b)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement