Subscribe via feed.

Trick + Of – Mind = TONIC

Posted by ragknot on July 10, 2013 – 9:07 pm

I don’t remember this, but I saw the text dated 2010. But I just computed and found 80 answers.  Here the text I found.
==================================

This will be interesting. If you have found these difficult, this may make it easier to find a solution.

Trick + Of – Mind = TONIC

Each letter in the equation above represents a different digit. (Ignore upper / lower case)

Hint: There are 484 different solutions!  Also the first code of any “word” will not be zero. Can you crack the code?
Please give the solution(s) using a string of digits that correspond to the key.

TRICKOFMND <– ten letters I call the KEY
xxxxxxxxxx <– ten digits, called “My String”

that correspond to your solution to the key.  Example > “7234561890″ .   (BTW that’s not one of the answers.) In this case you be setting T=7, R=2, etc.


This post is under “Tom” and has 28 respond so far.
If you enjoy this article, make sure you subscribe to my RSS Feed.

28 Responds so far- Add one»

  1. 1. ragknot Said:

    This morning, I re-checked my computations found for 484 is right.

  2. 2. JohnP24 Said:

    TRICKOFMND = 8796235401 is one solution.

    I do have some observations about how to solve this but have not found a way to produce all 484 solutions.

  3. 3. JohnP24 Said:

    6 solutions

    97851364802
    97856314802
    87962354901
    87965324901
    48961375902
    48967315902

    97851 + 36 – 4802 = 93085
    97856 + 31 – 4802 = 93085

    87962 + 35 – 4901 = 83096
    87965 + 32 – 4901 = 83096

    48961 + 37 – 5902 = 43096
    48967 + 31 – 5902 = 43096

    LOGIC
    N must be 0 since I – I = N
    CK + OF must be greater than ND or else it would result in borrowing a 1 from the I in trick during subtraction of MIND.

    K + F – D = C
    K + F – D cannot be greater than 9 since C is a single digit

    C + O – N = I
    C + O – N cannot be greater than 9 since I is a single digit

    TR – M = TO
    M cannot be greater than or equal to R or else equation fails

    ICK + OF – IND = NIC
    Again N must be equal to 0 since I – I. CK + OF – D = IC which means C + 0 must equal I and K + F – D = C as shown above.

    Also the first code of any “word” will not be zero was provided in the puzzle so T, O, & M cannot be 0

    I cannot put this into an equation at this point. Will try later.

  4. 4. JohnP24 Said:

    All of the previous logic simply limits your grunt work if using brute force. With over 3 million unique 10 digit numbers with no duplicates and 1, 6, and 8th digits not being a 0 brute force seemed impractical.

    I wrote a program to produce 10 digit numbers with no duplicate values and no 0 in the 1st, 6th and 8th digit. Then checked each value to see if it met the formula criteria. TRICK + OF – MIND = TONIC

    It looks like every result has a twin with only the 5th and 7th digit reversed. Which makes some sense since these represent K and F which are simply added to each other but never used in the result.

    Found 484 results
    15864293807
    15869243807
    16407283495
    16408273495
    17605482693
    17608452693
    17628394605
    17629384605
    17630284695
    17638204695
    17638295604
    17639285604
    17643295608
    17649235608
    17852394806
    17859324806
    18406275493
    18407265493
    18603542697
    18604532697
    18605473692
    18607453692
    18620374695
    18627304695
    18627395604
    18629375604
    18630275694
    18637205694
    19623475608
    19627435608
    19824653807
    19825643807
    19832574806
    19837524806
    19852376804
    19857326804
    19864257803
    19865247803
    24765193708
    24769153708
    24965381907
    24968351907
    24986173905
    24987163905
    25746183790
    25748163790
    25760143798
    25764103798
    26307184395
    26308174395
    26750184793
    26758104793
    26943581907
    26948531907
    26984175903
    26987145903
    27085394016
    27089354016
    27306185394
    27308165394
    27518394506
    27519384506
    27538196504
    27539186504
    27543196508
    27549136508
    28064593017
    28069543017
    28501463597
    28506413597
    28510374596
    28517304596
    28530176594
    28537106594
    28715463790
    28716453790
    28716593704
    28719563704
    28741395706
    28749315706
    29054683017
    29058643017
    29085376014
    29087356014
    29517386504
    29518376504
    29543178506
    29547138506
    29714653708
    29715643708
    29716584703
    29718564703
    29731485706
    29738415706
    29741386705
    29748316705
    29764158703
    29765148703
    36825471890
    36827451890
    36827591804
    36829571804
    36857294801
    36859274801
    36870124895
    36871254809
    36872104895
    36872195804
    36875214809
    36879125804
    37418295406
    37419285406
    37420185496
    37428105496
    37428196405
    37429186405
    37820561894
    37826501894
    37850264891
    37856204891
    37860214895
    37861204895
    37861295804
    37862145890
    37864125890
    37869215804
    38410275496
    38417205496
    38417296405
    38419276405
    38420176495
    38427106495
    38640215697
    38641205697
    39612574608
    39617524608
    39621485607
    39628415607
    39641287605
    39648217605
    39652178604
    39657128604
    39826574801
    39827564801
    43756281709
    43758261709
    43765192708
    43769152708
    43975281906
    43978251906
    43986172905
    43987162905
    45086392017
    45089362017
    45097283016
    45098273016
    46510382597
    46518302597
    46723581709
    46728531709
    46937581902
    46938571902
    46983175902
    46987135902
    47936582901
    47938562901
    47981235906
    47983215906
    48053692017
    48059632017
    48095276013
    48097256013
    48290563217
    48296503217
    48301265397
    48305176392
    48306215397
    48307156392
    48325167309
    48326157309
    48531296507
    48536197502
    48539167502
    48539216507
    48702631795
    48703621795
    48752136790
    48753126790
    48923751906
    48925731906
    48931672905
    48937612905
    48961375902
    48967315902
    48971325906
    48972315906
    48973256901
    48975236901
    49280653217
    49285603217
    49521386507
    49528316507
    49531287506
    49538217506
    49751326708
    49752316708
    49763158702
    49765138702
    53864291807
    53869241807
    53874192806
    53879142806
    54860231897
    54863201897
    54870132896
    54873102896
    56401372498
    56407312498
    56410283497
    56418203497
    57432196408
    57439126408
    57603482691
    57608432691
    57621493608
    57629413608
    58203146297
    58204136297
    58426197403
    58429167403
    59380742316
    59384702316
    59412376408
    59416287403
    59417326408
    59418267403
    59432178406
    59437128406
    59813742806
    59814732806
    59863247801
    59864237801
    63754291708
    63759241708
    63974281905
    63978241905
    63985172904
    63987152904
    64307182395
    64308172395
    64735281790
    64738251790
    64750182793
    64750231798
    64753201798
    64758102793
    64758193702
    64759183702
    65724381790
    65728341790
    65732491708
    65739421708
    65740321798
    65742301798
    65971342908
    65974312908
    65981243907
    65983174902
    65984213907
    65987134902
    67082453019
    67085423019
    67092354018
    67094285013
    67095324018
    67098245013
    67304185392
    67308145392
    67512483509
    67513284590
    67518234590
    67518423509
    67521394508
    67529314508
    67530214598
    67531204598
    68072543019
    68074523019
    68092345017
    68094325017
    68710542793
    68714502793
    68714593702
    68719543702
    68741235790
    68743215790
    68923741905
    68924731905
    69072485013
    69072534018
    69073524018
    69078425013
    69082435017
    69083425017
    69314257308
    69315247308
    69324158307
    69325148307
    69483752410
    69485732410
    73645281609
    73648251609
    73654192608
    73659142608
    74628391605
    74629381605
    74630281695
    74635182690
    74638152690
    74638201695
    74650132698
    74653102698
    74852391806
    74859321806
    75402361498
    75406321498
    75418293406
    75419283406
    75420183496
    75428103496
    75623481609
    75628431609
    75836491802
    75839461802
    75840361892
    75846301892
    75846392801
    75849362801
    75861293804
    75861342809
    75862143890
    75864123890
    75864312809
    75869213804
    76203154298
    76205134298
    76432195408
    76439125408
    76830451892
    76835401892
    76835492801
    76839452801
    76840352891
    76845302891
    76851243890
    76851432809
    76853412809
    76854213890
    78390642315
    78394602315
    78415296403
    78419256403
    78420156493
    78425106493
    78601532694
    78603512694
    78624395601
    78629345601
    78630245691
    78634205691
    78641325609
    78642315609
    79432168405
    79436128405
    79653148602
    79654138602
    79821653804
    79825613804
    79852346801
    79854326801
    83546172509
    83547162509
    83975261904
    83976251904
    84762193705
    84769123705
    85096273014
    85097263014
    85726491703
    85729461703
    85741392706
    85746293701
    85749263701
    85749312706
    85761243709
    85764213709
    86073492015
    86079432015
    86095274013
    86097254013
    86305174392
    86307154392
    86324175309
    86327145309
    86504372591
    86507342591
    86513472509
    86514273590
    86517243590
    86517432509
    86531294507
    86539214507
    86720451793
    86725401793
    86740253791
    86745203791
    86752134790
    86753124790
    86951472903
    86957412903
    86973254901
    86975234901
    87301254396
    87305214396
    87314265309
    87316245309
    87932651904
    87935621904
    87941562903
    87946512903
    87951463902
    87956413902
    87962354901
    87965324901
    89043762015
    89046732015
    89052673014
    89057623014
    89062574013
    89067524013
    89073465012
    89076435012
    89531267504
    89536217504
    89712643705
    89714623705
    89741356702
    89745316702
    93645271608
    93647251608
    93654182607
    93658142607
    93864271805
    93867241805
    93875162804
    93876152804
    95623471608
    95627431608
    95873164802
    95876134802
    96427185403
    96428175403
    96432185407
    96438125407
    97416285403
    97418265403
    97615483602
    97618453602
    97625384601
    97628354601
    97823641805
    97824631805
    97831562804
    97836512804
    97851364802
    97856314802
    97863245801
    97864235801
    98412365407
    98416325407
    98432167405
    98436127405
    98653147602
    98654137602

  5. 5. ragknot Said:

    JohnP24…
    Well you are almost right, but you made one thing that said it failed. Then I saw that you had 11 digits. Then I saw the 3rd digit is included again at the 9th place.
    Hold on a minute and let me see it I remove the duplicate number and re-check it.

  6. 6. ragknot Said:

    I checked John’s data, but something else is wrong.
    The first 38 (in whole number order), where T=1 is this.

    TRICKOFMND is ……Trick + of – mind = Tonic
    =====================================
    1586429307 is … 15864 + 29 – 3807 = 12086
    1586924307 is … 15869 + 24 – 3807 = 12086
    1640728395 is … 16407 + 28 – 3495 = 12940
    1640827395 is … 16408 + 27 – 3495 = 12940
    1760548293 is … 17605 + 48 – 2693 = 14960
    1760845293 is … 17608 + 45 – 2693 = 14960
    1762839405 is … 17628 + 39 – 4605 = 13062
    1762938405 is … 17629 + 38 – 4605 = 13062
    1763028495 is … 17630 + 28 – 4695 = 12963
    1763820495 is … 17638 + 20 – 4695 = 12963
    1763829504 is … 17638 + 29 – 5604 = 12063
    1763928504 is … 17639 + 28 – 5604 = 12063
    1764329508 is … 17643 + 29 – 5608 = 12064
    1764923508 is … 17649 + 23 – 5608 = 12064
    1785239406 is … 17852 + 39 – 4806 = 13085
    1785932406 is … 17859 + 32 – 4806 = 13085
    1840627593 is … 18406 + 27 – 5493 = 12940
    1840726593 is … 18407 + 26 – 5493 = 12940
    1860354297 is … 18603 + 54 – 2697 = 15960
    1860453297 is … 18604 + 53 – 2697 = 15960
    1860547392 is … 18605 + 47 – 3692 = 14960
    1860745392 is … 18607 + 45 – 3692 = 14960
    1862037495 is … 18620 + 37 – 4695 = 13962
    1862730495 is … 18627 + 30 – 4695 = 13962
    1862739504 is … 18627 + 39 – 5604 = 13062
    1862937504 is … 18629 + 37 – 5604 = 13062
    1863027594 is … 18630 + 27 – 5694 = 12963
    1863720594 is … 18637 + 20 – 5694 = 12963
    1962347508 is … 19623 + 47 – 5608 = 14062
    1962743508 is … 19627 + 43 – 5608 = 14062
    1982465307 is … 19824 + 65 – 3807 = 16082
    1982564307 is … 19825 + 64 – 3807 = 16082
    1983257406 is … 19832 + 57 – 4806 = 15083
    1983752406 is … 19837 + 52 – 4806 = 15083
    1985237604 is … 19852 + 37 – 6804 = 13085
    1985732604 is … 19857 + 32 – 6804 = 13085
    1986425703 is … 19864 + 25 – 7803 = 12086
    1986524703 is … 19865 + 24 – 7803 = 12086

  7. 7. ragknot Said:

    One thing to know is about N. N can be either 0, 1 or 9.

    When N=1 then I must be either 0,2, 3 for 4.

    Remark #3, the first digits listed says “97851364802″.
    Well it has 11 digits, something must be wrong. 8 is repeated.

    If “Trick” is 97851 then the true 10 digits must 9785136402
    to make the full equation be this…

    97851 + 36 – 4802 = 93085

  8. 8. ragknot Said:

    Also I suspect that Chris did this back before Jan 2010.
    I had the ToM copied, but I did not have any solutions copied.

    (ToM) means Trick of Mind)

    It was not to hard in Excel visual basic.

    There are 2,540,160 solutions where the letters are 0 to 9, but T, o, and M must be only 1 to 9, not 0 to 9.

    But only 484 “solutions” can give a correct equation.

  9. 9. ragknot Said:

    Section of my solution…

    For t = 1 To 9
    For r = 0 To 9
    If r = t Then GoTo nextr
    For i = 0 To 9
    If i = t Or i = r Then GoTo nexti
    For c = 0 To 9
    If c = t Or c = r Or c = i Then GoTo nextc
    For k = 0 To 9
    If k = t Or k = r Or k = i Or k = c Then GoTo nextk

    …. another section

    text1 = t & r & i & c & k
    num1 = Val(text1)
    text2 = o & f
    num2 = Val(text2)
    text3 = m & i & n & d
    num3 = Val(text3)
    text4 = t & o & n & i & c
    num4 = Val(text4)
    ans = num1 + num2 – num3
    If num4 = ans Then

  10. 10. Chris Said:

    Me too, 484 possible keys. I had a go as it gave me an excuse to tweak my permutator function. JohnP24 hasn’t made a mistake as such. He’s simply made the key be TRICKOFMIND rather than TRICKOFMND

    Now follows about the ugliest code I’ve written in many years. NB although the right hand side is chopped off, if you select all the lines and copy/paste them, it’ll be fine.

    Option Explicit
    'To load this into Excel: open Excel, click on a cell, press ALT+F11.
    'The VBA window should open. On the menu click "Insert", then "Module".
    'Paste this code into the "Module1" code window. Add the Debug tool bar.
    
    'If you get subscript out of range errors, you probably didn't start in "Main"
    
    'Solve TRICK + Of - MIND = TONIC, where each letter corresponds to a single digit
    'and neither T, O or M are allowed to have the value 0.
    'use the "key" TRICKOFMND to represent the solution
    
    Public Declare Function GetTickCount Lib "kernel32" () As Long
    
    Sub Main()
    'NB I'm using Long rather than Integer as they access faster
      Const cT As Long = 1, cR As Long = 2, cI As Long = 3, cC As Long = 4
      Const cK As Long = 5, cO As Long = 6, cF As Long = 7, cM As Long = 8
      Const cN As Long = 9, cD As Long = 10
      Dim i As Long, j As Long, t As Long
      Dim nTestedPerms As Long, nGoodPerms As Long
      Dim nTrick As Long, nOf As Long, nMind As Long, nTonic As Long
      Dim TOM(1 To 10) As Long 'the current trial key for TRICKOFMND
      Dim sTom As String, nTabs As Long
      Dim st1 As Long
    
      st1 = GetTickCount
    
      'TOM(cT), TOM(cO) and TOM(cM) are not allowed to be 0
      'this proggy will test 7*9! = 2,540,160 potential keys
    
      'initialise TOM(). Because TOM(cT) cannot = 0, start with 1023456789
      'this saves a little time and avoids the need to test that TOM(pT) <> 0
      TOM(cT) = 1: TOM(cR) = 0
      For i = cI To cD: TOM(i) = i - 1: Next i
    
      Do
        If TOM(cO) = 0 Then
          'not allowed. so short-circuit the permutor
          'by reversing the tail-end of TOM()
          i = cO + 1: j = cD
          Do While i < j
            t = TOM(i): TOM(i) = TOM(j): TOM(j) = t
            i = i + 1: j = j - 1
          Loop
        ElseIf TOM(cM) = 0 Then
          'not allowed. so short-circuit the permutor
          'by reversing the tail-end of TOM()
          'makes little difference to run time, but it's aesthetically pleasing
          i = cM + 1: j = cD
          Do While i < j
            t = TOM(i): TOM(i) = TOM(j): TOM(j) = t
            i = i + 1: j = j - 1
          Loop
        Else 'check if TRICK + OF - MIND = TONIC
          nTestedPerms = nTestedPerms + 1
          nTrick = 10000 * TOM(cT) + 1000 * TOM(cR) + 100 * TOM(cI) + 10 * TOM(cC) + TOM(cK)
          nOf = TOM(cO) * 10 + TOM(cF)
          nMind = 1000 * TOM(cM) + 100 * TOM(cI) + 10 * TOM(cN) + TOM(cD)
          nTonic = 10000 * TOM(cT) + 1000 * TOM(cO) + 100 * TOM(cN) + 10 * TOM(cI) + TOM(cC)
          If nTrick + nOf - nMind = nTonic Then
            nGoodPerms = nGoodPerms + 1
            sTom = ""
            For i = 1 To 10: sTom = sTom & Chr(Asc("0") + TOM(i)): Next i
            Debug.Print sTom; " ";
            nTabs = nTabs + 1
            If (nTabs Mod 7) = 0 Then Debug.Print
          End If
        End If
      Loop Until NextPermLng(TOM) = False
    
      Debug.Print vbCrLf; vbCrLf; "#Tested Perms ="; nTestedPerms
      Debug.Print "#Good perms ="; nGoodPerms
      Debug.Print "Time taken (seconds) ="; (GetTickCount - st1) / 1000
      Debug.Print vbCrLf
    
    End Sub
    
    Function NextPermLng(ByRef p() As Long) As Boolean
    'returns false if no more perms, and true if a new perm was found

    'see http://en.wikipedia.org/wiki/Permutation#Generation_in_lexicographic_order

    'p() must have at least 2 elements - this code doesn't test for compliance
      Dim i As Long, j As Long, t As Long
    
      i = UBound(p) - 1
      Do Until p(i) < p(i + 1)
        If i = LBound(p) Then
          NextPermLng = False
          Exit Function 'no more perms
        End If
        i = i - 1
      Loop
    
      j = UBound(p)
      Do Until p(i) < p(j)
        j = j - 1
      Loop
      t = p(i): p(i) = p(j): p(j) = t 'swap
    
      i = i + 1
      j = UBound(p)
      Do While i < j 'reverse the tail end
        t = p(i): p(i) = p(j): p(j) = t 'swap
        i = i + 1: j = j - 1
      Loop
    
      NextPermLng = True
    End Function
  11. 11. ragknot Said:

    The steps could be more specific, but I thought this would be easy to understand.

  12. 12. ragknot Said:

    I wrote this to put the answers on my open worksheet.
    All the values do not have DIM
    The ScreenUpdate = false makes it pretty quick.
    This should be easy to understand.

    Sub test()
      'Trick + Of - Mind = TONIC
      'TRICKOFMND < -- ten letters I call the KEY
    Dim text1 As String
    Dim text2 As String
    Dim text3 As String
    Dim text4 As String
    Dim num1 As Long
    Dim num2 As Long
    Dim num3 As Long
    Dim num4 As Long
    
    Application.ScreenUpdating = False
    Row = 20
    
    'trick
    For t = 1 To 9
    For r = 0 To 9
        If r = t Then GoTo nextr
    For i = 0 To 9
        If i = t Or i = r Then GoTo nexti
    For c = 0 To 9
        If c = t Or c = r Or c = i Then GoTo nextc
    For k = 0 To 9
        If k = t Or k = r Or k = i Or k = c Then GoTo nextk
    'of
    For o = 1 To 9
        If o = t Or o = r Or o = i Or o = c Or o = k Then GoTo nexto
    For f = 0 To 9
        If f = t Or f = r Or f = i Or f = c Or f = k Or f = o Then GoTo nextf
    'mind
    For m = 1 To 9
        If m = t Or m = r Or m = i Or m = c Or m = k Or m = o Or m = f Then GoTo nextm
    For n = 0 To 9
        If n = t Or n = r Or n = i Or n = c Or n = k Or n = o Or n = f Or n = m Then GoTo nextn
    For d = 0 To 9
            If d = t Or d = r Or d = i Or d = c Or d = k Or d = o Or d = f Or d = m Or d = n Then GoTo nextd
    
    text1 = t & r & i & c & k:              num1 = Val(text1)
    text2 = o & f:                               num2 = Val(text2)
    text3 = m & i & n & d:                  num3 = Val(text3)
    text4 = t & o & n & i & c:              num4 = Val(text4)
    ans = num1 + num2 - num3
       If num4 = ans Then
        Row = Row + 1
        Cells(Row, 1) = text1
        Cells(Row, 2) = text2
        Cells(Row, 3) = text3
        Cells(Row, 4) = text4
        Cells(Row, 6) = text1 & " + " & text2 & " - " & text3 & " = " & text4
        tot = tot + 1: Cells(Row, 7) = tot
        If ans = num4 Then Cells(Row, 8) = "true"
        Cells(Row, 9) = t & r & i & c & k & o & f & m & n & d
        Cells(Row, 10) = t
        Cells(Row, 11) = r
        Cells(Row, 12) = i
        Cells(Row, 13) = c
        Cells(Row, 14) = k
        Cells(Row, 15) = o
        Cells(Row, 16) = f
        Cells(Row, 17) = m
        Cells(Row, 18) = n
        Cells(Row, 19) = d
        End If
    
    nextd:    Next d       '10
    nextn:    Next n         '9
    nextm:   Next m        '8
    nextf:     Next f         '7
    nexto:    Next o        '6
    nextk:    Next k        '5
    nextc:    Next c         '4
    nexti:     Next i         '3
    nextr:     Next r        '2
    Next t                      '1
    
    End Sub
    
  13. 13. Chris Said:

    Hi ragknot. I’m curious about the running time of the code. On my PC, my proggy takes less than 5 seconds to run. How long does your one take on your PC? If you try mine, how long does it take?

    I probably could have made it a bit cleaner if I wrote a NextPerm function for a character string.

  14. 14. Chris Said:

    Oops, posts crossed. I’ll try your code out for speed.

  15. 15. Chris Said:

    Hi ragknot. I’ve added the <pre> and </pre> tags to your last post. It’s now possible to copy/paste it.

    For your info, your code took about 36 seconds to run on my PC.

  16. 16. ragknot Said:

    I thought of something, but I didn’t try it.

    For the 10th digit, I thought about subtracting the total from 45 to get the last digit. Like if the total of the nine was 39, then the single missing number would be 45-39=6, that would have saved many steps.

    I will change the 10 “for” to the equation for d.
    Now it took 25 seconds

  17. 17. Chris Said:

    Hi ragknot. I put some timing code in. My code actually takes 2.9 (was 3.5) seconds.

    To my surprise, I don’t seem to gain anything by making the TOM array be global.

    With my code, there is no way to take advantage of the sum of the digits being 45. That’s because the permutations generator has inherently obviated that trick. In fact, trying to use it would be counter-productive.

  18. 18. ragknot Said:

    Who did this ToM over 3 years ago?
    I thought may it was Chris.

  19. 19. Chris Said:

    I don’t remember this one being posted before. I do remember
    WOW/DVD = .FILMFILMFILM… and the sequel that you posted.

    Your sequel question boiled down to: if WDOVFILM represent different digits and neither W or D are allowed to be 0, then how many combinations are possible?

  20. 20. Chris Said:

    I’ve updated my code (post 10). On my PC now takes 3.1 seconds.

    For WDOVFILM there are 9*8*8!/2! = 1451520 combinations.

    FWIW, .FILMFILMFILM… = FILM/9999

  21. 21. ragknot Said:

    Cool Chris, I would like to see the code that does it in about 3 seconds.

    Who made the “Trick Of Mnd” back in 2010?

  22. 22. Chris Said:

    Hi ragknot. I just updated it again (now getting 2.9 seconds). It’s the code in post 10.

    I removed the DoEvents, an unnecessary loop counter and changed all Integer types to Long. I guess that Integers should only be used when memory or disc storage space is important.

    I can’t find the original post on this or the old site.

  23. 23. Chris Said:

    I just tried TRICK + OF + MIND = TONIC, then there’s only 186 solutions, and the run-time is 2.6 seconds.

  24. 24. Chris Said:

    Hi ragknot. I just rewrote everything to work with strings. i.e. the TOM key and the NextPerm etc. That code takes 19 seconds to run. I hadn’t expected such a dramatic performance loss. That might explain your code being so slow. I’ll investigate this further. I now have permutors for String, Integer, Long and Double. I now am going to think about how to do one for Variant – that’ll be interesting as it’ll need to define a compare function that’s called from NextPermVar().

    Moral, even if the natural data is of type String, it may well be best to convert it into an array of Long and do the processing on that.

  25. 25. Chris Said:

    Antother tidbit. I just rewrote the code to use Double instead of Long. It only increases the running time from 2.9 to 3.1 seconds.

    An advantage of Double is that it can exactly store integers to about 15.9 digits, whereas Long only does about 9.3 digits.

  26. 26. ragknot Said:

    Well, great, but I don’t understand exactly. I would have to study it more to learn. I will try to review it’s work.

  27. 27. Chris Said:

    Hi ragknot. I assume that you’re stuck on the NextPerm function. I got it from the link (in post 8, in the NextPerm comments). It’s a beautiful permutor. It seems to be quite efficient. It’s main characteristic is that if you give it an array, it’ll make a new permutation from it, and that permutation is the next in lexicographic order. Another very nice feature is that if the array contains duplicate elements, it handles them perfectly i.e. it always produces a unique permutation.

    It isn’t necessary to understand how it works, only what it actually does. This is much the same as using e.g. the Log function, you don’t need to understand how it actually determines the Log.

  28. 28. Chris Said:

    More info. Assume we have an integer array ia() and that
    ia(1) = 2, ia(2) = 5, ia(3) = 9 – I’ll write that as 259 for brevity, then starting with that 259, calling NextPerm will give 295, then 529, then 592, then 925, then 952, then no more.

    If had (again in brief form) 255, then the sequence would be 255 -> 525 -> 552 and that’s it.

    You know when there are no more perms when NextPerm returns False.

    To do the bypassing of some permutations, you simply reverse the order of the right hand end of the array. It is crucial that the right hand end is in ascending order though (before the reversal). If it isn’t, you’ll find that you get into an infinite loop. So far, the few times I’ve done it, that condition has been met inherently. If it hadn’t been met, I would have had to sort the right hand end first, then reverse it.

    I have now written NextPerm functions for Integer, Long, Double, Chr (a single string, permuted character wise), String (an array of strings). I haven’t bothered with an array of char or an array of byte. I’m postponing doing one for Variant or more general types until I have a definite need for such (and because I’m lazy).

    I’ll email my collection to you.

Post a reply




PHP Warning: PHP Startup: Unable to load dynamic library 'C:\Program Files (x86)\Parallels\Plesk\Additional\PleskPHP5\ext\php_mssql.dll' - The specified module could not be found. in Unknown on line 0 PHP Warning: PHP Startup: Unable to load dynamic library 'C:\Program Files (x86)\Parallels\Plesk\Additional\PleskPHP5\ext\php_pdo_mssql.dll' - The specified module could not be found. in Unknown on line 0