Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ## Assignment 1
- :: Start a gate with a single atom as argument
- ::
- |= n=@
- :: Call the 'goldbach' arm on the following core
- ::
- =< (goldbach n)
- :: Start the core
- ::
- |%
- :: Create an arm called 'prime'
- :: This arm should return true if the argument is prime
- ::
- ++ prime
- :: Start a gate with a single atom as argument
- ::
- |= n=@
- :: Cast the result to a loobean
- ::
- ^- ?
- :: If n is less than 2, return false
- ::
- ?: (lth n 2) |
- :: Else:
- :: If n is less than 4, return true
- ::
- ?: (lth n 4) &
- :: Otherwise:
- :: Add a variable i with type atom and value 2 to the subject
- ::
- =/ i=@ 2
- :: Add a variable j with type atom and value 2 to the subject
- ::
- =/ j=@ 2
- :: Start a trap, casting to loobean
- ::
- |- ^- ?
- :: If i * j is equal to n, return false
- ::
- ?: =((mul i j) n) |
- :: Else:
- :: If j is equal to n / 2, return true
- ::
- ?: =(j (div n 2)) &
- :: Otherwise:
- :: If i * j is greater than n
- ::
- ?: (gth (mul i j) n)
- :: Recurse, setting i to 2 and incrementing j
- $(i 2, j +(j))
- :: Else:
- :: Recurse, incrementing i
- $(i +(i))
- :: Create an arm called 'prime'
- ::
- ++ goldbach
- :: Start a gate with a single atom as argument
- ::
- |= n=@
- :: Cast the result to either a loobean or a cell
- :: containing a cell of atoms and a loobean
- ::
- ^- ?(? [[@ @] ?])
- :: If n is less than 4, or n is odd, return false
- ::
- ?: |((lth n 4) =((mod n 2) 1)) |
- :: Else:
- :: Add a variable i with type atom and value 2 to the subject
- ::
- =/ i=@ 2
- :: Add a variable j with type atom and value n - 2 to the subject
- ::
- =/ j=@ (sub n 2)
- :: Start a trap, casting the result to either a loobean or a cell
- :: containing a cell of atoms and a loobean
- ::
- |- ^- ?(? [[@ @] ?])
- :: If both i and j are prime, return a cell [[i j] |]
- ::
- ?: &((prime i) (prime j)) [[i j] |]
- :: Else:
- :: If i + 2 is equal to n, return true
- ::
- ?: =((add 2 i) n) &
- :: Otherwise:
- :: Recurse, incrementing i and decrementing j
- ::
- $(i +(i), j (dec j))
- :: Close the core
- ::
- --
- ## Assignment 2
- :: I couldn't figure out how to concatenate a list of cords
- :: while adding spaces in between; so I return a list of cords instead:
- ::
- :: > +assignment5b "hoon"
- :: <|.... --- --- -.|>
- ::
- |= raw=tape
- =< (convert (cuss raw))
- |%
- ++ convert
- |= [raw=tape]
- :: ^- tape
- (turn raw convert-char)
- ++ convert-char
- |= [char=@tD]
- ^- cord
- =/ chart ~(got by table)
- (chart char)
- ++ 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' '----.'
- ==
- --
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement