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

Home > Numbers
Four Digits (Posted on 2013-11-05) Difficulty: 2 of 5
You have a number where any digit appears at most twice. The sum of all neighboring four digits in this number is a square number.

What is the maximum possible value for this number?

Example: 205290 is such a number because no digit appears more than twice and 2+0+5+2, 0+5+2+9, and 5+2+9+0 are square numbers.

No Solution Yet Submitted by Danish Ahmed Khan    
Rating: 4.0000 (1 votes)

Comments: ( Back to comment list | You must be logged in to post comments.)
Solution computer solution | Comment 2 of 4 |

  5   dim Used(9),Digits(20)
 10   for Strtbase=1 to 9
 20     Nbr=Strtbase
 30     Digits(1)=Nbr
 40     Used(Nbr)=1
 70     Trial4=Nbr
 90     L=1
130     gosub *AddOn
135     Used(Nbr)=0
140   next
150   end
160
170   *AddOn
180   local I,Did1,Sr,Svtrial4
190   Did1=0
200   for I=0 to 9
210      if Used(I)<2 then
220        :inc Used(I)
225        :Svtrial4=Trial4
230        :Trial4=Trial4+I
235        :if L>3 then Trial4=Trial4-Digits(L-3):endif
240        :Sr=int(sqrt(Trial4)+0.5)
250        :if Sr*Sr=Trial4 or L<3 then
260            :Nbr=Nbr*10+I
265            :Digits(L+1)=I
270            :Did1=1
275            :inc L
280            :gosub *AddOn
290            :Nbr=Nbr\10
295            :dec L
300        :endif
310        :dec Used(I)
315        :Trial4=Svtrial4
320   next I
330   if Did1=0 and Nbr>Max then print Nbr:Max=Nbr
340   return

looks for answers in lexicographic order and when it gets a new high number, reports it. The results are:

10031573
10036793679
10126082698
10961026892
11026802689
11026892680
11026892689
12068206199
17531003679
178010358935
1978100367936
3976300187918
5398530108719
63976300187918
81978100367936

so the highest is 81978100367936.

The sample given, 205290, does not appear, as when the numbers starting with 2 were being done, the numbers starting with 1 had already reached 13 digits.


  Posted by Charlie on 2013-11-05 13:17:32
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 - 2017 by Animus Pactum Consulting. All rights reserved. Privacy Information