From 1aed5df049a0fa1c886dfe17e2cd0d6ff94c7e0d Mon Sep 17 00:00:00 2001 From: tA Date: Thu, 8 Aug 2019 15:40:11 +1200 Subject: [PATCH] test --- week3/week3.hoon | 10 +++--- week3/week3.txt | 36 ++++++++++++++++++++++ week5/goldman.hoon | 89 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ week5/morse.hoon | 51 +++++++++++++++++++++++++++++++ 4 files changed, 181 insertions(+), 5 deletions(-) create mode 100644 week3/week3.txt create mode 100644 week5/goldman.hoon create mode 100644 week5/morse.hoon diff --git a/week3/week3.hoon b/week3/week3.hoon index 647b75d..2ae12a5 100644 --- a/week3/week3.hoon +++ b/week3/week3.hoon @@ -1,8 +1,8 @@ |= a=(list *) -=/ n=@ud 3 +=/ n=@ud 1 |- -?~ a ~ -?: =(1 n) +?~ a + %napoleonesque-list +?: =(3 n) i.a -$(n (dec n), a t.a) - +$(n +(n), a t.a) diff --git a/week3/week3.txt b/week3/week3.txt new file mode 100644 index 0000000..f6792ed --- /dev/null +++ b/week3/week3.txt @@ -0,0 +1,36 @@ +:: 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)) + +:: Hoon 101 - Week 3 Assignment +:: ~bannum-magtus | s@p7.co.nz +:: +|= a=(list *) +=/ n=@ud 1 +|- +?~ a + %napoleonesque-list +?: =(3 n) + i.a +$(n +(n), a t.a) diff --git a/week5/goldman.hoon b/week5/goldman.hoon new file mode 100644 index 0000000..b652b5b --- /dev/null +++ b/week5/goldman.hoon @@ -0,0 +1,89 @@ +:: create a gate taking an atom as input, giving it the face 'n' +:: +|= n=@ +:: compose the calling of `goldbach` with the core containing goldbach +:: this has the effect of `running` the core when the outer gate is run +:: +=< (goldbach n) +:: form a core +:: +|% +:: create an arm named 'prime' +:: +++ prime + :: create a gate with an atom input given the face 'n' + :: + |= n=@ + :: typecast the output to a flag + :: + ^- ? + :: if n is less than two, return false, otherwise return the other branch + :: + ?: (lth n 2) | + :: if n is less than 4, return true, otherwise return the other branch + :: + ?: (lth n 4) & + :: add the atom named i to the subject, set to 2 + :: + =/ i=@ 2 + :: add the atom named j to the subject, set to 2 + :: + =/ j=@ 2 + :: create a gate and typecast the output to a flag + :: + |- ^- ? + :: if i * j equals n, return false, otherwise return the other branch + :: + ?: =((mul i j) n) | + :: if j is equal to n/2, return true, otherwise return the other branch + :: + ?: =(j (div n 2)) & + :: if i*j is greater than n, return the first branch, else the second + :: + ?: (gth (mul i j) n) + :: call the current battery (defined at the gate) with a modified payload + :: of i set to 2, and j incremented by one + :: + $(i 2, j +(j)) + :: call the current battery with the modified payload of i incremented by one + :: + $(i +(i)) +:: start a new arm called goldbach (this arm gets called with the tisgal) +:: +++ goldbach + :: create a gate with an input atom faced 'n' + :: + |= n=@ + :: typecast the output as a union of a flag (?) + :: and a cell of a cell of atoms, and a flag ([[@ @] ?]) + :: + ^- ?(? [[@ @] ?]) + :: if one of; n is less than 4, or n is odd, is true, return false + :: otherwise return the other branch + :: + ?: |((lth n 4) =((mod n 2) 1)) | + :: attach an atom name i to the subject, set to 2 + :: + =/ i=@ 2 + :: attach an atom name i to the subject, set to n minus 2 + :: + =/ j=@ (sub n 2) + :: create a trap, and typecast the output to the aformentioned union of + :: flag and cell of cell of atoms, and flag + :: + |- ^- ?(? [[@ @] ?]) + :: if both i and j are prime numbers, return a cell of: + :: a cell of i and j, and a false flag + :: otherwise return the other branch + :: + ?: &((prime i) (prime j)) [[i j] |] + :: if n is equal to i plus 2, return a true flag, otherwise the next branch + :: + ?: =((add 2 i) n) & + :: run the current battery, with an updated payload of + :: i incremented, and j decremented + :: + $(i +(i), j (dec j)) +:: close off the core +:: +-- :: this is for my pal ~rapfyr-diglyt diff --git a/week5/morse.hoon b/week5/morse.hoon new file mode 100644 index 0000000..ac374cd --- /dev/null +++ b/week5/morse.hoon @@ -0,0 +1,51 @@ +:: the comment ":: code belongs here" indicates that one or more lines of code are needed to make this section of the program work. + +|= raw=tape +=< + :: code belongs here +|% +++ convert + :: code belongs here + :: (~(got by a) b) produces the value located at key b within map a + =/ chart ~(got by table) + :: code belongs here +++ table + %- my + :~ :- 'A' '.-' + :- 'B' '-...' + :- 'C' '-.-.' + :- 'D' '-..' + :- 'E' '.' + :- 'F' '..-.' + :- 'G' '--.' + :- 'H' '....' + :- 'I' '..' + :- 'J' '.---' + :- 'K' '-.-' + :- 'L' '.-..' + :- 'M' '--' + :- 'N' '-.' + :- 'O' '---' + :- 'P' '.--.' + :- 'Q' '--.-' + :- 'R' '.-.' + :- 'S' '...' + :- 'T' '-' + :- 'U' '..-' + :- 'V' '...-' + :- 'W' '.--' + :- 'X' '-..-' + :- 'Y' '-.--' + :- 'Z' '--..' + :- '0' '-----' + :- '1' '.----' + :- '2' '..---' + :- '3' '...--' + :- '4' '....-' + :- '5' '.....' + :- '6' '-....' + :- '7' '--...' + :- '8' '---..' + :- '9' '----.' + == +--