maggie's farmer solution can be optimized more

106 views
Skip to first unread message

Aram Dovlatyan

unread,
Aug 15, 2020, 4:12:20 PM8/15/20
to C++ GCU Forum
Hi everyone,

In example 5: math puzzles at page https://developers.google.com/edu/c++/getting-started

The farmer problem I believe can be optimized better than is represented by Google's solution what it seems by Maggie Johnson.


My solution, there is no need to iterate h > 10, p>34 and r>100 because this won't satisfy
the constraint for $100. There are 2 constraints and if you consider them you can optimize the brute force searching algorithm.

my simple fix is to iterate the loops through as follows,

h=0 -> h<=10
p=0 -> p<=34
r=0 -> r<=100

Thank you
Reply all
Reply to author
Forward
0 new messages