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

Home > Logic
How old did you say they were? (Posted on 2005-03-03) Difficulty: 3 of 5

The hostess, at her 20th wedding anniversary party, tells you that her youngest child likes her to pose this problem to guests, and she proceeds to explain: "I normally ask guests to determine the ages of my three children, given the sum and products of their ages. Since Smith gave an incorrect answer to the problem tonight and Jones gave an incorrect answer at the party two years ago, I'll let you off the hook."

Your response is "No need to tell me more, their ages are..."

See The Solution Submitted by Erik O.    
Rating: 3.2000 (10 votes)

Comments: ( Back to comment list | You must be logged in to post comments.)
re(5): Solution (??) | Comment 9 of 31 |
(In reply to re(4): Solution (??) by Charlie)

I get the same answer, {6,12,16}, with my program adjusted for Charlie's sensible assumptions. (Having 1-year-old infants asking brainteasers at wedding anniversaries, my original assumption, was almost as silly as that "time-reversed gestation period" that somehow preserved the bride's reputation, in my second post).

Imports System
Imports System.IO
Imports System.Text
Imports System.Runtime.InteropServices
Imports System.Math
Module Module1
    Sub Main()
        Randomize()
        Dim intsize As Integer = 16 * 16 * 16
        Dim intloop As Integer = intsize - 1
        Dim intloop1 = -1
        Dim inttable(0, 0) As Integer
        Dim intloop19 As Integer = 19
        ReDim inttable(intsize, intsize)
        For index1 As Integer = 0 To intloop
            For index2 As Integer = 0 To intloop
                inttable(index1, index2) = -100
            Next
        Next
        For intage1 As Integer = 3 To intloop19
            For intage2 As Integer = intage1 To intloop19
                For intage3 As Integer = intage2 To intloop19
                    place_in_table( _
                    intage1, intage2, intage3, _
                    inttable, intloop, intloop1)
                Next
            Next
        Next
        For intage1 As Integer = 5 To intloop19 - 1
            For intage2 As Integer = intage1 + 1 To intloop19
                For intage3 As Integer = intage2 To intloop19
                    search_table( _
                    intage1, intage2, intage3, _
                    inttable, intloop1, intloop)
                Next
            Next
        Next
    End Sub

    Sub place_in_table( _
    ByRef intage1, ByRef intage2, ByRef intage3, _
    ByRef inttable, ByRef intloop, ByRef intloop1)
        Dim intprod As Integer
        Dim intsum As Integer
        intprod = intage1 * intage2 * intage3
        intsum = intage1 + intage2 + intage3
        For index1 As Integer = 0 To intloop
            If inttable(index1, 0) < 0 Then
                inttable(index1, 0) = intprod
                inttable(index1, 1) = intsum
                inttable(index1, 2) = intage1
                inttable(index1, 3) = intage2
                inttable(index1, 4) = intage3
                intloop1 = index1
                Exit Sub
            End If
            If inttable(index1, 0) = intprod And _
            inttable(index1, 1) = intsum Then
                For index2 As Integer = 2 To intloop
                    If inttable(index1, index2) < 0 Then
                        inttable(index1, index2) = intage1
                        inttable(index1, index2 + 1) = intage2
                        inttable(index1, index2 + 2) = intage3
                        Exit Sub
                    End If
                Next
            End If
        Next
    End Sub

    Sub search_table( _
    ByRef intage1, ByRef intage2, ByRef intage3, _
    ByRef inttable, ByRef intloop1, ByRef intloop)
        Dim intprod As Integer
        Dim intsum As Integer
        Dim intage1_m As Integer
        Dim intage2_m As Integer
        Dim intage3_m As Integer
        Dim intprod_m As Integer
        Dim intsum_m As Integer
        Dim strdisplay As String
        intage1_m = intage1 - 2
        intage2_m = intage2 - 2
        intage3_m = intage3 - 2
        If intage1_m < 0 Or intage2_m < 0 Or intage3_m < 0 Then
            Exit Sub
        End If
        intprod = intage1 * intage2 * intage3
        intsum = intage1 + intage2 + intage3
        intprod_m = intage1_m * intage2_m * intage3_m
        intsum_m = intage1_m + intage2_m + intage3_m
        For index1 As Integer = 0 To intloop1
            If inttable(index1, 0) = intprod And _
            inttable(index1, 1) = intsum Then
                If inttable(index1, 5) < 0 Then
                    Exit Sub
                End If
            End If
        Next
        For index1 As Integer = 0 To intloop1
            If inttable(index1, 0) = intprod_m And _
            inttable(index1, 1) = intsum_m Then
                If inttable(index1, 5) < 0 Then
                    Exit Sub
                End If
            End If
        Next
        Console.WriteLine(" ")
        Console.WriteLine( _
        "Ages: " & _
        intage1 & " " & intage2 & " " & intage3)
        strdisplay = "Current data: "
        For index1 As Integer = 0 To intloop1
            If inttable(index1, 0) = intprod And _
            inttable(index1, 1) = intsum Then
                For index2 As Integer = 0 To intloop
                    If inttable(index1, index2) < 0 Then
                        Exit For
                    End If
                    strdisplay &= inttable(index1, index2) & " "
                Next
                Exit For
            End If
        Next
        Console.WriteLine(strdisplay)
        strdisplay = "Two years ago: "
        For index1 As Integer = 0 To intloop1
            If inttable(index1, 0) = intprod_m And _
            inttable(index1, 1) = intsum_m Then
                For index2 As Integer = 0 To intloop
                    If inttable(index1, index2) < 0 Then
                        Exit For
                    End If
                    strdisplay &= inttable(index1, index2) & " "
                Next
                Exit For
            End If
        Next
        Console.WriteLine(strdisplay)
        Console.WriteLine( _
        "Please press ENTER to continue.")
        Console.ReadLine()
    End Sub
End Module

  


  Posted by Penny on 2005-03-05 03:25:06
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 - 2024 by Animus Pactum Consulting. All rights reserved. Privacy Information