diff options
| author | Dave Jacoby <jacoby.david@gmail.com> | 2021-08-16 15:30:40 -0400 |
|---|---|---|
| committer | Dave Jacoby <jacoby.david@gmail.com> | 2021-08-16 15:30:40 -0400 |
| commit | 637f7bbeceeaf4a26e1e6ecba8c6fcb308790bb3 (patch) | |
| tree | 9809af6d10a767e998f569b80cabfdeb979ece95 /challenge-125/stuart-little/lua/ch-1.lua | |
| parent | 989dcde471a30935b8e51c557b971496963caffc (diff) | |
| parent | d9bbad705412903ffd55fb8c07bedcaeae734f85 (diff) | |
| download | perlweeklychallenge-club-637f7bbeceeaf4a26e1e6ecba8c6fcb308790bb3.tar.gz perlweeklychallenge-club-637f7bbeceeaf4a26e1e6ecba8c6fcb308790bb3.tar.bz2 perlweeklychallenge-club-637f7bbeceeaf4a26e1e6ecba8c6fcb308790bb3.zip | |
Merge branch 'master' of https://github.com/manwar/perlweeklychallenge-club
Diffstat (limited to 'challenge-125/stuart-little/lua/ch-1.lua')
| -rwxr-xr-x | challenge-125/stuart-little/lua/ch-1.lua | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/challenge-125/stuart-little/lua/ch-1.lua b/challenge-125/stuart-little/lua/ch-1.lua new file mode 100755 index 0000000000..5358490334 --- /dev/null +++ b/challenge-125/stuart-little/lua/ch-1.lua @@ -0,0 +1,27 @@ +#!/usr/bin/env lua + +-- run <script> <number> + +function trps(n) + local triples={} + for i=1,math.floor((n+1)/2) do + local sqDif=math.floor(math.sqrt(n^2-i^2)) + if i<n and i^2+sqDif^2==n^2 then table.insert(triples,{i,sqDif,n}) end + end + for i=1,n-1 do + if n^2 % i == 0 and i%2 == (math.floor(n^2/i))%2 then + local s = math.floor(n^2/i) + table.insert(triples,{math.floor((s-i)/2), n, math.floor((s+i)/2)}) + end + end + return triples +end + +local sol = trps(tonumber(arg[1])) +if #sol>0 then + for _,v in ipairs(sol) do + print(table.unpack(v)) + end + os.exit() +end +print(-1) |
