Advertisement
Guest User

Untitled

a guest
Aug 18th, 2019
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.34 KB | None | 0 0
  1. ## Assignment 1
  2.  
  3. :: Start a gate with a single atom as argument
  4. ::
  5. |= n=@
  6. :: Call the 'goldbach' arm on the following core
  7. ::
  8. =< (goldbach n)
  9. :: Start the core
  10. ::
  11. |%
  12. :: Create an arm called 'prime'
  13. :: This arm should return true if the argument is prime
  14. ::
  15. ++ prime
  16. :: Start a gate with a single atom as argument
  17. ::
  18. |= n=@
  19. :: Cast the result to a loobean
  20. ::
  21. ^- ?
  22. :: If n is less than 2, return false
  23. ::
  24. ?: (lth n 2) |
  25. :: Else:
  26. :: If n is less than 4, return true
  27. ::
  28. ?: (lth n 4) &
  29. :: Otherwise:
  30. :: Add a variable i with type atom and value 2 to the subject
  31. ::
  32. =/ i=@ 2
  33. :: Add a variable j with type atom and value 2 to the subject
  34. ::
  35. =/ j=@ 2
  36. :: Start a trap, casting to loobean
  37. ::
  38. |- ^- ?
  39. :: If i * j is equal to n, return false
  40. ::
  41. ?: =((mul i j) n) |
  42. :: Else:
  43. :: If j is equal to n / 2, return true
  44. ::
  45. ?: =(j (div n 2)) &
  46. :: Otherwise:
  47. :: If i * j is greater than n
  48. ::
  49. ?: (gth (mul i j) n)
  50. :: Recurse, setting i to 2 and incrementing j
  51. $(i 2, j +(j))
  52. :: Else:
  53. :: Recurse, incrementing i
  54. $(i +(i))
  55. :: Create an arm called 'prime'
  56. ::
  57. ++ goldbach
  58. :: Start a gate with a single atom as argument
  59. ::
  60. |= n=@
  61. :: Cast the result to either a loobean or a cell
  62. :: containing a cell of atoms and a loobean
  63. ::
  64. ^- ?(? [[@ @] ?])
  65. :: If n is less than 4, or n is odd, return false
  66. ::
  67. ?: |((lth n 4) =((mod n 2) 1)) |
  68. :: Else:
  69. :: Add a variable i with type atom and value 2 to the subject
  70. ::
  71. =/ i=@ 2
  72. :: Add a variable j with type atom and value n - 2 to the subject
  73. ::
  74. =/ j=@ (sub n 2)
  75. :: Start a trap, casting the result to either a loobean or a cell
  76. :: containing a cell of atoms and a loobean
  77. ::
  78. |- ^- ?(? [[@ @] ?])
  79. :: If both i and j are prime, return a cell [[i j] |]
  80. ::
  81. ?: &((prime i) (prime j)) [[i j] |]
  82. :: Else:
  83. :: If i + 2 is equal to n, return true
  84. ::
  85. ?: =((add 2 i) n) &
  86. :: Otherwise:
  87. :: Recurse, incrementing i and decrementing j
  88. ::
  89. $(i +(i), j (dec j))
  90. :: Close the core
  91. ::
  92. --
  93.  
  94. ## Assignment 2
  95.  
  96. :: I couldn't figure out how to concatenate a list of cords
  97. :: while adding spaces in between; so I return a list of cords instead:
  98. ::
  99. :: > +assignment5b "hoon"
  100. :: <|.... --- --- -.|>
  101. ::
  102. |= raw=tape
  103. =< (convert (cuss raw))
  104. |%
  105. ++ convert
  106. |= [raw=tape]
  107. :: ^- tape
  108. (turn raw convert-char)
  109. ++ convert-char
  110. |= [char=@tD]
  111. ^- cord
  112. =/ chart ~(got by table)
  113. (chart char)
  114. ++ table
  115. %- my
  116. :~ :- 'A' '.-'
  117. :- 'B' '-...'
  118. :- 'C' '-.-.'
  119. :- 'D' '-..'
  120. :- 'E' '.'
  121. :- 'F' '..-.'
  122. :- 'G' '--.'
  123. :- 'H' '....'
  124. :- 'I' '..'
  125. :- 'J' '.---'
  126. :- 'K' '-.-'
  127. :- 'L' '.-..'
  128. :- 'M' '--'
  129. :- 'N' '-.'
  130. :- 'O' '---'
  131. :- 'P' '.--.'
  132. :- 'Q' '--.-'
  133. :- 'R' '.-.'
  134. :- 'S' '...'
  135. :- 'T' '-'
  136. :- 'U' '..-'
  137. :- 'V' '...-'
  138. :- 'W' '.--'
  139. :- 'X' '-..-'
  140. :- 'Y' '-.--'
  141. :- 'Z' '--..'
  142. :- '0' '-----'
  143. :- '1' '.----'
  144. :- '2' '..---'
  145. :- '3' '...--'
  146. :- '4' '....-'
  147. :- '5' '.....'
  148. :- '6' '-....'
  149. :- '7' '--...'
  150. :- '8' '---..'
  151. :- '9' '----.'
  152. ==
  153. --
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement