In Dingistan the coins are of the following denomination:
SILVER:
10, 15, and 20 dingos
COPPER:
1, 2, and 3 dingos.
The ACMs (automatic change machines) accept silver coins and return change as follows:
20d=(15+2+2+1) d
15d=(10+2+2+1) d
10d=(3+3+2+2) d
After Dingus converted into copper the 145d he had in silver coins, his friend W.G.Ringus counted them and successfully reconstructed the original composition of silver coins, previously unknown to him.
It is up to you to find both the input and the output
- if the Wise Guy did it – you can do it, too.
It is D4, if solved analytically.
DefDbl A-Z
Dim crlf$
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
Private Sub Form_Load()
ChDir "C:\Program Files (x86)\DevStudio\VB\projects\flooble"
Text1.Text = ""
crlf$ = Chr(13) + Chr(10)
Form1.Visible = True
DoEvents
totAmt = 145
For n20 = 0 To totAmt / 20
rem1 = totAmt - n20 * 20
For n15 = 0 To rem1 / 15
rem2 = rem1 - n15 * 15
If rem2 Mod 10 = 0 Then
n10 = rem2 / 10
sub20 = n20: sub15 = n15: sub10 = n10
n1 = sub20: n2 = 2 * sub20: n3 = 0
sub15 = sub15 + sub20
n1 = n1 + sub15: n2 = n2 + 2 * sub15
sub10 = sub10 + sub15
n2 = n2 + 2 * sub10: n3 = n3 + 2 * sub10
Text1.Text = Text1.Text & mform(n1, "###0") & mform(n2, "###0") & mform(n3, "###0")
Text1.Text = Text1.Text & " "
Text1.Text = Text1.Text & mform(n20, "###0") & mform(n15, "###0") & mform(n10, "###0")
Text1.Text = Text1.Text & crlf
End If
Next n15
Next n20
Text1.Text = Text1.Text & crlf & "done"
End Sub
produces an output that after sorting and annotating is:
observed original
1d 2d 3d 20d 15d 10d
1 30 28 0 1 13
3 32 26 0 3 10
3 32 26 1 1 11
5 34 24 0 5 7
5 34 24 1 3 8
5 34 24 2 1 9
7 36 22 0 7 4
7 36 22 1 5 5
7 36 22 2 3 6
7 36 22 3 1 7
9 38 20 0 9 1
9 38 20 1 7 2
9 38 20 2 5 3
9 38 20 3 3 4
9 38 20 4 1 5
11 40 18 2 7 0
11 40 18 3 5 1
11 40 18 4 3 2
11 40 18 5 1 3
13 42 16 5 3 0
13 42 16 6 1 1
Only the top row is unique for observed values: Dingus originally had 13 10d pieces and 1 15d piece, which were converted to 28 3d pieces, 30 2d pieces and 1 1d piece.
|
Posted by Charlie
on 2014-10-28 12:22:14 |