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

Home > Numbers
Big difference (Posted on 2016-02-14) Difficulty: 3 of 5
Using all integers from 1 to 20, assign them into a 5 by 4 grid so that adjacent numbers (horizontally, vertically and diagonally) will differ by at least 4.

No Solution Yet Submitted by Ady TZIDON    
No Rating

Comments: ( Back to comment list | You must be logged in to post comments.)
Solution computer solutions | Comment 1 of 4
The first version of the below program was finding tens of thousands of solutions (minor variations, I guess you'd say) without evan exhausting those with 1 in the upper left corner (reserved for the lowest corner number in the grid, to avoid reflections and rotations).  So the version below limits the number that are found with any given lowest corner.  The highest of the lowest corners was found to be 15, though up to 17 was allowed for in the case of, say, corners being 17, 18, 19 and 20.

DefDbl A-Z
Dim crlf$, grid(6, 5), used(20), solct, innerct

Private Sub Form_Load()
 Form1.Visible = True
 
 Text1.Text = ""
 crlf = Chr$(13) + Chr$(10)
 
 Open "big difference.txt" For Output As #2
 
 For upperleft = 1 To 17
   innerct = 0
   Text1.Text = Text1.Text & upperleft & crlf
   grid(1, 1) = upperleft
   used(upperleft) = 1
   addOn 1, 2
   used(upperleft) = 0
 Next

 Text1.Text = Text1.Text & crlf & solct & " done"
   
  Close 2
End Sub

Sub addOn(row, col)
DoEvents
 If innerct > 20 Then Exit Sub
  For newnum = 1 To 20
    If used(newnum) = 0 Then
      good = 1
      If row = 1 And col = 4 Or row = 5 And col = 4 Then If newnum < grid(1, 1) Then good = 0
      If row = 5 And col = 1 Then If newnum < grid(1, 1) Or newnum < grid(1, 4) Then good = 0
      If good Then
        bad = 0
        For dr = -1 To 1
         For dc = -1 To 1
           If dr <> 0 Or dc <> 0 Then
             If grid(row + dr, col + dc) > 0 Then
               If Abs(newnum - grid(row + dr, col + dc)) < 4 Then bad = 1: Exit For
             End If
           End If
         Next
         If bad Then Exit For
        Next
        If bad = 0 Then
          grid(row, col) = newnum
          used(newnum) = 1
            If row = 5 And col = 4 Then
              For r = 1 To 5
              For c = 1 To 4
                Print #2, mform(grid(r, c), "##0");
              Next
              Print #2,
              Next
              Print #2,
              solct = solct + 1
              innerct = innerct + 1
            Else
              r = row: c = col
              c = c + 1: If c > 4 Then c = 1: r = r + 1
              addOn r, c
            End If
          grid(row, col) = 0
          used(newnum) = 0
          
        End If
      End If
    End If
  Next
End Sub

Function mform$(x, t$)
  a$ = Format$(x, t$)
  If Len(a$) < Len(t$) Then a$ = Space$(Len(t$) - Len(a$)) & a$
  mform$ = a$
End Function

The sampling:

  1  5  9  2
 14 18 13 17
 10  3  8  4
 16 20 15 19
 12  6 11  7

  1  5  9  2
 14 18 13 17
 10  3  8  4
 16 20 15 19
 12  7 11  6

  1  5  9  2
 14 18 13 17
 10  3  8  4
 19 15 20 12
  6 11  7 16


  2  6  1  5
 17 13 19 15
  9  3  7 11
 18 14 20 16
 10  4  8 12

  2  6  1  7
 12 16 11 15
  8 20  3 19
  4 14  9 13
 10 18  5 17

  2  6  1  7
 12 16 11 15
  8 20  4 19
  3 14  9 13
 10 18  5 17

  2  6  1  7
 12 16 11 15
  8 20  5 19
  3 14  9 13
 10 18  4 17

  3  7  1  5
 12 16 11 15
  8 20  6 19
  4 14  2 13
 10 18  9 17

  3  7  1  5
 12 16 11 15
  8 20  6 19
 13  2 14 10
 17  9 18  4

  3  7  1  5
 12 16 11 19
  8 20  6 15
  4 13  2 10
 17  9 18 14

  3  7  1  5
 13 17 11 15
  9  2  6 19
 16 20 14 10
 12  8  4 18

  3  7  1  5
 16 12 17 13
 20  8  2  9
  4 14 19 15
 18 10  6 11
 
 
  4  8  1  5
 13 17 12 16
  9  2  6 20
 14 18 11 15
 10  3  7 19

  4  8  1  5
 13 17 12 16
  9  2  6 20
 15 19 14 10
 11  7  3 18

  4  8  1  5
 13 17 12 16
  9  2  7 20
 15 19 14  3
 11  6 10 18

  4  8  1  5
 13 17 12 16
  9  3  7 20
 14 18 11 15
 10  2  6 19

  4  8  1  5
 13 17 12 16
  9  3  7 20
 14 18 11 15
 10  6  2 19

  4  8  1  5
 13 17 12 16
  9  3  7 20
 15 19 14  2
 11  6 10 18

  4  8  1  5
 14 18 12 16
 10  6  2 20
 15 19 13  9
 11  7  3 17

  4  8  1  5
 14 18 13 17
 10  6  2  9
 19 15 20 16
  7 11  3 12
  
  
  5  1  6 10
 11 15 20 16
 19  2  7 12
  8 13 18  3
 17  4  9 14

  5  1  6 10
 11 15 20 16
 19  2  7 12
  9 13 18  3
 17  4  8 14

  5  1  6 10
 11 15 20 16
 19  2  8 12
  7 13 18  4
 17  3  9 14

  5  1  6 10
 11 15 20 16
 19  3  7 12
  8 13 18  2
 17  4  9 14

  5  1  6 10
 11 15 20 16
 19  3  7 12
  9 13 18  2
 17  4  8 14

  5  1  6 10
 11 15 20 16
 19  3  8 12
  7 13 18  4
 17  2  9 14

  5  1  6 10
 15 11 18 14
 19  7  2  8
  3 13 20 12
 17  9  4 16
 
 
  6  1  5  9
 10 18 13 17
 14  2  7  3
  8 20 11 15
 12 16  4 19

  6  1  5  9
 10 18 13 17
 14  2  7  3
  8 20 11 19
 12 16  4 15

  6  1  5  9
 10 18 13 17
 14  3  7  2
  8 20 11 15
 12 16  4 19

  6  1  5  9
 10 18 13 17
 14  3  7  2
  8 20 11 19
 12 16  4 15

  6  1  5  9
 14 18 13 17
 10  2  7  3
 15 19 12 16
 11  4  8 20

  6  1  5  9
 14 18 13 17
 10  2  8  4
 19 15 20 16
 11  3  7 12


  7  1  5  9
 14 18 13 17
 10  2  8  3
  6 15 20 12
 19 11  4 16

  7  1  5  9
 14 18 13 17
 10  2  8  3
  6 15 20 16
 19 11  4 12

  7  1  5  9
 14 18 13 17
 10  2  8  4
  6 15 20 12
 19 11  3 16

  7  1  5  9
 14 18 13 17
 10  2  8  4
  6 15 20 16
 19 11  3 12

  7  1  5  9
 14 18 13 17
 10  3  8  4
 15 19 12 16
 11  2  6 20

  7  1  5  9
 14 18 13 17
 10  3  8  4
 15 19 12 16
 11  6  2 20

  7  1  5  9
 14 18 13 17
 10  4  8  3
 19 15 20 12
 11  2  6 16
 
 
  8  1  5  9
 14 18 13 17
 10  2  7  3
  6 15 20 12
 19 11  4 16

  8  1  5  9
 14 18 13 17
 10  2  7  3
  6 15 20 16
 19 11  4 12

  8  1  5  9
 14 18 13 17
 10  2  7  3
  6 16 11 15
 12 20  4 19

  8  1  5  9
 14 18 13 17
 10  2  7  3
  6 16 11 19
 12 20  4 15

  8  1  5  9
 14 18 13 17
 10  2  7  3
  6 20 11 15
 12 16  4 19

  8  1  5 10
 17 13 18 14
  4  9  2  6
 16 20 15 19
 12  3  7 11


  9  1  5 10
 15 19 14 18
 11  3  8  4
  7 17 12 16
 13  2  6 20

  9  1  5 10
 15 19 14 18
 11  3  8  4
  7 17 12 20
 13  2  6 16

  9  1  5 10
 15 19 14 18
 11  7  2  6
  3 17 12 16
 13  8  4 20

  9  1  5 10
 15 19 14 18
 11  7  2  6
  3 17 12 20
 13  8  4 16

  9  1  5 10
 17 13 18 14
  3  7  2  6
 11 15 20 12
 19  4  8 16

  9  1  5 10
 17 13 18 14
  3  7  2  6
 11 15 20 16
 19  4  8 12

  9  1  5 10
 17 13 18 14
  4  8  2  6
 12 20 15 11
 16  3  7 19


 10  1  5 11
  6 14 19 15
 18  2  7  3
  9 13 20 12
 17  4  8 16

 10  1  5 11
  6 14 19 15
 18  2  7  3
  9 13 20 16
 17  4  8 12

 10  1  5 11
  6 14 19 15
 18  2  8  4
  9 13 20 12
 17  3  7 16

 10  1  5 11
  6 14 19 15
 18  2  8  4
  9 13 20 16
 17  3  7 12

 10  1  5 11
  6 14 19 15
 18  2  9  4
  7 13 20 16
 17  3  8 12

 10  1  5 11
  6 14 19 15
 18  2  9  4
  8 13 20 16
 17  3  7 12

 10  1  5 11
  6 14 20 16
 18  2  7 12
  8 13 19  3
 17  4  9 15

 10  1  5 13
  6 19  9 18
 15  2 14  4
 11  7 20  8
 17  3 16 12


 11  1  5 17
  7 15  9 13
 19  3 20  4
 14 10 16  8
 18  6  2 12

 11  1  6 15
  7 18 10  2
 12  3 14 19
  8 20  9  5
 16  4 13 17

 11  1  6 15
  7 19 10  2
 12  3 14 18
  8 20  9  5
 16  4 13 17

 11  1  6 16
  5 15 20 10
 19  9  2 14
  4 13 18  7
 17  8  3 12

 11  1  6 16
  5 15 20 10
 19  9  3 14
  4 13 18  7
 17  8  2 12

 11  1  6 16
  5 15 20 10
 19  9  4 14
  2 13 18  8
 17  7  3 12

 11  1  6 16
  5 15 20 10
 19  9  4 14
  3 13 18  8
 17  7  2 12

 11  1  7 12
  5 15 20 16
 19  9  2  6
  3 13 18 10
 17  8  4 14

 11  1  7 12
  5 15 20 16
 19  9  2  6
  4 13 18 10
 17  8  3 14

 11  1  9 15
 20  5 19  4
 16 10 14  8
  6  2 18  3
 17 13  7 12


 12  1  5 13
  8 19  9 18
  3 15  4 14
  7 11 20 10
 17  2  6 16

 12  1  9 13
 16  5 18  4
 20 10 14  8
  6  2 19  3
 17 11  7 15

 12  1  9 13
 18  5 19  4
 14 10 15  8
  6  2 20  3
 17 11  7 16

 12  1  9 13
 19  5 18  4
 15 10 14  8
  6  2 20  3
 17 11  7 16

 12  1  9 13
 20  5 18  4
 16 10 14  8
  6  2 19  3
 17 11  7 15

 12  1  9 15
 16  5 19  4
 20 10 14  8
  6  2 18  3
 17 11  7 13

 12  1  9 15
 20  5 19  4
 16 10 14  8
  6  2 18  3
 17 11  7 13

 12  3  7 15
  8 16 11 19
  4 20  2  6
 13  9 14 10
 17  5  1 18


 13  1 10 14
  5 19  6  2
  9 15 11 17
  4 20  3  7
 16  8 12 18

 13  1 10 14
  5 19  6  2
  9 15 11 18
  4 20  3  7
 16  8 12 17

 13  2  6 15
  9 17 11 19
  5  1  7  3
 10 14 20 12
 18  4  8 16

 13  2  7 17
  9 18 12  3
  5  1  8 16
 11 15 20  4
 19  6 10 14

 13  2  7 18
  9 17 12  3
  5  1  8 16
 11 15 20  4
 19  6 10 14

 13  2  8 16
  6 17 12 20
 10  1  7  3
  5 14 19 11
 18  9  4 15

 13  2  8 17
  6 18 12  3
 10  1  7 16
  5 14 20 11
 19  9  4 15

 13  3  7 18
  9 17 11  2
  5  1  6 15
 16 12 19 10
 20  8  4 14
 
 
 14  2  6 15
 10 18 11 19
  5  1  7  3
  9 13 20 12
 17  4  8 16

 14  3  7 15
 10 18 11 19
  2  6  1  5
 12 20 13  9
 16  8  4 17

 14  3  7 15
 10 18 11 19
  5  1  6  2
  9 13 20 12
 17  4  8 16

 14  4  8 16
 10 18 12 20
  5  1  6  2
  9 13 19 11
 17  3  7 15

 14  4  8 16
 10 18 12 20
  5  1  7  3
  9 13 19 11
 17  2  6 15

 14  4  8 17
 10 18 12  2
  5  1  6 16
  9 13 20 11
 19  3  7 15

 14  4  8 17
 10 18 12  3
  5  1  7 16
  9 13 20 11
 19  2  6 15

 14  5  9 15
 10  1 19  4
 17  6 13  8
 12  2 20  3
 18  7 11 16


 15  5  9 17
 11  1 13  3
 16  7 18  8
 12  2 14  4
 19  6 10 20

 15  5  9 17
 11  1 13  3
 16  7 18  8
 12  2 14  4
 20  6 10 19

 15  5  9 17
 11  1 13  3
 16  7 19  8
 12  2 14  4
 18  6 10 20

 15  5  9 17
 11  1 13  3
 16  7 19  8
 12  2 14  4
 20  6 10 18

 15  5  9 17
 11  1 13  3
 16  7 20  8
 12  2 14  4
 18  6 10 19

 15  5  9 17
 11  1 13  3
 16  7 20  8
 12  2 14  4
 19  6 10 18

 15  5  9 17
 11  1 13  4
  7 18  8 19
  3 14  2 12
 20 10  6 16

 15  5  9 17
 11  1 13  4
  7 18  8 20
  3 14  2 12
 19 10  6 16

 15  5  9 17
 11  1 13  4
 19  7 18  8
  3 14  2 12
 20 10  6 16


  Posted by Charlie on 2016-02-14 15:03:30
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 (10)
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