Advertisement
keatondunsford

Hoon Project Euler 9, attempt #1 - `nest-fail`

Feb 25th, 2017
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.46 KB | None | 0 0
  1. :: Project Euler 9
  2. :: https://projecteuler.net/problem=9
  3. ::
  4. :: > A Pythagorean triplet is a set of three natural numbers, a < b < c, for
  5. :: > which,
  6. :: > > a2 + b2 = c2
  7. :: > For example, 3^2 + 4^2 = 9 + 16 = 25 = 5^2.
  8. :: > There exists exactly one Pythagorean triplet for which a + b + c = 1000.
  9. :: > Find the product abc.
  10. ::
  11. /? 310
  12. ::
  13. !:
  14. ::
  15. :- %say |= *
  16. :- %noun
  17. =< (find-pythagorean-triplet-abc-sum-eq-one-thousand [1 1 998])
  18. ::
  19. !.
  20. ::
  21. |%
  22. ++ find-pythagorean-triplet-abc-sum-eq-one-thousand
  23. |= {a/@u b/@u c/@u} :: gate, takes 3 numbers
  24. =| p/@u :: product, abc, set l8r
  25. |- ^- @u :: loop, prod is 1 num.
  26. ?: p p :: if p, produce p (abc)
  27. ?> =((add (add a b) c) 1.000) :: else, sure a+b+c=1000
  28. %= $ :: call loop.
  29. a |- ^- @u :: a -> new loop product
  30. ?: =((add (mul a a) (mul b b)) (mul c c)) :: if pythagorean trip.,
  31. ~& [a b c] :: prints cell [a b c].
  32. ^$(p (mul (mul a b) c)) :: p -> abc (outer loop)
  33. ?: =(b c) :: else, if no combos =,
  34. +(a) :: increment a.
  35. $(b +(b), c (dec c)) :: else, this loop +b -c
  36. c (dec c) :: c -> decrement c.
  37. ==
  38. --
  39.  
  40.  
  41.  
  42. > +examples/euler9
  43. /~rep/home/~2017.2.6..22.48.38..23d6/arvo/ford:<[1.211 24].[1.211 52]>
  44. /~difmyn-tipsut-ricnec-fidped--tadbex-watten-disfet-witbyn/home/0/gen/examples/euler9:<[13 1].[38 3]>
  45. /~difmyn-tipsut-ricnec-fidped--tadbex-watten-disfet-witbyn/home/0/gen/examples/euler9:<[15 1].[38 3]>
  46. /~difmyn-tipsut-ricnec-fidped--tadbex-watten-disfet-witbyn/home/0/gen/examples/euler9:<[15 11].[38 3]>
  47. /~difmyn-tipsut-ricnec-fidped--tadbex-watten-disfet-witbyn/home/0/gen/examples/euler9:<[16 1].[38 3]>
  48. /~difmyn-tipsut-ricnec-fidped--tadbex-watten-disfet-witbyn/home/0/gen/examples/euler9:<[17 1].[38 3]>
  49. /~difmyn-tipsut-ricnec-fidped--tadbex-watten-disfet-witbyn/home/0/gen/examples/euler9:<[19 1].[38 3]>
  50. nest-fail
  51. ford: core /~difmyn-tipsut-ricnec-fidped--tadbex-watten-disfet-witbyn/home/~2017.2.25..23.30.05..9735/gen/examples/euler9
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement