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

Home > Numbers
n-Pandigital and k-Divisible (Posted on 2023-10-08) Difficulty: 3 of 5
For n in {1,2,...,9}, find all n-digit positive integers, which are
(1) n-pandigital, i.e. formed from a permutation of the digits 1 to n, with no repeat digits; and
(2) k-divisible, i.e. for all k, k ≤ n, the integer formed from the truncated left most k digits is evenly divisible by k.

And for n=10, also find all 10-digit pandigitals with the same second condition.

Example: 2136547 almost qualifies, but fails for k=2.
2136547 is divisible by 7
213654 is divisible by 6
21365 is divisible by 5
2136 is divisible by 4
213 is divisible by 3
21 is not divisible by 2
2 is divisible by 1

No Solution Yet Submitted by Larry    
No Rating

Comments: ( Back to comment list | You must be logged in to post comments.)
Solution computer solution Comment 1 of 1
clearvars,clc
global sols s 
p=perms('1':'9'); sols=[];
for i=1:length(p)
  s=p(i,:);
  for l=1:9
    check(s(1:l))
  end
end
fprintf('%10d\n',sort(sols));

function check(ns)
global sols s
  tst=sort(ns);
  if str2double(tst(length(ns)))==length(ns)
    good=true;
    for l=1:length(ns)
      if mod(str2double(ns(1:l)),l)~=0
        good=false;
        break
      end
    end
    if good
      if ~ismember(str2double(ns),sols)
        sols(end+1)=str2double(ns);
      end
    end
  end
end

finds

         1
        12
       123
       321
    123654
    321654
  38165472
 381654729

A 10-digit pandigital that's divisible by 10 must end in zero. It must therefore be the 9-digit pandigital with a zero appended: 3816547290.

  Posted by Charlie on 2023-10-08 12:58:55
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 (9)
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