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

Home > Numbers
A few coins (Posted on 2004-11-19) Difficulty: 1 of 5
In Levikland, there are coins worth 1, 2, 5, 10, 20, 50 and 100 perplexii. A has twice as much money as B, who has twice as much as C, who has twice as much as D. How can this be, if everybody has two coins?

See The Solution Submitted by e.g.    
Rating: 2.9231 (13 votes)

Comments: ( Back to comment list | You must be logged in to post comments.)
Solution For A Few Dollars More (Solution) | Comment 6 of 14 |
A has 20 and 100
B has 10 and 50
C has 10 and 20
D has 5 and 10
 
That is the only solution possible.
 
The following VB program found this solution in ZERO elapsed time. (Let's see you beat that, Decrypto)
 
Imports System
Imports System.IO
Imports System.Text
Imports System.Runtime.InteropServices
Imports System.Math
Module Module1
        Sub Main()
        Randomize()
        Dim strstarttime As String
        Dim strendtime As String
        Dim strend As String
        strstarttime = TimeOfDay
        Console.WriteLine("Start of execution: " & strstarttime)
        For indexa1 As Integer = 0 To 6
            For indexa2 As Integer = indexa1 To 6
                subacoins(indexa1, indexa2)
            Next
        Next
        strendtime = TimeOfDay
        Console.WriteLine(" ")
        Console.WriteLine("Start of execution: " & strstarttime)
        strendtime = TimeOfDay
        Console.WriteLine("End of execution: " & strendtime)
        strend = "?"
        Console.WriteLine(" ")
        While strend <> "X"
            Console.WriteLine("Please enter X to exit program...")
            strend = UCase(Console.ReadLine())
        End While
    End Sub

    Sub subacoins(ByRef indexa1, ByRef indexa2)
        Dim intcoin1 As Integer
        Dim intcoin2 As Integer
        Dim intcoin3 As Integer
        Dim intcoin4 As Integer
        coin_exchange(indexa1, intcoin1)
        coin_exchange(indexa2, intcoin2)
        For indexb1 As Integer = 0 To 6
            For indexb2 As Integer = indexb1 To 6
                coin_exchange(indexb1, intcoin3)
                coin_exchange(indexb2, intcoin4)
                If (intcoin1 + intcoin2) = _
                2 * (intcoin3 + intcoin4) Then
                    subbcoins( _
                    indexa1, indexa2, _
                    indexb1, indexb2)
                End If
            Next
        Next
    End Sub

    Sub subbcoins(ByRef indexa1, ByRef indexa2, _
    ByRef indexb1, ByRef indexb2)
        Dim intcoin1 As Integer
        Dim intcoin2 As Integer
        Dim intcoin3 As Integer
        Dim intcoin4 As Integer
        coin_exchange(indexb1, intcoin1)
        coin_exchange(indexb2, intcoin2)
        For indexc1 As Integer = 0 To 6
            For indexc2 As Integer = indexc1 To 6
                coin_exchange(indexc1, intcoin3)
                coin_exchange(indexc2, intcoin4)
                If (intcoin1 + intcoin2) = _
                2 * (intcoin3 + intcoin4) Then
                    subccoins( _
                    indexa1, indexa2, _
                    indexb1, indexb2, _
                    indexc1, indexc2)
                End If
            Next
        Next
    End Sub

    Sub subccoins(ByRef indexa1, ByRef indexa2, _
    ByRef indexb1, ByRef indexb2, _
    ByRef indexc1, ByRef indexc2)
        Dim intcoin1 As Integer
        Dim intcoin2 As Integer
        Dim intcoin3 As Integer
        Dim intcoin4 As Integer
        coin_exchange(indexc1, intcoin1)
        coin_exchange(indexc2, intcoin2)
        For indexd1 As Integer = 0 To 6
            For indexd2 As Integer = indexd1 To 6
                coin_exchange(indexd1, intcoin3)
                coin_exchange(indexd2, intcoin4)
                If (intcoin1 + intcoin2) = _
                2 * (intcoin3 + intcoin4) Then
                    subdcoins( _
                    indexa1, indexa2, _
                    indexb1, indexb2, _
                    indexc1, indexc2, _
                    indexd1, indexd2)
                End If
            Next
        Next
    End Sub

    Sub subdcoins( _
    ByRef indexa1, ByRef indexa2, _
    ByRef indexb1, ByRef indexb2, _
    ByRef indexc1, ByRef indexc2, _
    ByRef indexd1, ByRef indexd2)
        Dim intcoina1 As Integer
        Dim intcoina2 As Integer
        Dim intcoinb1 As Integer
        Dim intcoinb2 As Integer
        Dim intcoinc1 As Integer
        Dim intcoinc2 As Integer
        Dim intcoind1 As Integer
        Dim intcoind2 As Integer
        Console.WriteLine("Eureka !!!!!!!")
        coin_exchange(indexa1, intcoina1)
        coin_exchange(indexa2, intcoina2)
        coin_exchange(indexb1, intcoinb1)
        coin_exchange(indexb2, intcoinb2)
        coin_exchange(indexc1, intcoinc1)
        coin_exchange(indexc2, intcoinc2)
        coin_exchange(indexd1, intcoind1)
        coin_exchange(indexd2, intcoind2)
        Console.WriteLine( _
        "A has " & Str(intcoina1) & " and " & Str(intcoina2))
        Console.WriteLine( _
        "B has " & Str(intcoinb1) & " and " & Str(intcoinb2))
        Console.WriteLine( _
        "C has " & Str(intcoinc1) & " and " & Str(intcoinc2))
        Console.WriteLine( _
        "D has " & Str(intcoind1) & " and " & Str(intcoind2))
    End Sub

    Sub coin_exchange(ByRef indexval, ByRef intcoin)
        Select Case indexval
            Case 0
                intcoin = 1
            Case 1
                intcoin = 2
            Case 2
                intcoin = 5
            Case 3
                intcoin = 10
            Case 4
                intcoin = 20
            Case 5
                intcoin = 50
            Case 6
                intcoin = 100
        End Select
    End Sub
End Module

  Posted by Penny on 2004-11-20 13:40:04
Please log in:
Login:
Password:
Remember me:
Sign up! | Forgot password


Search:
Search body:
Forums (1)
Newest Problems
Random Problem
FAQ | About This Site
Site Statistics
New Comments (6)
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