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

Home > Algorithms
Shared by squares (Posted on 2015-02-10) Difficulty: 3 of 5
Devise an efficient method of finding consecutive squares which have the same digits.

Find such pairs up to 1000000.

Feel free to go further.

No Solution Yet Submitted by Jer    
Rating: 4.0000 (1 votes)

Comments: ( Back to comment list | You must be logged in to post comments.)
Some Thoughts re: A start Comment 3 of 3 |
(In reply to A start by Steve Herman)

Indeed Steve's insight on the mod 9 value speeds up the search:


169 196
24649 24964
833569 835396
20367169 20376196
214534609 214563904
368678401 368716804
372142681 372181264
392554969 392594596
407676481 407716864
771617284 771672841
1013021584 1013085241
1212780625 1212850276
1404075841 1404150784
1567051396 1567130569
1623848209 1623928804
2538748996 2538849769
2866103296 2866210369
2898960964 2899068649
3015437569 3015547396
3967236196 3967362169
4098688441 4098816484
4937451289 4937591824
5854239169 5854392196
6121654081 6121810564
6822264409 6822429604
7984494736 7984673449
9672132409 9672329104
0.428999999993017

169 196
24649 24964
833569 835396
20367169 20376196
214534609 214563904
368678401 368716804
372142681 372181264
392554969 392594596
407676481 407716864
771617284 771672841
1013021584 1013085241
1212780625 1212850276
1404075841 1404150784
1567051396 1567130569
1623848209 1623928804
2538748996 2538849769
2866103296 2866210369
2898960964 2899068649
3015437569 3015547396
3967236196 3967362169
4098688441 4098816484
4937451289 4937591824
5854239169 5854392196
6121654081 6121810564
6822264409 6822429604
7984494736 7984673449
9672132409 9672329104
0.475999999999999

169 196
24649 24964
833569 835396
20367169 20376196
214534609 214563904
368678401 368716804
372142681 372181264
392554969 392594596
407676481 407716864
771617284 771672841
1013021584 1013085241
1212780625 1212850276
1404075841 1404150784
1567051396 1567130569
1623848209 1623928804
2538748996 2538849769
2866103296 2866210369
2898960964 2899068649
3015437569 3015547396
3967236196 3967362169
4098688441 4098816484
4937451289 4937591824
5854239169 5854392196
6121654081 6121810564
6822264409 6822429604
7984494736 7984673449
9672132409 9672329104
0.106000000001046

This last uses Steve's idea and it achieves the solution up through 10 billion in .106 seconds, compared to .429 and .476 seconds for my previously given programs in this set of trials

 t = Timer
    For n = 4 To 100000 Step 9
      nxtsq = (n + 1) * (n + 1): nxtsqs$ = LTrim(Str(nxtsq))
      sq = n * n: sqs$ = LTrim(Str(sq))
      If Len(nxtsqs) = Len(sqs) Then good = 1 Else good = 0
      For i = 1 To Len(sqs)
       ix = InStr(nxtsqs$, Mid(sqs, i, 1))
       If ix = 0 Then
        good = 0: Exit For
       Else
        nxtsqs = Left(nxtsqs, ix - 1) + Mid(nxtsqs, ix + 1)
       End If
      Next
      If good = 1 Then Text1.Text = Text1.Text & sqs & " " & nxtsq & crlf: DoEvents
    Next
  Text1.Text = Text1.Text & Timer - t & crlf


  Posted by Charlie on 2015-02-10 19:44:38
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 (2)
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