 All about flooble | fun stuff | Get a free chatterbox | Free JavaScript | Avatars  perplexus dot info  Toasting the eternal (Posted on 2017-09-27) " How I need a drink, alcoholic of course, after the heavy lectures involving ..etc etc. is a well-known mnemonics, coding the letters of pi i.e. 3.1415926535..."

Interesting fact is that the alphametic
"HOW+I+NEED+A=DRINK"
has a unique solution, discounting the interchangeability of W and A.

Find this solution.

 No Solution Yet Submitted by Ady TZIDON No Rating Comments: ( Back to comment list | You must be logged in to post comments.) computer solution (spoilers) Comment 1 of 1
DefDbl A-Z
Dim crlf\$

Form1.Visible = True

Text1.Text = ""
crlf = Chr\$(13) + Chr\$(10)

s\$ = "0123456789": h\$ = s
Do
how = Val(Left(s, 3))
If how > 99 Then
i = Val(Mid(s, 4, 1))
need = 100 * Val(Mid(s, 5, 2)) + Val(Mid(s, 6, 2))
a = Val(Mid(s, 9, 1))
drink = Val(Mid(s, 7, 2)) * 1000 + 100 * i + Val(Mid(s, 5, 1)) * 10 + Val(Mid(s, 10, 1))
If how + i + need + a = drink Then
Text1.Text = Text1.Text & how & Str(i) & Str(need) & Str(a) & Str(drink) & crlf
End If
End If
DoEvents
permute s
Loop Until s = h

Text1.Text = Text1.Text & crlf & " done"

End Sub

Sub permute(a\$)

x\$ = ""
For i = Len(a\$) To 1 Step -1
l\$ = x\$
x\$ = Mid\$(a\$, i, 1)
If x\$ < l\$ Then Exit For
Next

If i = 0 Then
For j = 1 To Len(a\$) \ 2
x\$ = Mid\$(a\$, j, 1)
Mid\$(a\$, j, 1) = Mid\$(a\$, Len(a\$) - j + 1, 1)
Mid\$(a\$, Len(a\$) - j + 1, 1) = x\$
Next
Else
For j = Len(a\$) To i + 1 Step -1
If Mid\$(a\$, j, 1) > x\$ Then Exit For
Next
Mid\$(a\$, i, 1) = Mid\$(a\$, j, 1)
Mid\$(a\$, j, 1) = x\$
For j = 1 To (Len(a\$) - i) \ 2
x\$ = Mid\$(a\$, i + j, 1)
Mid\$(a\$, i + j, 1) = Mid\$(a\$, Len(a\$) - j + 1, 1)
Mid\$(a\$, Len(a\$) - j + 1, 1) = x\$
Next
End If
End Sub

did not guard against leading zeros and so found spurious results in which DRINK appears as only a 4-digit number, the D being zero:

632 1 8550 4 9187
634 1 8550 2 9187
635 4 1770 9 2418
639 4 1770 5 2418
714 3 8660 5 9382
715 3 8660 4 9382
735 1 8440 6 9182
736 1 8440 5 9182
751 6 3880 2 4639
752 6 3880 1 4639
812 3 6550 4 7369
814 3 6550 2 7369
823 4 9661 7 10495
827 4 9661 3 10495
843 5 1660 9 2517
847 5 2660 9 3521
849 5 1660 3 2517
849 5 2660 7 3521
865 3 1440 9 2317
869 3 1440 5 2317
935 1 6220 8 7164
938 1 6220 5 7164

only

`823 4 9661 7 10495827 4 9661 3 10495HOW I NEED A DRINK`

 Posted by Charlie on 2017-09-27 11:49:50 Please log in:

 Search: Search body:
Forums (4)