How Fast Can He Do It?

What is the fewest number of steps this man needs to take to get all of his cherries to his house?

Note: A "step" is counted for each edge he travels. He can retrace his steps, but that would count as two steps.


The answer is 18.

This section requires Javascript.
You are seeing this because something didn't load right. We suggest you, (a) try refreshing the page, (b) enabling javascript if it is disabled on your browser and, finally, (c) loading the non-javascript version of this page . We're sorry about the hassle.

1 solution

Rushikesh Jogdand
Jun 26, 2016

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
F=(0,0) #farmer
S1=(4,1)
S2=(1,2)
S3=(3,4)
S4=(1,5)
H=(5,5) #house
cherries=[S1,S2,S3,S4]
#minimum distance between two nodes
def d(a,b):
    return abs(a[0]-b[0])+abs(a[1]+b[1])
from random import shuffle
minimum=1000
c=10000
while c>0:
    c-=1
    path=d(F,s[0])+d(s[0],s[1])+d(s[1],s[2])+d(s[2],s[3])+d(s[3],H)
    if path<minimum:
        minimum=path
        print(cherries,path)
        shuffle(s)

0 pending reports

×

Problem Loading...

Note Loading...

Set Loading...