remembered to update
This commit is contained in:
parent
2b9b002e1c
commit
aac01b3ce3
12 changed files with 310 additions and 0 deletions
7
101/week1/week1.hoon
Normal file
7
101/week1/week1.hoon
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
:: Hoon School - Week 1
|
||||
:: ~bannum-magtus || s@p7.co.nz
|
||||
::
|
||||
|= inp=@ :: 1 - create a gate with one atom input, 'inp'
|
||||
^- @p :: 2 - use kethep to cast inp to a planet aura
|
||||
inp :: 3 - close the kethep, and ergo close the bartis
|
||||
|
||||
13
101/week2/week2.hoon
Normal file
13
101/week2/week2.hoon
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
:: Hoon School - Week 2
|
||||
:: ~bannum-magtus || s@p7.co.nz
|
||||
::
|
||||
|= a=* :: take in any noun
|
||||
^- tape :: explicitly return a tape
|
||||
%+ weld :: weld some strings to reduce repitition
|
||||
"input is " ::
|
||||
?^ a :: first branch, test whether a is a cell
|
||||
"a cell" ::
|
||||
=- (weld - " atom") :: attach a block to the head of the subject
|
||||
?: =((mod a 2) 0) :: mod is safe because we know a isnt a cell
|
||||
"an even" ::
|
||||
"an odd" ::
|
||||
24
101/week3/assignment_3a.hoon
Normal file
24
101/week3/assignment_3a.hoon
Normal file
|
|
@ -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))
|
||||
8
101/week3/week3.hoon
Normal file
8
101/week3/week3.hoon
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
|= a=(list *)
|
||||
=/ n=@ud 1
|
||||
|-
|
||||
?~ a
|
||||
%napoleonesque-list
|
||||
?: =(3 n)
|
||||
i.a
|
||||
$(n +(n), a t.a)
|
||||
36
101/week3/week3.txt
Normal file
36
101/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)
|
||||
40
101/week4/week4.hoon
Normal file
40
101/week4/week4.hoon
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
:: Hoon 101 - Week 4
|
||||
:: ~bannum-magtus || s@p7.co.nz
|
||||
::
|
||||
|= n=@
|
||||
^- @
|
||||
=< (wrrrm n)
|
||||
|%
|
||||
::
|
||||
:: the atom made a 'clink' as it fell into the hole
|
||||
++ clink
|
||||
|= [a=@ b=@]
|
||||
^- ?
|
||||
=(0 (mod a b))
|
||||
::
|
||||
:: there was a 'clunk' as the atom fell multiple times
|
||||
++ clunk
|
||||
|= a=@
|
||||
^- ?
|
||||
?|
|
||||
(clink a 3)
|
||||
(clink a 5)
|
||||
==
|
||||
::
|
||||
:: a 'bzzrp' was heard as certain atoms were vapourised
|
||||
++ bzzrp
|
||||
|= a=@
|
||||
?: (clunk a)
|
||||
a
|
||||
0
|
||||
::
|
||||
:: 'wrrrm' was all you could hear as the machine started up
|
||||
++ wrrrm
|
||||
|= x=@
|
||||
^- @
|
||||
%- roll
|
||||
:_ add
|
||||
%- turn
|
||||
:_ bzzrp
|
||||
(gulf 1 x)
|
||||
--
|
||||
89
101/week5/goldman.hoon
Normal file
89
101/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
|
||||
64
101/week5/morse.hoon
Normal file
64
101/week5/morse.hoon
Normal 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' '----.'
|
||||
==
|
||||
--
|
||||
61
101/week6/cards.hoon
Normal file
61
101/week6/cards.hoon
Normal file
|
|
@ -0,0 +1,61 @@
|
|||
:: Hoon 101 - Week 6
|
||||
:: ~bannum-magtus || s@p7.co.nz
|
||||
::
|
||||
:- %say
|
||||
|= [[* eny=@uvJ *] [x=@ y=@ ~] ~]
|
||||
:- %noun
|
||||
?: (gth (mul x y) 52)
|
||||
!!
|
||||
=<
|
||||
:: Im so sorry
|
||||
(take-hands x y new-deck)
|
||||
|%
|
||||
++ take-hands
|
||||
|= [x=@ y=@ d=(list tape)]
|
||||
^- (list (list tape))
|
||||
=/ hands=(list (list tape)) ~
|
||||
|-
|
||||
?: =(x 0)
|
||||
hands
|
||||
%= $
|
||||
hands :-((scag y d) hands)
|
||||
d (slag y d)
|
||||
x (dec x)
|
||||
==
|
||||
++ suit-store
|
||||
^- (list tape)
|
||||
["H" "D" "C" "S" ~]
|
||||
++ suit-donnees
|
||||
^- (list tape)
|
||||
["A" "2" "3" "4" "5" "6" "7" "8" "9" "10" "J" "Q" "K" ~]
|
||||
++ new-deck
|
||||
=/ nd=(list tape) ~
|
||||
=/ s 0
|
||||
|-
|
||||
?: (gte s 4)
|
||||
(shuffle-deck nd eny)
|
||||
=/ v 0
|
||||
|-
|
||||
?. (lth v 13)
|
||||
^$(s +(s))
|
||||
%= $
|
||||
v +(v)
|
||||
nd :-((weld (snag v suit-donnees) (snag s suit-store)) nd)
|
||||
==
|
||||
++ shuffle-deck
|
||||
|= [unshuffled=(list tape) entropy=@]
|
||||
^- (list tape)
|
||||
=| shuffled=(list tape)
|
||||
=/ random ~(. og entropy)
|
||||
=/ remaining (lent unshuffled)
|
||||
|-
|
||||
?: =(remaining 1)
|
||||
:_ shuffled
|
||||
(snag 0 unshuffled)
|
||||
=^ index random (rads:random remaining)
|
||||
%= $
|
||||
shuffled (snag index unshuffled)^shuffled
|
||||
remaining (dec remaining)
|
||||
unshuffled (oust [index 1] unshuffled)
|
||||
==
|
||||
--
|
||||
Loading…
Add table
Add a link
Reference in a new issue