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

Home > Numbers > Sequences
Some sequences! (Posted on 2015-12-18) Difficulty: 3 of 5
There are two arithmetic increasing sequences of 3 terms each (4-digit prime numbers), such that each of their terms is a permutation of another.

Find both.

See The Solution Submitted by Ady TZIDON    
No Rating

Comments: ( Back to comment list | You must be logged in to post comments.)
Solution computer solution Comment 1 of 1
1487 4817 8147

2969 6299 9629

from

DefDbl A-Z
Dim crlf$

Private Sub Form_Load()
 Text1.Text = ""
 crlf$ = Chr(13) + Chr(10)
 Form1.Visible = True
 
 p1 = 999
 Do
   DoEvents
   p1 = nxtprm(p1)
   If p1 <= 9995 Then
     p2 = p1
     r = 9999 - p1
     Do
       p2 = nxtprm(p2)
       If p2 <= p1 + r / 2 Then
         diff = p2 - p1
         p3 = p2 + diff
         If prmdiv(p3) = p3 And p3 <= 9999 Then
           If isPerm(Str(p1), Str(p2)) And isPerm(Str(p2), Str(p3)) Then
             Text1.Text = Text1.Text & p1 & Str(p2) & Str(p3) & crlf
           End If
         End If
       End If
     Loop Until p2 > 9997
   End If
 Loop Until p1 > 9999
 
   
 End Sub

Function prmdiv(num)
 Dim n, dv, q
 If num = 1 Then prmdiv = 1: Exit Function
 n = Abs(num): If n > 0 Then limit = Sqr(n) Else limit = 0
 If limit <> Int(limit) Then limit = Int(limit + 1)
 dv = 2: GoSub DivideIt
 dv = 3: GoSub DivideIt
 dv = 5: GoSub DivideIt
 dv = 7
 Do Until dv > limit
   GoSub DivideIt: dv = dv + 4 '11
   GoSub DivideIt: dv = dv + 2 '13
   GoSub DivideIt: dv = dv + 4 '17
   GoSub DivideIt: dv = dv + 2 '19
   GoSub DivideIt: dv = dv + 4 '23
   GoSub DivideIt: dv = dv + 6 '29
   GoSub DivideIt: dv = dv + 2 '31
   GoSub DivideIt: dv = dv + 6 '37
 Loop
 If n > 1 Then prmdiv = n
 Exit Function

DivideIt:
 Do
  q = Int(n / dv)
  If q * dv = n And n > 0 Then
    prmdiv = dv: Exit Function
   Else
    Exit Do
  End If
 Loop

 Return
End Function

Function nxtprm(x)
  Dim n
  n = x + 1
  While prmdiv(n) < n
    n = n + 1
  Wend
  nxtprm = n
End Function

Function isPerm(a$, b$)
  x$ = a$
  good = 1
  If Len(a$) <> Len(b$) Then isPerm = 0: Exit Function
  For i = 1 To Len(b$)
    ix = InStr(x, Mid(b, i, 1))
    If ix = 0 Then good = 0: Exit For
    x = Left(x, ix - 1) + Mid(x, ix + 1)
  Next
  isPerm = good
End Function



  Posted by Charlie on 2015-12-18 11:00:18
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 (7)
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