Hint:

[spoiler]

You will need to assume that each instruction requires some amount of time, even when the robot does not travel.

[/spoiler]

Solution:

[spoiler]

1 – Go Left

2 – If you are standing on a parachute, go to instruction 4

3 – Go to instruction 1

4 – Go Left

5 – Go to instruction 4

[/spoiler]

L = Move left one step

R = Move right one step

Gn = Goto instruction n

Cn = Conditional goto – Gn iff currently standing on a parachute

then the following program will suffice:

1. R

2. L

3. R

4. C6

5. G1

6. R

7. G6

The shortest algorithm I am sure of has 7 instructions.

1. Go Left

2. If Parachute, Skip to 6

3. Go Left

4. Go Right

5. Skip to 1

6. Go Left

7. Skip to 6

Thus, both progress left at one square every three moves until the one who landed on the right hits the other robot’s parachute. After that, the robot that landed on the right speeds up to one square leftward every move.

I had assumed instruction time was negligible compared to moving time in arriving at the algorithm. If every instruction takes equal time, we can eliminate 3 and 4. Both robots move leftward one space every three ticks until the rightmost robot finds the other parachute. Then, the rightmost robot accelerates to one square leftward every two ticks.

]]>Collatz[1] = 1;

Collatz[n_] := If[EvenQ[n], n/2, 3 n + 1];

DoCollatz[n_] := (Print[Length[#] – 1, ” steps: “, #, “\n”]) &@ FixedPointList[Collatz, n]

(* so typing in DoCollatz[27] spits out the sequence starting at 27;

DoCollatz /@ Range[1,200] spits out results for 1 through 200 *)

]]>#so put this together as a simple test for a single number (27))

#!/usr/bin/perl

#

#

my $num = 27;

my $count = 0;

my $test3 = 0;

until( $test3 == 1 )

{

print “$count number is: $num\n”;

if($num eq 1)

{

$test3 = 1;

}

#get last digit if even divide by 2

if(!($num % 2))

{

$num = $num / 2;

}

#if not multiply by 3 and add 1

else

{

$num = (($num * 3) + 1)

}

$count++;

}

————-

#!/usr/bin/env python

def collatz(start):

'''

Run through the collatz series for a given number and return the number of

iterations and the largest number found.

'''

current = start

iter = 0

max = start

while current != 1:

iter += 1

if current % 2: # odd

current = current * 3 + 1

else: # even

current = current / 2

if current > max:

max = current

return (iter, max)

if __name__ == "__main__":

target = 1000

max_tuple = (0, 0, 0)

iter_tuple = (0, 0, 0)

for start in xrange(1, target + 1):

(iter, max) = collatz(start)

if max > max_tuple[2]:

max_tuple = (start, iter, max)

if iter > iter_tuple[1]:

iter_tuple = (start, iter, max)

print 'Largest integer hit:', max_tuple

print 'Longest series hit:', iter_tuple

————-