diff options
| author | Mohammad S Anwar <Mohammad.Anwar@yahoo.com> | 2022-01-10 18:31:57 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-01-10 18:31:57 +0000 |
| commit | ea660d1fd8df468cb05ea02c26c8af9d8a51b160 (patch) | |
| tree | bad4987ce5d530b1b7be774db7f2714cb3527c77 /challenge-147/roger-bell-west/lua/ch-2.lua | |
| parent | e9411bdc7658179af3f23d3ada7970323547a7d7 (diff) | |
| parent | 8580bd80aa9245695b20c075a18dfac2061f7579 (diff) | |
| download | perlweeklychallenge-club-ea660d1fd8df468cb05ea02c26c8af9d8a51b160.tar.gz perlweeklychallenge-club-ea660d1fd8df468cb05ea02c26c8af9d8a51b160.tar.bz2 perlweeklychallenge-club-ea660d1fd8df468cb05ea02c26c8af9d8a51b160.zip | |
Merge pull request #5497 from Firedrake/rogerbw-challenge-147
Solutions for challenge #147
Diffstat (limited to 'challenge-147/roger-bell-west/lua/ch-2.lua')
| -rwxr-xr-x | challenge-147/roger-bell-west/lua/ch-2.lua | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/challenge-147/roger-bell-west/lua/ch-2.lua b/challenge-147/roger-bell-west/lua/ch-2.lua new file mode 100755 index 0000000000..cbe31d0ed8 --- /dev/null +++ b/challenge-147/roger-bell-west/lua/ch-2.lua @@ -0,0 +1,38 @@ +#! /usr/bin/lua + +function pentagon(n) + return math.floor(n*(3*n-1)/2) +end + +function pentpair() + fpent={} + rpent={} + mx=0 + a=1 + while 1 do + while mx < a do + mx = mx + 1 + table.insert(fpent,pentagon(mx)) + rpent[fpent[mx]]=mx + end + for b = 1,a do + d=fpent[a]-fpent[b] + if rpent[d] ~= nil then + s=fpent[a]+fpent[b] + while s > fpent[mx] do + mx = mx + 1 + table.insert(fpent,pentagon(mx)) + rpent[fpent[mx]]=mx + end + if rpent[s] ~= nil then + print(string.format("P(%d) + P(%d) = %d + %d = %d = P(%d)",a,b,fpent[a],fpent[b],s,rpent[s])) + print(string.format("P(%d) - P(%d) = %d - %d = %d = P(%d)",a,b,fpent[a],fpent[b],d,rpent[d])) + os.exit(0) + end + end + end + a = a + 1 + end +end + +pentpair() |
