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

Home > Algorithms
Duodecimal Pandigital Divisibility Device (Posted on 2016-09-13) Difficulty: 3 of 5
N is an 11-digit duodecimal positive integer that uses every digit from 1 to B inclusively exactly once, and:
N is divisible by 7.

Devise an algorithm to generate all possible values of N.

No Solution Yet Submitted by K Sengupta    
No Rating

Comments: ( Back to comment list | You must be logged in to post comments.)
Solution Choice of two algorithms | Comment 1 of 2
The first 11-digit duodecimal positive integer is 10000000000 and the last is bbbbbbbbbbb. The former, in decimal is 12^10, and the latter is 12^13 - 1. Those numbers are  61,917,364,224 and  743,008,370,687 respectively.

The first of these numbers is congruent to 2 mod 7, so we can start testing numbers for duodecimal pandigitality at the duodecimal equivalent of 61,917,364,224 + 5 = 61,917,364,229, and continue incrementing by 7. This involves testing almost 100 billion numbers to see if their duodecimal representation is pandigital and reporting any found, using duodecimal representation.

An alternative is to take the string "123456789ab" and form all  479,001,600 permutations to see which ones are divisible by 7. That's only about 1/200 as many numbers to test.

DefDbl A-Z
Dim crlf$

Private Sub Form_Load()
 Form1.Visible = True
  
 Text1.Text = ""
 crlf = Chr$(13) + Chr$(10)
 
 n$ = "123456789ab": h$ = n
 Do
   v = fromBase(n, 12)
   permute n
   DoEvents
   q = Int(v / 7)
   r = v - 7 * q
   If r = 0 Then
      Text1.Text = Text1.Text & n & "    " & v & "    " & v - prev & crlf
      prev = v
      ct = ct + 1
      If ct > 200 Then Exit Sub
   End If
 Loop Until n = h
  
 Text1.Text = Text1.Text & crlf  & " done"
  
End Sub

Function fromBase(n$, b)
  v = 0
  For i = 1 To Len(n$)
    c$ = LCase$(Mid(n$, i, 1))
    If c$ > " " Then
      v = v * b + InStr("0123456789abcdefghijklmnopqrstuvwxyz", c$) - 1
    End If
  Next
  fromBase = v
End Function

The above implementation cuts off after 201 values are found.  These values are:
                                decimal
duodecimal       decimal     difference from
                equivalent   previous value
                
12345679ba8    73686782554    
1234567a8b9    73686783863    1309
1234567ba98    73686785865    2002
123456879ba    73686799571    13706
12345687b9a    73686799725    154
1234568b97a    73686806193    6468
123456987ab    73686820592    14399
123456987ba    73686821747    1155
12345698ba7    73686822286    539
1234569a87b    73686825212    2926
1234569b78a    73686825751    539
1234569b7a8    73686826906    1155
123456a7b98    73686841305    14399
123456ab897    73686847773    6468
123456b789a    73686847927    154
123456b798a    73686861633    13706
123456b978a    73686863635    2002
123456b987a    73686864944    1309
12345768ba9    73687008934    143990
123457698ba    73687010243    1309
1234576a9b8    73687012091    1848
12345789a6b    73687051438    39347
1234578ab69    73687053594    2156
1234578ab96    73687053825    231
123457968ab    73687055442    1617
12345796ab8    73687067531    12089
1234579a68b    73687071150    3619
1234579b86a    73687075616    4466
123457a698b    73687088013    12397
123457a89b6    73687091555    3542
123457ab698    73687096329    4774
123457b68a9    73687108726    12397
123457b6a89    73687108880    154
123457ba869    73687115348    6468
1234586a7b9    73687260647    145299
1234586ab79    73687260955    308
123458769ab    73687262803    1848
12345876ba9    73687275046    12243
12345879ab6    73687280051    5005
1234587b96a    73687282977    2926
1234587b9a6    73687283362    385
12345896b7a    73687316395    33033
12345897a6b    73687317550    1155
1234589b67a    73687323402    5852
123458a76b9    73687338263    14861
123458a9b67    73687341882    3619
123458b679a    73687345578    3696
123458b6a97    73687357821    12243
123458b7a69    73687359438    1617
123458ba796    73687364289    4851
12345968a7b    73687506046    141757
12345968ab7    73687506431    385
1234596ba78    73687511359    4928
12345976b8a    73687523756    12397
12345978ba6    73687527298    3542
1234597ab68    73687530378    3080
123459876ab    73687544623    14245
12345987ab6    73687546163    1540
1234598a6b7    73687550783    4620
123459ab678    73687589514    38731
123459ab687    73687593980    4466
123459ab867    73687594134    154
123459b786a    73687607840    13706
123459b86a7    73687609534    1694
123459ba768    73687612999    3465
12345a6798b    73687753293    140294
12345a6987b    73687756604    3311
12345a6b789    73687757143    539
12345a6b987    73687760300    3157
12345a76b98    73687772697    12397
12345a7896b    73687775469    2772
12345a7968b    73687776162    693
12345a796b8    73687777163    1001
12345a79b86    73687777856    693
12345a7b869    73687780628    2772
12345a867b9    73687792871    12243
12345a86b79    73687793179    308
12345a8b697    73687801341    8162
12345a9867b    73687815894    14553
12345a986b7    73687816895    1001
12345a9b786    73687822208    5313
12345ab6789    73687822362    154
12345ab8976    73687858783    36421
12345ab9687    73687860092    1309
12345ab9867    73687860246    154
12345b679a8    73688002234    141988
12345b6879a    73688002388    154
12345b6897a    73688003697    1309
12345b78a69    73688024718    21021
12345b798a6    73688026258    1540
12345b7a689    73688026566    308
12345b7a698    73688027721    1155
12345b869a7    73688041966    14245
12345b89a67    73688046894    4928
12345b89a76    73688047279    385
12345b9687a    73688062448    15169
12345b9876a    73688065759    3311
12345b9a678    73688066298    539
12345b9a876    73688069455    3157
12345ba6798    73688083161    13706
12345ba6978    73688083315    154
12345ba7896    73688085009    1694
12345ba8967    73688086626    1617
12345ba9786    73688088320    1694
123465789ab    73688088474    154
12346579b8a    73689519596    1431122
1234657b89a    73689521444    1848
1234657b98a    73689522753    1309
12346587ba9    73689536998    14245
1234658a79b    73689540463    3465
1234658ab97    73689542157    1694
12346597a8b    73689557326    15169
1234659a7b8    73689562331    5005
123465a789b    73689564487    2156
123465a78b9    73689578039    13552
123465a89b7    73689579887    1848
123465a978b    73689580195    308
123465b79a8    73689598906    18711
123465b879a    73689599060    154
123465b897a    73689600369    1309
12346759ba8    73689975898    375529
1234675a8b9    73689977207    1309
1234675ba98    73689979209    2002
123467895ba    73690037267    58058
1234678ab59    73690039577    2310
123467958ab    73690041425    1848
12346795b8a    73690051820    10395
12346798a5b    73690056286    4466
1234679a58b    73690057133    847
1234679b8a5    73690061830    4697
123467a59b8    73690072379    10549
123467a85b9    73690076999    4620
123467a9b85    73690079540    2541
123467b8a95    73690098405    18865
123467ba598    73690101177    2772
123467ba985    73690101716    539
12346857ab9    73690221143    119427
123468597ab    73690221297    154
1234685a97b    73690225917    4620
1234685ba79    73690227919    2002
123468759ba    73690259027    31108
12346875b9a    73690259181    154
1234687b5a9    73690268806    9625
12346895a7b    73690300222    31416
12346895ab7    73690300607    385
123468975ba    73690303379    2772
1234689b57a    73690309385    6006
123468a57b9    73690320935    11550
123468a5b79    73690321243    308
123468a79b5    73690324631    3388
123468a9b57    73690327865    3234
123468ab795    73690331253    3388
123468b579a    73690331561    308
123468b7a59    73690345421    13860
123468b95a7    73690348270    2849
123468b9a75    73690348963    693
123469578ba    73690469699    120736
1234695a78b    73690471855    2156
1234695ba87    73690476860    5005
12346975ba8    73690508122    31262
12346978ab5    73690513127    5005
1234697a5b8    73690515899    2772
1234697ab58    73690516361    462
1234698ab75    73690537459    21098
1234698b75a    73690538383    924
1234698b7a5    73690538614    231
123469a785b    73690572956    34342
123469ab578    73690575497    2541
123469ab857    73690580117    4620
123469b587a    73690590512    10395
123469b78a5    73690594054    3542
123469ba587    73690598828    4774
12346a5879b    73690718948    120120
12346a587b9    73690720103    1155
12346a58b79    73690720411    308
12346a598b7    73690721951    1540
12346a7958b    73690762145    40194
12346a7b598    73690766457    4312
12346a7b985    73690766996    539
12346a859b7    73690777391    10395
12346a8759b    73690777699    308
12346a8795b    73690780317    2618
12346a95b78    73690798027    17710
12346a95b87    73690798412    385
12346a978b5    73690801415    3003
12346a9857b    73690801877    462
12346a98b75    73690803571    1694
12346ab5789    73690808345    4774
12346ab5897    73690839453    31108
12346ab7589    73690839607    154
12346ab8759    73690844227    4620
12346ab9857    73690846229    2002
12346b578a9    73690967350    121121
12346b57a89    73690967504    154
12346b589a7    73690969198    1694
12346b59a78    73690970815    1617
12346b5a897    73690972509    1694
12346b7589a    73690972663    154
12346b78a59    73691010701    38038
12346b7985a    73691011856    1155
12346b7a589    73691012549    693

The differences are irregular, but all positive, as a and b are higher in the collating sequence than normal decimal digits; thus the numbers are found in ascending sequence.



  Posted by Charlie on 2016-09-13 09:51:04
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 (3)
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