From a638f4bd2474453313d9965f9b4213b825037725 Mon Sep 17 00:00:00 2001 From: techieAgnostic Date: Tue, 23 Jul 2019 20:48:22 +1200 Subject: [PATCH] week3 --- week3/assignment_3a.hoon | 24 ++++++++++++++++++++++++ week3/week3.hoon | 8 ++++++++ 2 files changed, 32 insertions(+) create mode 100644 week3/assignment_3a.hoon create mode 100644 week3/week3.hoon diff --git a/week3/assignment_3a.hoon b/week3/assignment_3a.hoon new file mode 100644 index 0000000..5d60635 --- /dev/null +++ b/week3/assignment_3a.hoon @@ -0,0 +1,24 @@ +:: Hoon 101: Assignment 3a. Comment each line of code to tell the reader what the code is doing. +:: Comments should be written as "breathing comments" as suggested in the Hoon Style Guide: https://urbit.org/docs/learn/hoon/style/ + +:: create a gate, with the sample @ud, given the face n +:: +|= n=@ud +:: attach a 't' faced @ud to the subject, with the value 1 +:: +=/ t=@ud 1 +:: create and execute a gate, such that we can recurse back to this point +:: +|- +:: if n is 1, return the next child, otherwise the one after +:: +?: =(n 1) +:: at the end, return our total +:: + t +:: otherwise recurse with n minus one, +:: and t multiplied by n. note t is +:: not reset with the recurse, as it +:: is attached before our recurse point +:: +$(n (dec n), t (mul t n)) diff --git a/week3/week3.hoon b/week3/week3.hoon new file mode 100644 index 0000000..647b75d --- /dev/null +++ b/week3/week3.hoon @@ -0,0 +1,8 @@ +|= a=(list *) +=/ n=@ud 3 +|- +?~ a ~ +?: =(1 n) + i.a +$(n (dec n), a t.a) +