test
This commit is contained in:
parent
a638f4bd24
commit
1aed5df049
@ -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)
|
||||
|
36
week3/week3.txt
Normal file
36
week3/week3.txt
Normal file
@ -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)
|
89
week5/goldman.hoon
Normal file
89
week5/goldman.hoon
Normal 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
|
51
week5/morse.hoon
Normal file
51
week5/morse.hoon
Normal file
@ -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' '----.'
|
||||
==
|
||||
--
|
Loading…
Reference in New Issue
Block a user