Skip to content

Instantly share code, notes, and snippets.

@tacryt-socryp
Created May 16, 2018 22:30
Show Gist options
  • Save tacryt-socryp/c5850b73c71e172b272b0ab5266c75da to your computer and use it in GitHub Desktop.
Save tacryt-socryp/c5850b73c71e172b272b0ab5266c75da to your computer and use it in GitHub Desktop.
Decrement written in Hoon

Decrement

Write a gate that takes some integer n and returns (n - 1). You may not use dec from the Hoon stdlib, and you may not look at the code for dec in hoon.hoon. You're under the honor system.

/+ mylib :: import
=, mylib :: alias to the subject (don't have to type mylib anymore)
|= a=@
^- @
(new-dec a)
|%
++ new-dec
|= a/@
^- @
?: (lte a 0) ::
0
?: (lte a 1)
0
%- inner-dec :+(a 1 0)
++ inner-dec
|= e=[a=@ b=[c=@ d=@]] :: sample (input mold)
^- @ :: return atom
::~& e :: printf
?: (gte c.b.e a.e) :: if (c.b.e >= a.e)
d.b.e :: yes, return result
%- inner-dec :+(a.e .+(c.b.e) .+(d.b.e)) :: no, call inner-dec with tuple of a.e (c.b.e + 1) and (d.b.e + 1)
--
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment