Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- :: Project Euler 9
- :: https://projecteuler.net/problem=9
- ::
- :: > A Pythagorean triplet is a set of three natural numbers, a < b < c, for
- :: > which,
- :: > > a2 + b2 = c2
- :: > For example, 3^2 + 4^2 = 9 + 16 = 25 = 5^2.
- :: > There exists exactly one Pythagorean triplet for which a + b + c = 1000.
- :: > Find the product abc.
- ::
- /? 310
- ::
- !:
- ::
- :- %say |= *
- :- %noun
- =< (find-pythagorean-triplet-abc-sum-eq-one-thousand [1 1 998])
- ::
- !.
- ::
- |%
- ++ find-pythagorean-triplet-abc-sum-eq-one-thousand
- |= {a/@u b/@u c/@u} :: gate, takes 3 numbers
- =| p/@u :: product, abc, set l8r
- |- ^- @u :: loop, prod is 1 num.
- ?: p p :: if p, produce p (abc)
- ?> =((add (add a b) c) 1.000) :: else, sure a+b+c=1000
- %= $ :: call loop.
- a |- ^- @u :: a -> new loop product
- ?: =((add (mul a a) (mul b b)) (mul c c)) :: if pythagorean trip.,
- ~& [a b c] :: prints cell [a b c].
- ^$(p (mul (mul a b) c)) :: p -> abc (outer loop)
- ?: =(b c) :: else, if no combos =,
- +(a) :: increment a.
- $(b +(b), c (dec c)) :: else, this loop +b -c
- c (dec c) :: c -> decrement c.
- ==
- --
- > +examples/euler9
- /~rep/home/~2017.2.6..22.48.38..23d6/arvo/ford:<[1.211 24].[1.211 52]>
- /~difmyn-tipsut-ricnec-fidped--tadbex-watten-disfet-witbyn/home/0/gen/examples/euler9:<[13 1].[38 3]>
- /~difmyn-tipsut-ricnec-fidped--tadbex-watten-disfet-witbyn/home/0/gen/examples/euler9:<[15 1].[38 3]>
- /~difmyn-tipsut-ricnec-fidped--tadbex-watten-disfet-witbyn/home/0/gen/examples/euler9:<[15 11].[38 3]>
- /~difmyn-tipsut-ricnec-fidped--tadbex-watten-disfet-witbyn/home/0/gen/examples/euler9:<[16 1].[38 3]>
- /~difmyn-tipsut-ricnec-fidped--tadbex-watten-disfet-witbyn/home/0/gen/examples/euler9:<[17 1].[38 3]>
- /~difmyn-tipsut-ricnec-fidped--tadbex-watten-disfet-witbyn/home/0/gen/examples/euler9:<[19 1].[38 3]>
- nest-fail
- 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