Advertisement
Guest User

Untitled

a guest
Dec 7th, 2019
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.62 KB | None | 0 0
  1. commented factorial:
  2.  
  3. :: produce a gate w/ sample n, an unsigned decimal number
  4. ::
  5. |= n=@ud
  6. :: combine unsigned decimal 1 w/ face t with the subject
  7. ::
  8. =/ t=@ud 1
  9. :: produce and evaluate trap. Starting point for recursion.
  10. ::
  11. |-
  12. :: If n is equal to 1, return t, the completed factorial
  13. ::
  14. ?: =(n 1)
  15. t
  16. :: else tail recurse, decrement n, t as running product of the factorial
  17. ::
  18. $(n (dec n), t (mul t n))
  19.  
  20. return third element of list without standard library list functions:
  21.  
  22. |= input=(list @)
  23. =/ count 2
  24. |-
  25. ?: =(count 0)
  26. ?~(input ~ i.input)
  27. $(input ?~(input ~ t.input), count (dec count))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement