Skip to content

Instantly share code, notes, and snippets.

@etscrivner
Created July 10, 2016 20:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save etscrivner/1a0292ed7b11ac2249ccc1808f56be0e to your computer and use it in GitHub Desktop.
Save etscrivner/1a0292ed7b11ac2249ccc1808f56be0e to your computer and use it in GitHub Desktop.
Hoon for producing triangular/tetrahedral numbers.
|= number/@
=/ curnum 1
|- ^- (list @)
?: (gth curnum number) ~
:_ $(curnum (add 1 curnum))
=< (roll (triangular curnum) add)
|%
++ iota
|= {start/@ end/@}
=/ count start
|- ^- (list @)
?: (gth count end)
~
:_ $(count (add 1 count))
count
++ triangular
|= n/@
=/ next 1
|- ^- (list @)
?: (gth next n) ~
:_ $(next (add 1 next))
(roll (iota [1 next]) add)
--
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment