/* Euler problem 45 """ Triangle, pentagonal, and hexagonal numbers are generated by the following formulae: Triangle Tn=n(n+1)/2 1, 3, 6, 10, 15, ... Pentagonal Pn=n(3n−1)/2 1, 5, 12, 22, 35, ... Hexagonal Hn=n(2n−1) 1, 6, 15, 28, 45, ... It can be verified that T(285) = P(165) = H(143) = 40755. Find the next triangle number that is also pentagonal and hexagonal. """ This Pop-11 program was created by Hakan Kjellerstrand (hakank@gmail.com). See also my Pop-11 / Poplog page: http://www.hakank.org/poplog/ */ compile('/home/hakank/Poplib/init.p'); define pent(n); n*(3*n-1)/2; enddefine; define tri(n); n*(n+1)/2; enddefine; define hex(n); n*(2*n-1); enddefine; define problem45; lvars t = 285+1; lvars tt = tri(t); lvars p = 165; lvars pp = pent(p); lvars h = 143; lvars hh = hex(h); while true do if tt = pp and pp = hh then quitloop endif; t+1->t; tri(t)->tt; if tt > pp then p+1->p; pent(p)->pp; endif; if pp > hh then h+1->h; hex(h)->hh; endif; if tt > hh then h+1->h; hex(h)->hh; endif; endwhile; ;;; [t ^t tt ^tt p ^p pp ^pp h ^h hh ^hh]=> tt=> enddefine; 'problem45()'=> problem45();