Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Code Challenge: Snacky Friends, a donkey, and Apples
#4
Okay try this.

My first version was a compact, concise little thing similar to @bplus's, but then I reread your challenge and realized I wasn't giving all the information required.

D'oh!!  Chuck it in the #%@&-it bucket and start with fresh ingredients:
(unusually for me, there is no stunt programming or early optimization on this one... just keepin' it simple)
(this program makes no assumptions e.g. about how many apples the donkey eats; it just performs the calculations implied by the puzzle)


Code: (Select All)
Code: (Select All)
Dim C, T, DONKEYEATEN, F1EATEN, F2EATEN, F3EATEN, ALLEAT As Integer


Print "Total", "FatBoy", "Friend2", "Friend3", "Donkey"

For C = 1 To 1000
    T = C
    DONKEYEATEN = 1 'give the donkey an apple so he won't rat us out
    T = T - 1
    If (T Mod 3) = 0 Then
        F1EATEN = T / 3 'friend #1 aka "fatboy".
        T = T - F1EATEN

        DONKEYEATEN = DONKEYEATEN + 1 'give the donkey an apple so he won't rat us out
        T = T - 1
        If (T Mod 3) = 0 Then
            F2EATEN = T / 3
            T = T - F2EATEN

            DONKEYEATEN = DONKEYEATEN + 1 'give the donkey an apple so he won't rat us out
            T = T - 1
            If (T Mod 3) = 0 Then
                F3EATEN = T / 3
                T = T - F3EATEN

                DONKEYEATEN = DONKEYEATEN + 1 'the donkey is sick of apples by now
                T = T - 1
                If (T Mod 3) = 0 Then
                    ALLEAT = T / 3
                    F3EATEN = F3EATEN + ALLEAT
                    F2EATEN = F2EATEN + ALLEAT
                    F1EATEN = F1EATEN + ALLEAT

                    Print C, F1EATEN, F2EATEN, F3EATEN,  DONKEYEATEN

                End If
            End If
        End If
    End If
Next


Possible solutions up to 1000:
   
Reply


Messages In This Thread
RE: Code Challenge: Snacky Friends, a donkey, and Apples - by JRace - 08-04-2024, 05:20 AM



Users browsing this thread: 3 Guest(s)