Zig Zag and Zoom

Part A
As you escape run in a zig-zag pattern.

Part B
Ziggity Zaggity Zoom!

Page 1
You need to escape from Death Valley. Archers are trying to shoot you from behind.

Use the power of modulo to dodge these shots!

Modulo caps a number at a certain maximum.

In this case. the modg function should subtract 9 from n while n is greater or equal to 9.



Page 2
The modulo operation returns the remainder after division of one number by another. The modulo function must return a value from 0 to X, where is modulo operand.

While input argument (n) is less than the X it returns the input number. But when n is greater or equal to the X it must reduce the input number by X until it's less than X.

The second function mod9 must return a value from 0 to 9. In the sample code, it works only until n < 9. But when n >= 9 it returns a wrong value. To complete the function you need to add conditional loop while. While it's greater or equal than 9 -- while (n >= 9). If it's true, then subtract -- n = n - 9.

Be careful, and don't change the code under while.

Python
FUNCTIONS: RETURN

A function can return a value back to where the function was called.

You have used function return values a lot: enemy = hero.findNearestEnemy In this example, you assign the value returned by hero.findNearestEnemy to the variable enemy.

Functions you write can also return values, using the return keyword: def add(a, b):     return a + b sum = add(2, 3) hero.say(sum) # The hero says: 5 Note that return immediately exits the function and returns the given value back to the caller.

JavaScript
FUNCTIONS: RETURN

A function can return a value back to where the function was called.

You have used function return values a lot: var enemy = hero.findNearestEnemy; In this example, you assign the value returned by hero.findNearestEnemy to the variable enemy.

Functions you write can also return values, using the return keyword: function add(a, b) { return a + b; } var sum = add(2, 3); hero.say(sum); // The hero says: 5 Note that return immediately exits the function and returns the given value back to the caller.

CoffeeScript
FUNCTIONS: RETURN

A function can return a value back to where the function was called.

You have used function return values a lot:

In this example, you assign the value returned by hero.findNearestEnemy to the variable enemy.

Functions you write can also return values, using the return keyword:

Note that return immediately exits the function and returns the given value back to the caller.

Lua
FUNCTIONS: RETURN

A function can return a value back to where the function was called.

You have used function return values a lot:

In this example, you assign the value returned by hero.findNearestEnemy to the variable enemy.

Functions you write can also return values, using the return keyword:

Note that return immediately exits the function and returns the given value back to the caller.

Python
"A strategy by Anaphalis:" time = hero.time if time < 30: y = 10 + 3 * mod15(time) else: y = 20 + 3 * mod9(time) x = 10 + time hero.moveXY(x, y)
 * 1) Move by with a zigzag pattern using real modulo functions.
 * 2) This function returns a value from 0 to 15: def mod15(n):     while n >= 15:         n -= 15     return n
 * 3) This function should return a value from 0 to 9: def mod9(n):     # While n is greater or equal to 9, subtract 9 from n:     while n >= 9:         n -= 9     return n
 * 4) Don't change the following code: while True:

JavaScript
"A strategy by Anaphalis:" // Escape from Death Valley! // Move by with a zigzag pattern using real modulo functions. // This function returns a value from 0 to 15: function mod15(n) {     while (n >= 15) {         n -= 15;     }     return n; } // This function should return a value from 0 to 9: function mod9(n) {     // While n is greater or equal to 9, subtract 9 from n:     while (n >= 9) {         n -= 9;     }     return n; } // Don't change the following code: while (true) {     var time = hero.time;     var x, y;     if (time < 30) {         y = 10 + 3 * mod15(time);     } else {         y = 20 + 3 * mod9(time);     }     x = 10 + time;     hero.moveXY(x, y); }

CoffeeScript
"A strategy by Anaphalis:"
 * 1) Escape from Death Valley! # Move by with a zigzag pattern using real modulo functions.
 * 2) This function returns a value from 0 to 15: mod15 = (n) ->    while n >= 15        n -= 15    n
 * 3) This function should return a value from 0 to 9: mod9 = (n) ->    # While n is greater or equal to 9, subtract 9 from n:    while n >= 9        n -= 9    n
 * 4) Don't change the following code: while true    time = hero.time    if time < 30        y = 10 + 3 * mod15 time    else        y = 20 + 3 * mod9 time    x = 10 + time    hero.moveXY(x, y)

Lua
"A strategy by Anaphalis:" -- Escape from Death Valley! -- Move by with a zigzag pattern using real modulo functions. -- This function returns a value from 0 to 15: local mod15 = function(n)     while n >= 15 do         n = n - 15     end     return n end -- This function should return a value from 0 to 9: local mod9 = function(n)     -- While n is greater or equal to 9, subtract 9 from n:     while n >= 9 do         n = n - 9     end     return n end -- Don't change the following code: while true do     local time = hero.time     local y     if time < 30 then         y = 10 + 3 * mod15(time)     else         y = 20 + 3 * mod9(time)     end     local x = 10 + time     hero:moveXY(x, y) end