My work for Hoon 101. Will remain private until the class is over.
Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

90 Zeilen
2.6KB

  1. :: create a gate taking an atom as input, giving it the face 'n'
  2. ::
  3. |= n=@
  4. :: compose the calling of `goldbach` with the core containing goldbach
  5. :: this has the effect of `running` the core when the outer gate is run
  6. ::
  7. =< (goldbach n)
  8. :: form a core
  9. ::
  10. |%
  11. :: create an arm named 'prime'
  12. ::
  13. ++ prime
  14. :: create a gate with an atom input given the face 'n'
  15. ::
  16. |= n=@
  17. :: typecast the output to a flag
  18. ::
  19. ^- ?
  20. :: if n is less than two, return false, otherwise return the other branch
  21. ::
  22. ?: (lth n 2) |
  23. :: if n is less than 4, return true, otherwise return the other branch
  24. ::
  25. ?: (lth n 4) &
  26. :: add the atom named i to the subject, set to 2
  27. ::
  28. =/ i=@ 2
  29. :: add the atom named j to the subject, set to 2
  30. ::
  31. =/ j=@ 2
  32. :: create a gate and typecast the output to a flag
  33. ::
  34. |- ^- ?
  35. :: if i * j equals n, return false, otherwise return the other branch
  36. ::
  37. ?: =((mul i j) n) |
  38. :: if j is equal to n/2, return true, otherwise return the other branch
  39. ::
  40. ?: =(j (div n 2)) &
  41. :: if i*j is greater than n, return the first branch, else the second
  42. ::
  43. ?: (gth (mul i j) n)
  44. :: call the current battery (defined at the gate) with a modified payload
  45. :: of i set to 2, and j incremented by one
  46. ::
  47. $(i 2, j +(j))
  48. :: call the current battery with the modified payload of i incremented by one
  49. ::
  50. $(i +(i))
  51. :: start a new arm called goldbach (this arm gets called with the tisgal)
  52. ::
  53. ++ goldbach
  54. :: create a gate with an input atom faced 'n'
  55. ::
  56. |= n=@
  57. :: typecast the output as a union of a flag (?)
  58. :: and a cell of a cell of atoms, and a flag ([[@ @] ?])
  59. ::
  60. ^- ?(? [[@ @] ?])
  61. :: if one of; n is less than 4, or n is odd, is true, return false
  62. :: otherwise return the other branch
  63. ::
  64. ?: |((lth n 4) =((mod n 2) 1)) |
  65. :: attach an atom name i to the subject, set to 2
  66. ::
  67. =/ i=@ 2
  68. :: attach an atom name i to the subject, set to n minus 2
  69. ::
  70. =/ j=@ (sub n 2)
  71. :: create a trap, and typecast the output to the aformentioned union of
  72. :: flag and cell of cell of atoms, and flag
  73. ::
  74. |- ^- ?(? [[@ @] ?])
  75. :: if both i and j are prime numbers, return a cell of:
  76. :: a cell of i and j, and a false flag
  77. :: otherwise return the other branch
  78. ::
  79. ?: &((prime i) (prime j)) [[i j] |]
  80. :: if n is equal to i plus 2, return a true flag, otherwise the next branch
  81. ::
  82. ?: =((add 2 i) n) &
  83. :: run the current battery, with an updated payload of
  84. :: i incremented, and j decremented
  85. ::
  86. $(i +(i), j (dec j))
  87. :: close off the core
  88. ::
  89. -- :: this is for my pal ~rapfyr-diglyt