Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions easy_puzzles/horse_racing_duals/test_horse_racing_duals.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"name": "Simple case",
"input": {
'n': 3,
"pi": [
"pis": [
5,
8,
9
Expand All @@ -19,7 +19,7 @@
"name": "Horses in any order",
"input": {
'n': 10,
"pi": [
"pis": [
5,
15,
17,
Expand All @@ -38,7 +38,7 @@
"name": "Many horses",
"input": {
'n': 99999,
"pi": [
"pis": [
9999999,
9999888,
9999741,
Expand Down Expand Up @@ -100047,5 +100047,5 @@
@pytest.mark.parametrize("case", test_cases, ids = [case["name"] for case in test_cases])
def test_cases_run(case):
input = case["input"]
output = main(input['n'], input["pi"])
output = main(input['n'], input["pis"])
assert (output == case["expected_value"])
104 changes: 104 additions & 0 deletions easy_puzzles/power_of_thor_episode_1/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
# Power of Thor - Episode 1

## The Goal

Your program must allow Thor to reach the light of power.

## Rules

Thor moves on a map which is 40 wide by 18 high. Note that the coordinates (X and Y) start at the top left! This means the most top left cell has coordinates "X=0,Y=0" and the most bottom right one has the coordinates "X=39,Y=17".

Once the program starts you are given:
- the variable `lightX`: the X position of the light of power that Thor must reach.
- the variable `lightY`: the Y position of the light of power that Thor must reach.
- the variable `initialTX`: the starting X position of Thor.
- the variable `initialTY`: the starting Y position of Thor.

At the end of the game turn, you must output the direction in which you want Thor to go among:

![image_1](https://files.codingame.com/codingame/ragnarok/rose_des_vents2.png)

- `N`: North
- `NE`: North-East
- `E`: East
- `SE`: South-East
- `S`: South
- `SW`: South-West
- `W`: West
- `NW`: North-West

Each movement makes Thor move by 1 cell in the chosen direction.

### Victory Conditions

You win when Thor reaches the light of power.

### Lose Conditions

Thor moves outside the map.

### Game Play

#### Initial Phase

Thor starts on the map at position (3, 6). The light is at position (3, 8).

![image_2](https://files.codingame.com/codingame/ragnarok/thor0.png)

#### Round 1

Action `S`: Thor moves towards south.

New position is (3, 7).

![image_2](https://files.codingame.com/codingame/ragnarok/demo1.png)

#### Round 2

Action `S`: Thor moves towards south.

New position is (3, 8).

![image_2](https://files.codingame.com/codingame/ragnarok/demo2.png)

## Note

Do not forget to execute the tests from the "Test cases" panel.

Beware: the tests given and the validators used to compute the score are slightly different in order to avoid hard coded solutions.

## Game Input

The program must first read the initialization data from the standard input, then, in an infinite loop, provides on the standard output the instructions to move Thor.

### Initialization Input

Line 1: 4 integers `lightX`, `lightY`, `initialTX`, `initialTY`. (`lightX`, `lightY`) indicates the position of the light. (`initialTX`, `initialTY`) indicates the initial position of Thor.

### Input for a Game Round

Line 1: the number of remaining moves for Thor to reach the light of power: `remainingTurns`. You can ignore this data but you must read it.

### Output for a Game Round

A single line providing the move to be made `N`, `NE`, `E`, `SE`, `S`, `SW`, `W` or `NW`.

### Constraints

0 < `lightX` < 40

0 < `lightY` < 18

0 < `initialTX` < 40

0 < `initialTY` < 18

Response time for a game round ≤ 100ms

## Synopsis

The final battle of Ragnarök, the twilight of the gods is approaching. You incarnate Thor who is participating in his final battle against all the forces of evil, led by Loki, Thor's wizard brother.

Thor was wounded during a previous battle against Fenrir, the wolf-god. During the battle, Loki took advantage of the general confusion and used his magic to annihilate the magical powers of Thor's hammer, Mjöllnir, by separating it from his soul: the light of power.

Thor, who now feels very weak, must find and reach the light of power, as fast as possible, since it is the only thing which can restore his and Mjöllnir's powers.
32 changes: 32 additions & 0 deletions easy_puzzles/power_of_thor_episode_1/power_of_thor_episode_1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import sys
import math

def main(light_x: int, light_y: int, current_tx: int, current_ty: int) -> tuple:

move_direction = ""

if (current_ty > light_y and current_ty > 0):
move_direction = move_direction + "N"
current_ty = int(current_ty) - 1
elif (current_ty < light_y and current_ty < 17):
move_direction = move_direction + "S"
current_ty = int(current_ty) + 1
if (current_tx > light_x and current_tx > 0):
move_direction = move_direction + "W"
current_tx = int(current_tx) - 1
elif (current_tx < light_x and current_tx < 39):
move_direction = move_direction + "E"
current_tx = int(current_tx) + 1

return move_direction, current_tx, current_ty

# TO PRINT TO CONSOLE

# light_x, light_y, initial_tx, initial_ty = [int(i) for i in input().split()]
# current_tx = initial_tx
# current_ty = initial_ty

# while True:
# result, current_tx, current_ty = main(light_x, light_y, current_tx, current_ty)
# remaining_turns = int(input())
# print(result)
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import pytest

from power_of_thor_episode_1 import main

test_cases = [
{
"name": "Straight line",
"input": {
"light_x": 31,
"light_y": 4,
"initial_tx": 5,
"initial_ty": 4
},
"expected_value":
["E"] * 26
},
{
"name": "Up",
"input": {
"light_x": 31,
"light_y": 4,
"initial_tx": 31,
"initial_ty": 17
},
"expected_value":
["N"] * 13
},
{
"name": "Easy angle",
"input": {
"light_x": 0,
"light_y": 17,
"initial_tx": 31,
"initial_ty": 4
},
"expected_value":
["SW"] * 13 +
["W"] * 18
},
{
"name": "Optimal angle",
"input": {
"light_x": 36,
"light_y": 17,
"initial_tx": 0,
"initial_ty": 0
},
"expected_value":
["SE"] * 17 +
["E"] * 19
}
]

@pytest.mark.parametrize("case", test_cases, ids = [case["name"] for case in test_cases])
def test_cases_run(case):
captured_output = []
input = case["input"]

output, current_tx, current_ty = main(input["light_x"], input["light_y"], input["initial_tx"], input["initial_ty"])
captured_output.append(output)

while (current_tx != input["light_x"] or current_ty != input["light_y"]):
output, current_tx, current_ty = main(input["light_x"], input["light_y"], current_tx, current_ty)
captured_output.append(output)

assert (captured_output == case["expected_value"])