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

Home > Numbers
Nine kids (Posted on 2004-09-09) Difficulty: 3 of 5
My neighbor has nine kids (all under 21), and their ages are such that you can never pick three kids so that the middle one is the average of the ages of the extreme ones. What are their ages?

(Note that you could also say that you can never find three kids whose ages are in arithmetic progression.)

See The Solution Submitted by e.g.    
Rating: 4.1250 (8 votes)

Comments: ( Back to comment list | You must be logged in to post comments.)
Solution Many different solutions | Comment 14 of 22 |

Assuming a "kid" can be a newborn (age = 0 ???) and assuming there are no twins, I get eighteen different solutions with the VB program below. [I'm losing my touch -- the program took two seconds to execute. :-(   ] 

0 1 3 4 11 13 14 16 20
0 1 3 4 11 13 16 17 20
0 1 3 8 11 12 17 18 20
0 1 4 5 11 13 14 16 20
0 1 4 5 11 13 14 19 20
0 1 4 5 11 14 16 19 20
0 1 4 6 9 15 16 19 20
0 1 5 6 8 13 14 17 19
0 1 6 7 9 15 16 19 20
0 2 3 5 12 13 17 18 20
0 2 3 7 8 15 17 18 20
0 2 3 8 9 12 17 19 20
0 2 5 6 11 13 14 18 19
0 3 4 7 9 16 17 19 20
0 4 6 7 9 15 16 19 20
0 4 6 7 9 16 17 19 20
1 2 6 7 9 14 15 18 20
1 3 6 7 12 14 15 19 20

Program used:

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
        Dim intfamily(100, 9) As Integer
        Dim intloop As Integer = 99
        Dim strstring As String
        strstarttime = TimeOfDay
        Console.WriteLine( _
        TimeOfDay & ": Start of execution.")
        For index1 As Integer = 0 To intloop
            For index2 As Integer = 0 To 8
                intfamily(index1, index2) = 999
            Next
        Next
        For index1 As Integer = 0 To 12
            For index2 As Integer = index1 + 1 To 13
                For index3 As Integer = index2 + 1 To 14
                    sub123(index1, index2, index3, _
                    intfamily, intloop)
                Next
            Next
        Next
        writefile(intfamily, intloop)
        Console.WriteLine("Start of execution: " & strstarttime)
        strendtime = TimeOfDay
        Console.WriteLine( _
        TimeOfDay & ": End of execution.")
        strend = "?"
        Console.WriteLine(" ")
        While strend <> "x"
            Console.WriteLine( _
            "Please enter X to exit program.")
            strend = LCase(Console.ReadLine())
        End While
    End Sub

    Sub sub123(ByRef index1, ByRef index2, ByRef index3, _
    ByRef intfamily, ByRef intloop)
        Dim strflag As String
        meansub( _
        index1, index2, index3, strflag)
        If strflag = "y" Then
            Exit Sub
        End If
        For index4 As Integer = index3 + 1 To 15
            For index5 As Integer = index4 + 1 To 16
                For index6 As Integer = index5 + 1 To 17
                    sub456(index1, index2, index3, _
                    index4, index5, index6, _
                    intfamily, intloop)
                Next
            Next
        Next
    End Sub

    Sub sub456(ByRef index1, ByRef index2, ByRef index3, _
    ByRef index4, ByRef index5, ByRef index6, _
    ByRef intfamily, ByRef intloop)
        Dim strflag As String
        Dim intages(6) As Integer
        intages(0) = index1
        intages(1) = index2
        intages(2) = index3
        intages(3) = index4
        intages(4) = index5
        intages(5) = index6
        For index11 As Integer = 0 To 3
            For index12 As Integer = index11 + 1 To 4
                For index13 As Integer = index12 + 1 To 5
                    meansub( _
                    intages(index11), intages(index12), _
                    intages(index13), strflag)
                    If strflag = "y" Then
                        Exit Sub
                    End If
                Next
            Next
        Next
        For index7 As Integer = index6 + 1 To 18
            For index8 As Integer = index7 + 1 To 19
                For index9 As Integer = index8 + 1 To 20
                    sub789(index1, index2, index3, _
                    index4, index5, index6, _
                    index7, index8, index9, _
                    intfamily, intloop)
                Next
            Next
        Next
    End Sub

    Sub sub789(ByRef index1, ByRef index2, ByRef index3, _
    ByRef index4, ByRef index5, ByRef index6, _
    ByRef index7, ByRef index8, ByRef index9, _
    ByRef intfamily, ByRef intloop)
        Dim strflag As String
        Dim strflag2 As String
        Dim intages(9) As Integer
        intages(0) = index1
        intages(1) = index2
        intages(2) = index3
        intages(3) = index4
        intages(4) = index5
        intages(5) = index6
        intages(6) = index7
        intages(7) = index8
        intages(8) = index9
        For index11 As Integer = 0 To 6
            For index12 As Integer = index11 + 1 To 7
                For index13 As Integer = index12 + 1 To 8
                    meansub( _
                    intages(index11), intages(index12), _
                    intages(index13), strflag)
                    If strflag = "y" Then
                        Exit Sub
                    End If
                Next
            Next
        Next
        If intfamily(intloop, 0) <> 999 Then
            Console.WriteLine( _
            "ERROR !!!! Make results table larger !!!")
            Console.ReadLine()
            End
        End If
        For index11 As Integer = 0 To intloop
            If intfamily(index11, 0) = 999 Then
                For index12 As Integer = 0 To 8
                    intfamily(index11, index12) = _
                    intages(index12)
                Next
                Exit Sub
            End If
        Next
    End Sub

    Sub meansub(ByRef val1, ByRef val2, _
    ByRef val3, ByRef strflag)
        If val2 = (val1 + val3) / 2 Then
            strflag = "y"
        Else
            strflag = "n"
        End If
    End Sub

    Sub writefile(ByRef intfamily, ByRef intloop)
        Dim strstring As String
        Dim objStreamWriter As StreamWriter
        objStreamWriter = _
        New StreamWriter("C:\VBKIDS.AGES2")
        For index1 As Integer = 0 To intloop
            If intfamily(index1, 0) = 999 Then
                Exit For
            End If
            strstring = ""
            For index2 As Integer = 0 To 8
                strstring &= intfamily(index1, index2)
                strstring &= " "
            Next
            objStreamWriter.WriteLine(strstring)
        Next
        objStreamWriter.Close()
    End Sub
End Module

 

 

Edited on September 9, 2004, 10:45 am
  Posted by Penny on 2004-09-09 10:22: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