All about flooble | fun stuff | Get a free chatterbox | Free JavaScript | Avatars    
perplexus dot info

Home > Numbers
3 Pals make a Pal (Posted on 2022-04-20) Difficulty: 3 of 5
Of the 6-digit palindromes composed of 3 distinct digits which can be formed by adding together three 5-digit palindromes:

a) which is the largest?
b) which is closest to a perfect square?
c) what is the largest palindrome you can form by adding some of these 6-digit palindromes together (using at most one copy of each 6-digit palindrome)?
d) same question as (c) but duplicate addends allowed?

No Solution Yet Submitted by Larry    
Rating: 5.0000 (1 votes)

Comments: ( Back to comment list | You must be logged in to post comments.)
parts a and b | Comment 1 of 2
pals5=[]; ct=0; pSquareDist=999999; largest=0;
for h=100:999
  d1=floor(h/100); d2=mod(floor(h/10),10);
  pal5=100*h+10*d2+d1;
  pals5=[pals5 pal5];
end
for a=1:900
  disp(a)
  for b=a:900
    for c=b:900
      p6=sum(pals5([a b c]));
      if p6>99999
        if ispal(p6)
         p6s=char(string(p6));
         if length(unique(p6s))==3
          if p6>largest
            largest=p6;
            lgabc=[a b c];
          end
          sr=sqrt(p6); srRound=round(sr);
          sq=srRound^2;
          if abs(sq-p6)<pSquareDist
            pSquareDist=abs(sq-p6);
            nearSquare=p6;
            
          end
          ct=ct+1;
         end
        end
      end
    end
  end
end
disp(ct)
disp(largest)
disp([pals5(lgabc)])
disp(nearSquare)


function ip=ispal(x)
  s=char(string(x));
  good=true;
  for i=1:floor(length(s)/2)
    if s(i)~=s(length(s)+1-i)
      good=false;
      break
    end
  end
  if good
    ip=true;
  else
    ip=false;
  end
end

finds

       19743 such six digit palindromes
      243342 the largest , consisting of 44044 +  99299 +  99999
      123321 the nearest to a perfect square (351^2 = 123201)    

  Posted by Charlie on 2022-04-20 12:50:54
Please log in:
Login:
Password:
Remember me:
Sign up! | Forgot password


Search:
Search body:
Forums (0)
Newest Problems
Random Problem
FAQ | About This Site
Site Statistics
New Comments (0)
Unsolved Problems
Top Rated Problems
This month's top
Most Commented On

Chatterbox:
Copyright © 2002 - 2024 by Animus Pactum Consulting. All rights reserved. Privacy Information