-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Descent, Thor 1, Temperatures, Mars Lander 1, ASCII Art, MIME Type, D…
…efibrillators & Duals
- Loading branch information
1 parent
5c3fa24
commit 9b689d9
Showing
33 changed files
with
1,164 additions
and
362 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
# Power of Thor - Episode 1 | ||
|
||
## Description | ||
|
||
In this puzzle, Thor is stranded on a rectangular grid and needs to reach a lightning bolt that is located at a specific position on the grid. The position of Thor and the lightning bolt are given as input to the program. Thor can move in four directions: North, South, East, and West. For each move, the program needs to output the direction in which Thor should move to get closer to the lightning bolt. | ||
|
||
## Solution Overview | ||
|
||
The solution uses a loop to iterate over the possible moves of Thor. At each iteration, the program calculates the direction in which Thor should move based on his current position and the position of the lightning bolt. The program then outputs the direction in which Thor should move and updates his position accordingly. | ||
|
||
## Example Input/Output | ||
|
||
**Initialization input** | ||
|
||
``` | ||
31 4 5 4 | ||
``` | ||
|
||
**Output for a game round** | ||
|
||
``` | ||
E | ||
``` | ||
|
||
## Code Example | ||
|
||
```bash | ||
# Auto-generated code below aims at helping you parse | ||
# the standard input according to the problem statement. | ||
# --- | ||
# Hint: You can use the debug stream to print thorX and thorY if Thor seems not to follow your orders. | ||
|
||
# lightX: the X position of the light of power | ||
# lightY: the Y position of the light of power | ||
# thorX: Thor's current X position | ||
# thorY: Thor's current Y position | ||
read -r lightX lightY thorX thorY | ||
|
||
# game loop | ||
while true; do | ||
# remainingTurns: The remaining amount of turns Thor can move. Do not remove this line. | ||
read -r remainingTurns | ||
|
||
# Calculate the direction | ||
direction="" | ||
|
||
# Determine the vertical direction (N or S) and update position | ||
if [ "$thorY" -gt "$lightY" ]; then | ||
direction+="N" | ||
((thorY--)) | ||
elif [ "$thorY" -lt "$lightY" ]; then | ||
direction+="S" | ||
((thorY++)) | ||
fi | ||
|
||
# Determine the horizontal direction (E or W) and update position | ||
if [ "$thorX" -gt "$lightX" ]; then | ||
direction+="W" | ||
((thorX--)) | ||
elif [ "$thorX" -lt "$lightX" ]; then | ||
direction+="E" | ||
((thorX++)) | ||
fi | ||
|
||
# Output the direction | ||
echo "$direction" | ||
done | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
# Auto-generated code below aims at helping you parse | ||
# the standard input according to the problem statement. | ||
# --- | ||
# Hint: You can use the debug stream to print thorX and thorY if Thor seems not to follow your orders. | ||
|
||
# lightX: the X position of the light of power | ||
# lightY: the Y position of the light of power | ||
# thorX: Thor's current X position | ||
# thorY: Thor's current Y position | ||
read -r lightX lightY thorX thorY | ||
|
||
# game loop | ||
while true; do | ||
# remainingTurns: The remaining amount of turns Thor can move. Do not remove this line. | ||
read -r remainingTurns | ||
|
||
# Calculate the direction | ||
direction="" | ||
|
||
# Determine the vertical direction (N or S) and update position | ||
if [ "$thorY" -gt "$lightY" ]; then | ||
direction+="N" | ||
((thorY--)) | ||
elif [ "$thorY" -lt "$lightY" ]; then | ||
direction+="S" | ||
((thorY++)) | ||
fi | ||
|
||
# Determine the horizontal direction (E or W) and update position | ||
if [ "$thorX" -gt "$lightX" ]; then | ||
direction+="W" | ||
((thorX--)) | ||
elif [ "$thorX" -lt "$lightX" ]; then | ||
direction+="E" | ||
((thorX++)) | ||
fi | ||
|
||
# Output the direction | ||
echo "$direction" | ||
done |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
# The Descent | ||
|
||
## Description | ||
|
||
The goal of the puzzle is to destroy the mountains by firing at the highest one at the start of each game turn. The heights of the mountains are given as input, and the output should be the index of the mountain to fire at. The game is won if all the mountains are destroyed, and lost if the ship crashes into a mountain. | ||
|
||
## Algorithm | ||
|
||
The following code snippet is a game loop that continuously reads the heights of 8 mountains and outputs the index of the highest mountain to "shoot" at. It does this by iterating through the mountain heights, keeping track of the highest height and its corresponding index, and then printing the index of the highest mountain. The loop repeats indefinitely. | ||
|
||
## Example Input/Output | ||
|
||
**Input** | ||
|
||
``` | ||
9 | ||
8 | ||
7 | ||
6 | ||
5 | ||
4 | ||
3 | ||
2 | ||
``` | ||
|
||
**Output** | ||
|
||
``` | ||
0 | ||
``` | ||
|
||
## Code Example | ||
|
||
```cpp | ||
#include <iostream> | ||
using namespace std; | ||
|
||
int main() { | ||
// Game loop | ||
while (true) { | ||
int highestIndex = 0; | ||
int highestHeight = -1; | ||
|
||
// Read the heights of the mountains and determine the highest | ||
for (int i = 0; i < 8; i++) { | ||
int mountainHeight; | ||
cin >> mountainHeight; | ||
|
||
// Check if this mountain is the highest so far | ||
if (mountainHeight > highestHeight) { | ||
highestHeight = mountainHeight; | ||
highestIndex = i; | ||
} | ||
} | ||
|
||
// Output the index of the highest mountain to shoot | ||
cout << highestIndex << endl; | ||
} | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#include <iostream> | ||
using namespace std; | ||
|
||
int main() { | ||
// Game loop | ||
while (true) { | ||
int highestIndex = 0; | ||
int highestHeight = -1; | ||
|
||
// Read the heights of the mountains and determine the highest | ||
for (int i = 0; i < 8; i++) { | ||
int mountainHeight; | ||
cin >> mountainHeight; | ||
|
||
// Check if this mountain is the highest so far | ||
if (mountainHeight > highestHeight) { | ||
highestHeight = mountainHeight; | ||
highestIndex = i; | ||
} | ||
} | ||
|
||
// Output the index of the highest mountain to shoot | ||
cout << highestIndex << endl; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
# Mars Lander - Episode 1 | ||
|
||
## Description | ||
|
||
This puzzle teaches you how to compare values using a simple condition. It's an introduction to the "Mars Lander" series of puzzles and requires only a simple condition to solve. | ||
|
||
## Solution Overview | ||
|
||
The algorithm starts by reading the surface data. Then, it enters an infinite loop, continually reading the current state of the spacecraft and calculating the new thrust power based on the vertical speed. The thrust power is adjusted by one unit if the vertical speed exceeds the maximum allowed, and the new power value is adjusted to be within the valid range. The thrust power is adjusted by one unit if the vertical speed is below the minimum allowed, and the new power value is adjusted to be within the valid range. Finally, the new thrust power and rotation angle are printed to the console. | ||
|
||
## Code Example | ||
|
||
```csharp | ||
using System; | ||
|
||
class Player | ||
{ | ||
// Define constants for better readability and maintainability | ||
const int MAX_VERTICAL_SPEED = -40; // Maximum allowed vertical speed before adjusting thrust | ||
const int MAX_THRUST_POWER = 4; // Maximum thrust power | ||
const int MIN_THRUST_POWER = 0; // Minimum thrust power | ||
static void Main(string[] args) | ||
{ | ||
string[] inputs; | ||
int surfaceN = int.Parse(Console.ReadLine()); // the number of points used to draw the surface of Mars. | ||
for (int i = 0; i < surfaceN; i++) | ||
{ | ||
inputs = Console.ReadLine().Split(' '); | ||
int landX = int.Parse(inputs[0]); // X coordinate of a surface point. (0 to 6999) | ||
int landY = int.Parse(inputs[1]); // Y coordinate of a surface point. By linking all the points together in a sequential fashion, you form the surface of Mars. | ||
} | ||
|
||
// game loop | ||
while (true) | ||
{ | ||
inputs = Console.ReadLine().Split(' '); | ||
int hSpeed = int.Parse(inputs[2]); // the horizontal speed (in m/s), can be negative. | ||
int vSpeed = int.Parse(inputs[3]); // the vertical speed (in m/s), can be negative. | ||
int power = int.Parse(inputs[6]); // the thrust power (0 to 4). | ||
// Adjust thrust power based on the vertical speed using constants | ||
if (vSpeed <= MAX_VERTICAL_SPEED && power < MAX_THRUST_POWER) // Increase thrust if falling too fast | ||
{ | ||
power++; | ||
} | ||
else if (vSpeed > MAX_VERTICAL_SPEED && power > MIN_THRUST_POWER) // Decrease thrust if falling slowly | ||
{ | ||
power--; | ||
} | ||
|
||
// Output the desired rotation and power (rotation is always 0 for this level) | ||
Console.WriteLine("0 " + power); | ||
} | ||
} | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
using System; | ||
|
||
class Player | ||
{ | ||
// Define constants for better readability and maintainability | ||
const int MAX_VERTICAL_SPEED = -40; // Maximum allowed vertical speed before adjusting thrust | ||
const int MAX_THRUST_POWER = 4; // Maximum thrust power | ||
const int MIN_THRUST_POWER = 0; // Minimum thrust power | ||
|
||
static void Main(string[] args) | ||
{ | ||
string[] inputs; | ||
int surfaceN = int.Parse(Console.ReadLine()); // the number of points used to draw the surface of Mars. | ||
for (int i = 0; i < surfaceN; i++) | ||
{ | ||
inputs = Console.ReadLine().Split(' '); | ||
int landX = int.Parse(inputs[0]); // X coordinate of a surface point. (0 to 6999) | ||
int landY = int.Parse(inputs[1]); // Y coordinate of a surface point. By linking all the points together in a sequential fashion, you form the surface of Mars. | ||
} | ||
|
||
// game loop | ||
while (true) | ||
{ | ||
inputs = Console.ReadLine().Split(' '); | ||
int hSpeed = int.Parse(inputs[2]); // the horizontal speed (in m/s), can be negative. | ||
int vSpeed = int.Parse(inputs[3]); // the vertical speed (in m/s), can be negative. | ||
int power = int.Parse(inputs[6]); // the thrust power (0 to 4). | ||
|
||
// Adjust thrust power based on the vertical speed using constants | ||
if (vSpeed <= MAX_VERTICAL_SPEED && power < MAX_THRUST_POWER) // Increase thrust if falling too fast | ||
{ | ||
power++; | ||
} | ||
else if (vSpeed > MAX_VERTICAL_SPEED && power > MIN_THRUST_POWER) // Decrease thrust if falling slowly | ||
{ | ||
power--; | ||
} | ||
|
||
// Output the desired rotation and power (rotation is always 0 for this level) | ||
Console.WriteLine("0 " + power); | ||
} | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.