Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Code Challenge: Snacky Friends, a donkey, and Apples
#21
Quote:See if this holds up. These guys may eat a few less than you think:

Testing 51

51 / 3 = 17 R 0 fail need Remainder 1 to give to Donkey

'52 / 3 = 17 R 1 52 - 17 - 1 = 34

'34 / 3 = 11 R 1 34 - 11 - 1 = 22

'22 / 3 = 7 R 1 so 7 for each

'26 + 7 = 33 1st
'17 + 7 = 24 2nd
'11 + 7 = 18 3rd
' +4 Donkey
====================
= 79 It works alright

(08-05-2024, 04:29 PM)Pete Wrote: When I need answers to difficult programming approaches, I consult Clippy... then do the opposite. Works every time! Clippy, the Anti-Maze.

Pete Big Grin

This reminds me of Seinfeld when George started succeeding in Life by doing the opposite of his first instinct.
b = b + ...
Reply
#22
Ah!  I didn't count it as 3 and remainder of 1.  I counted it as eat 1/3, feed the donkey 1 of the remaining. 2/3.
Reply
#23
I remember that episode. I had a friend, in high school, who was pretty close to George. In 1975 and 1976 he was rooting for the Oakland Raiders to make it to and win the Superbowl. Well, both those years Oakland didn't make it, and the Stealers won. So in 1977 he switched to the Stealers and as soon as I heard that, I called him a fool and said that this is the year Oakland will win it all. He was so pissed he bet me $5.00, on the spot, and I took that bet. Congrats to the 1977 Superbowl champion Oakland Raiders! They have their rings, and I have my $5.00 framed and hanging in my mancave.

Edit: It's not Steve's fault. I don't think he grows apples. He could. Amazingly enough, they do quite well in Virginia climate and soil, and unlike Washington state apples, they don't roll to the left.

Pete Big Grin
Shoot first and shoot people who ask questions, later.
Reply
#24
Just got back to home.  Here's the answer with the "Divide by 3, with a remainder of 1", rather than my previous "Divide by 3, give 1 from the remaining".

Simplified down to 8 lines of code:
Code: (Select All)
FOR i = 0 TO 1000
total = i: Guy1 = Eat(total): guy2 = Eat(total): guy3 = Eat(total): morning = (total - 1) / 3
IF Guy1 = INT(Guy1) AND guy2 = INT(guy2) AND guy3 = INT(guy3) AND morning = INT(morning) THEN PRINT i, Guy1 + morning, guy2 + morning, guy3 + morning, 4
NEXT
FUNCTION Eat (Total)
Eat = 1 / 3 * (Total - 1)
Total = Total - 1 / 3 * (Total - 1) - 1
END FUNCTION
Reply
#25
sweet!
b = b + ...
Reply
#26
So testing what we've learned:

How many apples do you need at minimum if you don't give the donkey an apple in the morning?
Hint: considerably less!
b = b + ...
Reply
#27
(08-06-2024, 07:24 AM)bplus Wrote: So testing what we've learned:

How many apples do you need at minimum if you don't give the donkey an apple in the morning?
Hint: considerably less!

Donkey, hell!  Don't give the first guy any.  he's got to be even fatter than me!
Reply
#28
OK then 3 Friends, Apples and Steve who needs no apples, just a music festival roll into the neighborhood once or twice a summer.

Update:
Oh wow! Look at all the apples needed if you aren't giving an apple to a donkey at each divy!
Unless I miscalculated, its more than 79. ??
b = b + ...
Reply
#29
Keeping it to whole apples only, looks like the minimum is 81... the next multiple of 3 (or 9) above 79.

Code: (Select All)
Total         FatBoy        Friend2       Friend3       Donkey
81            35            26            20            0
162           70            52            40            0
243           105           78            60            0
324           140           104           80            0
405           175           130           100           0
486           210           156           120           0
567           245           182           140           0
648           280           208           160           0
729           315           234           180           0
810           350           260           200           0
891           385           286           220           0
972           420           312           240           0
Reply
#30
Yes

Just got Internet back from Tues 4:30PM storm, here are my calcs for the 2 followup questions:
Code: (Select All)
' Charlies orig problem solution
'For i = 1 To 4000
'    If i Mod 3 = 1 Then
'        i2 = i - Int(i / 3) - 1 '1st
'        If i2 Mod 3 = 1 Then
'            i3 = i2 - Int(i2 / 3) - 1 '2nd
'            If i3 Mod 3 = 1 Then
'                i4 = i3 - Int(i3 / 3) - 1 ' 3rd
'                If i4 Mod 3 = 1 Then
'                    i5 = i4 - Int(i4 / 3) - 1 '4th
'                    'If i5 Mod 3 = 0 Then
'                    Print i; "="; i2 / 2 + i5 / 2; "+"; i3 / 2 + i5 / 2; "+"; i4 / 2 + i5 / 2; "+"; 4
'                    Exit For
'                    'End If
'                End If
'            End If
'        End If
'    End If
'Next

Print " What if donkey does not get apple in am? "
For i = 1 To 4000
    If i Mod 3 = 1 Then
        i2 = i - Int(i / 3) - 1 '1st
        If i2 Mod 3 = 1 Then
            i3 = i2 - Int(i2 / 3) - 1 '2nd
            If i3 Mod 3 = 1 Then
                i4 = i3 - Int(i3 / 3) - 1 ' 3rd
                If i4 Mod 3 = 0 Then
                    i5 = i4 - Int(i4 / 3) '4th
                    'If i5 Mod 3 = 0 Then
                    Print i; "="; i2 / 2 + i5 / 2; "+"; i3 / 2 + i5 / 2; "+"; i4 / 2 + i5 / 2; "+"; 3
                    Exit For
                    'End If
                End If
            End If
        End If
    End If
Next

Print " What if donkey doesn't get any apples?"
For i = 1 To 4000
    If i Mod 3 = 0 Then
        i2 = i - Int(i / 3) '1st
        If i2 Mod 3 = 0 Then
            i3 = i2 - Int(i2 / 3) '2nd
            If i3 Mod 3 = 0 Then
                i4 = i3 - Int(i3 / 3) ' 3rd
                If i4 Mod 3 = 0 Then
                    i5 = i4 - Int(i4 / 3) '4th
                    'If i5 Mod 3 = 0 Then
                    Print i; "="; i2 / 2 + i5 / 2; "+"; i3 / 2 + i5 / 2; "+"; i4 / 2 + i5 / 2; "+"; 0
                    ' debug check Print "Divisions:"; i2; i3; i4; i5
                    Exit For
                    'End If
                End If
            End If
        End If
    End If
Next
b = b + ...
Reply




Users browsing this thread: 2 Guest(s)