Advertisement
Guest User

rivlys-dalsun-week5.hoon

a guest
Aug 20th, 2019
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.02 KB | None | 0 0
  1. :: Assignment A
  2. :: create a gate that accepts an atom and give it the face n
  3. ::
  4. |= n=@
  5. :: evaluate the first child expression with respect to its second child expression as the subject
  6. ::
  7. =< (goldbach n)
  8. |%
  9. :: define arm with the face prime to check if input atom is a prime number
  10. ::
  11. ++ prime
  12. :: create gate that accepts atom and gives it face of n
  13. ::
  14. |= n=@
  15. :: cast output as flag
  16. ::
  17. ^- ?
  18. :: if n is less than 2 produce %.n (not prime numbers)
  19. ::
  20. ?: (lth n 2) |
  21. :: if n is less than 4 (i.e. 3) produce %.y (3 is prime)
  22. ::
  23. ?: (lth n 4) &
  24. :: if n is less than 4 create two atoms with faces of i and j and initial values of 2
  25. ::
  26. =/ i=@ 2
  27. =/ j=@ 2
  28. :: create recursion trap that returns loobean when recursion exits
  29. |- ^- ?
  30. :: if i x j equals n
  31. ?: =((mul i j) n) |
  32. :: or if j equals n divided by 2
  33. ?: =(j (div n 2)) &
  34. :: and if i x j is greater than n
  35. ?: (gth (mul i j) n)
  36. :: set i to 2 and increment j
  37. $(i 2, j +(j))
  38. :: increment i
  39. $(i +(i))
  40. :: define arm with the face goldbach
  41. ::
  42. ++ goldbach
  43. :: create a gate that accepts an atom with the face n
  44. |= n=@
  45. :: cast output to loobean or cell encapsulating a cell of two atoms and a loobean
  46. ^- ?(? [[@ @] ?])
  47. :: if n is less than 4 or n modulo 2 remainder is 1
  48. ?: |((lth n 4) =((mod n 2) 1)) |
  49. :: create atom with face i and initial value of 2
  50. =/ i=@ 2
  51. :: create atom with face j and initial value of n - 2
  52. =/ j=@ (sub n 2)
  53. :: create trap that casts output to loobean or cell encapsulating a cell of two atoms and a loobean
  54. |- ^- ?(? [[@ @] ?])
  55. :: if i and j are prime numbers return cell encapsulating cell of i and j and produce %.n
  56. ?: &((prime i) (prime j)) [[i j] |]
  57. :: if addition of 2 and i equals n produce %.y
  58. ?: =((add 2 i) n) &
  59. :: recurse incrementing i and decrementing j
  60. $(i +(i), j (dec j))
  61. :: close core
  62. --
  63.  
  64.  
  65. :: Assignment B
  66. :: Convert message into morse code
  67. |= raw=tape
  68. =< (convert (cuss raw))
  69. |%
  70. ++ convert
  71. |= message=tape
  72. ^- tape
  73. =| morse=tape
  74. |-
  75. ?~ message morse
  76. =/ chart (~(got by table) i.message)
  77. $(message t.message, morse (weld morse (trip chart)))
  78. ++ table
  79. %- my
  80. :~ :- 'A' '.-'
  81. :- 'B' '-...'
  82. :- 'C' '-.-.'
  83. :- 'D' '-..'
  84. :- 'E' '.'
  85. :- 'F' '..-.'
  86. :- 'G' '--.'
  87. :- 'H' '....'
  88. :- 'I' '..'
  89. :- 'J' '.---'
  90. :- 'K' '-.-'
  91. :- 'L' '.-..'
  92. :- 'M' '--'
  93. :- 'N' '-.'
  94. :- 'O' '---'
  95. :- 'P' '.--.'
  96. :- 'Q' '--.-'
  97. :- 'R' '.-.'
  98. :- 'S' '...'
  99. :- 'T' '-'
  100. :- 'U' '..-'
  101. :- 'V' '...-'
  102. :- 'W' '.--'
  103. :- 'X' '-..-'
  104. :- 'Y' '-.--'
  105. :- 'Z' '--..'
  106. :- '0' '-----'
  107. :- '1' '.----'
  108. :- '2' '..---'
  109. :- '3' '...--'
  110. :- '4' '....-'
  111. :- '5' '.....'
  112. :- '6' '-....'
  113. :- '7' '--...'
  114. :- '8' '---..'
  115. :- '9' '----.'
  116. :- ' ' ' '
  117. ==
  118. --
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement