remembered to update

This commit is contained in:
tA 2019-09-26 14:47:30 +12:00
parent 2b9b002e1c
commit aac01b3ce3
12 changed files with 310 additions and 0 deletions

89
101/week5/goldman.hoon Normal file
View file

@ -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

64
101/week5/morse.hoon Normal file
View file

@ -0,0 +1,64 @@
:: 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
=<
=. raw (cuss raw)
(convert raw)
|%
:: the latest and greatest rapper
++ mcelem
|= l=@t
?|
&((gte l 'A') (lte l 'Z'))
&((gte l '0') (lte l '9'))
==
++ convert
|= m=tape
^- tape
%- zing
%+ turn m
|= l=@t
?: =(l ' ')
"[_]"
?: (mcelem l)
~[' ' (~(got by table) l) ' ']
~['[' l ']']
++ 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' '----.'
==
--