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.
Created
May 16, 2018 22:30
-
-
Save tacryt-socryp/c5850b73c71e172b272b0ab5266c75da to your computer and use it in GitHub Desktop.
Decrement written in Hoon
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/+ mylib :: import | |
=, mylib :: alias to the subject (don't have to type mylib anymore) | |
|= a=@ | |
^- @ | |
(new-dec a) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
|% | |
++ 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