Code Challenge: Snacky Friends, a donkey, and Apples - Printable Version +- QB64 Phoenix Edition (https://qb64phoenix.com/forum) +-- Forum: QB64 Rising (https://qb64phoenix.com/forum/forumdisplay.php?fid=1) +--- Forum: Code and Stuff (https://qb64phoenix.com/forum/forumdisplay.php?fid=3) +---- Forum: Programs (https://qb64phoenix.com/forum/forumdisplay.php?fid=7) +---- Thread: Code Challenge: Snacky Friends, a donkey, and Apples (/showthread.php?tid=2902) |
Code Challenge: Snacky Friends, a donkey, and Apples - CharlieJV - 08-04-2024 You'll find my solution for this challenge (coded with BAM) here. The gist of the challenge: Quote:Once upon a time, 3 friends bought apples and carried them on a donkey. RE: Code Challenge: Snacky Friends, a donkey, and Apples - bplus - 08-04-2024 Code: (Select All) For i = 1 To 4000 This problem is similar to 5 Sailors, Coconuts and a Monkey at Rosetta Code. Find the minimum number to satisfy the conditions set by problem, I learned later at Syntax Bomb. RE: Code Challenge: Snacky Friends, a donkey, and Apples - CharlieJV - 08-04-2024 With the code I wrote, the first possible solution for number of apples bought: 79 Friend 3 ate a total of 18 apples. Friend 2 ate a total of 24 apples. Friend 1 ate a total of 33 apples. The donkey ate 4 apples. Friend 1 is a pig. I'm not entirely convinced I got it right, so I look forward to confirmation one way or the other via other approaches. RE: Code Challenge: Snacky Friends, a donkey, and Apples - JRace - 08-04-2024 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)
Possible solutions up to 1000: RE: Code Challenge: Snacky Friends, a donkey, and Apples - Pete - 08-04-2024 While it appears the donkey got the short end of the stick that night, write a program, for the next day, showing how many apples came out of their _ _ _. Pete RE: Code Challenge: Snacky Friends, a donkey, and Apples - bplus - 08-04-2024 Testing 79 79 / 3 = 26 R 1 79 - 26 - 1 = 52 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 more for each friend and donkey gets the 4 Remainders. 26 + 7 = 33 1st 17 + 7 = 24 2nd 11 + 7 = 18 3rd +4 Donkey = 79 It works alright I stand corrected Where did I go wrong? Code: (Select All) For i = 1 To 4000 Aha! i5 mod 3 = 0 was not required! Well it wouldn't be right to be first AND be correct ;-)) Quote:Friend 1 is a pig.ha! Friend 1 was the earliest bird for the worm laden apples RE: Code Challenge: Snacky Friends, a donkey, and Apples - bplus - 08-04-2024 (08-04-2024, 08:54 AM)Pete Wrote: While it appears the donkey got the short end of the stick that night, write a program, for the next day, showing how many apples came out of their _ _ _. Code: (Select All) print 0; "apples came out that any reasonable, well fed human might eat." RE: Code Challenge: Snacky Friends, a donkey, and Apples - CharlieJV - 08-04-2024 (08-04-2024, 05:20 AM)JRace Wrote: Okay try this. Man, I love code that has comedic Easter eggs in 'em !!! When I graduated from university eons ago, I got hired and immediately thrown into a project that was long over budget and late delivering. Four months later, the project was delivered (but buggy), and I was the only team member kept on to eliminate the bugs. The other two Programmer's, the two analysis, the technical architect and the project manager all left. Not long after, I find this gem of a comment in the code: "Completely non-standard way of designing a form. See my analyst." Extra funny to me because of the friction between the 4GL Windows Programmer's and the COBOL Mainframe background analysts. All of that aside: thanks! Nice to compare output results to validate one's own program with somebody else's work. (08-04-2024, 08:54 AM)Pete Wrote: While it appears the donkey got the short end of the stick that night, write a program, for the next day, showing how many apples came out of their _ _ _. Insta-thought: When one comes from a place where the men are men and the donkeys are nervous, the donkeys can only hope to get the short end of any stick late at night ... RE: Code Challenge: Snacky Friends, a donkey, and Apples - CharlieJV - 08-04-2024 (08-04-2024, 10:47 AM)bplus Wrote: ha! Friend 1 was the earliest bird for the worm laden apples The earliest bird may get the worm, but it is the second mouse that gets the cheese. RE: Code Challenge: Snacky Friends, a donkey, and Apples - bplus - 08-04-2024 LOL! oh man I had to think about that for more than second, then all the funnier! |