diff --git a/README.md b/README.md
index 6f52ac9..cd92b94 100644
--- a/README.md
+++ b/README.md
@@ -1,7 +1,7 @@
# Solutions to CodinGame Puzzles
-
+
The "Solutions to CodinGame Puzzles" project is a collection of answers to coding problems from CodinGame. CodinGame is a website where people can practice coding by solving puzzles. In this project, people have written solutions to these puzzles using languages like Python, C++, and Java. Each solution is saved in a file named after the puzzle it solves. The puzzles range from easy to hard and cover different coding topics like variables, conditions, and arrays. The goal of the project is to help developers get better at problem-solving and learn different ways of coding. It also includes explanations to help people understand the solutions better.
@@ -14,15 +14,15 @@ The "Solutions to CodinGame Puzzles" project is a collection of answers to codin
| Title | Solution(s) | Topic(s) |
| :---: | :------: | :------: |
| Onboarding πΉ | [Python](./puzzles/python3/onboarding), [JavaScript](./puzzles/js/onboarding), [C++](./puzzles/cpp/onboarding) | Variables, Input/Output, Conditions |
-| The Descent π | [Python](./puzzles/python3/the-descent) ★, [Kotlin](./puzzles/kotlin/src/the-descent), [TypeScript](./puzzles/ts/the-descent), [C](./puzzles/c/the-descent) | Conditions, Loops |
-| Power of Thor 1 β‘ | [Python](./puzzles/python3/power-of-thor1) ★, [Kotlin](./puzzles/kotlin/src/power-of-thor1), [TypeScript](./puzzles/ts/power-of-thor1), [C++](./puzzles/cpp/power-of-thor1.cpp), [Swift](./puzzles/swift/power-of-thor1) | Input/Output, Conditions |
-| Temperatures βοΈ | [Python](./puzzles/python3/temperatures) ★, [Kotlin](./puzzles/kotlin/src/temperatures), [TypeScript](./puzzles/ts/temperatures), [Ruby](./puzzles/ruby/temperatures) | Conditions, Loops, Arrays |
-| Mars Lander 1 π | [Python](./puzzles/python3/mars-lander1), [Kotlin](./puzzles/kotlin/src/mars-lander1), [TypeScript](./puzzles/ts/mars-lander1) ★, [C++](./puzzles/cpp/mars-lander1.cpp) | Conditions, Loops |
-| ASCII Art π¨ | [Python](./puzzles/python3/ascii-art), [Kotlin](./puzzles/kotlin/src/ascii-art), [TypeScript](./puzzles/ts/ascii-art), [Ruby](./puzzles/ruby/ascii-art) ★ | Strings |
+| The Descent π | [Python](./puzzles/python3/the-descent) ★, [Kotlin](./puzzles/kotlin/src/the-descent), [TypeScript](./puzzles/ts/the-descent), [C++](./puzzles/cpp/the-descent) | Conditions, Loops |
+| Power of Thor 1 β‘ | [Python](./puzzles/python3/power-of-thor1) ★, [Kotlin](./puzzles/kotlin/src/power-of-thor1), [TypeScript](./puzzles/ts/power-of-thor1), [Bash](./puzzles/bash/power-of-thor1), [Swift](./puzzles/swift/power-of-thor1) | Input/Output, Conditions |
+| Temperatures βοΈ | [Python](./puzzles/python3/temperatures), [Kotlin](./puzzles/kotlin/src/temperatures), [TypeScript](./puzzles/ts/temperatures), [Ruby](./puzzles/ruby/temperatures) ★ | Conditions, Loops, Arrays |
+| Mars Lander 1 π | [Python](./puzzles/python3/mars-lander1), [Kotlin](./puzzles/kotlin/src/mars-lander1), [TypeScript](./puzzles/ts/mars-lander1) ★, [C++](./puzzles/cpp/mars-lander1.cpp), [C#](./puzzles/cs/mars-lander1) | Conditions, Loops |
+| ASCII Art π¨ | [Python](./puzzles/python3/ascii-art) ★, [Kotlin](./puzzles/kotlin/src/ascii-art), [TypeScript](./puzzles/ts/ascii-art), [Ruby](./puzzles/ruby/ascii-art) | Strings |
| Unary 1οΈβ£ | [Python](./puzzles/python3/unary), [TypeScript](./puzzles/ts/unary) ★, [Haskell](./puzzles/haskell/unary), [C#](./puzzles/cs/unary) | Strings, Encoding |
| MIME Type π΅ | [Python](./puzzles/python3/mime-type) ★, [Kotlin](./puzzles/kotlin/src/mime-type), [TypeScript](./puzzles/ts/mime-type), [C#](./puzzles/cs/mime-type) | Strings, Hash Tables |
-| Defibrillators π | [Python](./puzzles/python3/defibrillators) ★, [Kotlin](./puzzles/kotlin/src/defibrillators), [TypeScript](./puzzles/ts/defibrillators), [C#](./puzzles/cs/defibrillators) | Strings, Trigonometry |
-| Racing Duals π | [Python](./puzzles/python3/horse-racing-duals) ★, [Kotlin](./puzzles/kotlin/src/horse-racing-duals), [JavaScript](./puzzles/js/horse-racing-duals), [Ruby](./puzzles/ruby/horse-racing-duals) | Arrays, Sorting |
+| Defibrillators π | [Python](./puzzles/python3/defibrillators) ★, [Kotlin](./puzzles/kotlin/src/defibrillators), [JavaScript](./puzzles/js/defibrillators), [C#](./puzzles/cs/defibrillators) | Strings, Trigonometry |
+| Horse-racing Duals π | [Python](./puzzles/python3/horse-racing-duals) ★, [Kotlin](./puzzles/kotlin/src/horse-racing-duals), [JavaScript](./puzzles/js/horse-racing-duals) | Arrays, Sorting |
### Medium Puzzles
| Title | Solution(s) | Topic(s) |
diff --git a/images/codingame_logo.png b/images/codingame_logo.png
new file mode 100644
index 0000000..b6ea7f2
Binary files /dev/null and b/images/codingame_logo.png differ
diff --git a/puzzles/bash/power-of-thor1/README.md b/puzzles/bash/power-of-thor1/README.md
new file mode 100644
index 0000000..6b63e68
--- /dev/null
+++ b/puzzles/bash/power-of-thor1/README.md
@@ -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
+```
diff --git a/puzzles/bash/power-of-thor1/power_of_thor1.sh b/puzzles/bash/power-of-thor1/power_of_thor1.sh
new file mode 100644
index 0000000..6013ddf
--- /dev/null
+++ b/puzzles/bash/power-of-thor1/power_of_thor1.sh
@@ -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
diff --git a/puzzles/cpp/the-descent.cpp b/puzzles/cpp/the-descent.cpp
deleted file mode 100644
index 9584128..0000000
--- a/puzzles/cpp/the-descent.cpp
+++ /dev/null
@@ -1,21 +0,0 @@
-#include
-
-using namespace std;
-
-int main() {
- // game loop
- while (true) {
- int max = -1;
- int indexMax = 0;
- for (int i = 0; i < 8; i++) {
- int height; // represents the height of one mountain.
- cin >> height; cin.ignore();
- if (height > max) {
- max = height;
- indexMax = i;
- }
- }
-
- cout << indexMax << endl; // The index of the mountain to fire on.
- }
-}
diff --git a/puzzles/cpp/the-descent/README.md b/puzzles/cpp/the-descent/README.md
new file mode 100644
index 0000000..6588c01
--- /dev/null
+++ b/puzzles/cpp/the-descent/README.md
@@ -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
+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;
+ }
+}
+```
diff --git a/puzzles/cpp/the-descent/the_descent.cpp b/puzzles/cpp/the-descent/the_descent.cpp
new file mode 100644
index 0000000..5e9f46c
--- /dev/null
+++ b/puzzles/cpp/the-descent/the_descent.cpp
@@ -0,0 +1,25 @@
+#include
+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;
+ }
+}
diff --git a/puzzles/cs/mars-lander1/README.md b/puzzles/cs/mars-lander1/README.md
new file mode 100644
index 0000000..38d517d
--- /dev/null
+++ b/puzzles/cs/mars-lander1/README.md
@@ -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);
+ }
+ }
+}
+```
diff --git a/puzzles/cs/mars-lander1/mars_lander1.cs b/puzzles/cs/mars-lander1/mars_lander1.cs
new file mode 100644
index 0000000..f69a956
--- /dev/null
+++ b/puzzles/cs/mars-lander1/mars_lander1.cs
@@ -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);
+ }
+ }
+}
diff --git a/puzzles/js/defibrillators.js b/puzzles/js/defibrillators.js
deleted file mode 100644
index f429d43..0000000
--- a/puzzles/js/defibrillators.js
+++ /dev/null
@@ -1,36 +0,0 @@
-'use strict';
-
-const EARTH_RADIUS = 6371;
-const NAME = 1;
-const LONGITUDE = 4;
-const LATITUDE = 5;
-
-// Convert degrees to radians
-function toRadians(distance) {
- let degrees = distance.replace(",", ".");
- return degrees * Math.PI / 180;
-}
-
-let min = Number.MAX_SAFE_INTEGER;
-let name = "";
-
-let longitude = toRadians(readline());
-let latitude = toRadians(readline());
-let defibCount = parseInt(readline());
-
-// Determine the name of the defibrillator located the closest to the userβs position.
-for (let i = 0; i < defibCount; ++i) {
- let defib = readline();
- let defibArray = defib.split(";");
- let defibLon = toRadians(defibArray[LONGITUDE]);
- let defibLat = toRadians(defibArray[LATITUDE]);
- let x = (defibLon - longitude) * Math.cos((latitude + defibLat) / 2);
- let y = defibLat - latitude;
- let distance = Math.hypot(x, y) * EARTH_RADIUS;
- if (distance < min) {
- min = distance;
- name = defibArray[NAME];
- }
-}
-
-print(name);
diff --git a/puzzles/js/defibrillators/README.md b/puzzles/js/defibrillators/README.md
new file mode 100644
index 0000000..a1028a9
--- /dev/null
+++ b/puzzles/js/defibrillators/README.md
@@ -0,0 +1,96 @@
+# Defibrillators
+
+## Problem Description
+
+The city of Montpellier has equipped its streets with defibrillators, and the data corresponding to their positions is available. The task is to write a program that helps users find the nearest defibrillator to their current location.
+
+### Inputs
+
+1. **User Location:**
+ - Line 1: User's longitude (in degrees, comma-separated).
+ - Line 2: User's latitude (in degrees, comma-separated).
+ - Line 3: The number `N` of defibrillators in the city.
+
+2. **Defibrillators Data:**
+ Each of the next `N` lines contains the following fields separated by semicolons (`;`):
+ - A number identifying the defibrillator.
+ - Name of the defibrillator.
+ - Address.
+ - Contact Phone number.
+ - Longitude (degrees, comma-separated).
+ - Latitude (degrees, comma-separated).
+
+### Output
+
+The program should display the **name** of the defibrillator that is **closest** to the userβs current position.
+
+### Distance Formula
+
+The distance `d` between the user and a defibrillator is calculated as:
+
+```
+x = (longitudeB - longitudeA) * cos((latitudeA + latitudeB) / 2)
+y = latitudeB - latitudeA
+distance = hypot(x, y) * 6371
+```
+
+### Constraints
+
+- 0 < `N` < 10,000
+
+### Example
+
+#### Input
+```
+3,879483
+43,608177
+3
+1;Maison de la Prevention Sante;6 rue Maguelone 340000 Montpellier;;3,87952263361082;43,6071285339217
+2;Hotel de Ville;1 place Georges Freche 34267 Montpellier;;3,89652239197876;43,5987299452849
+3;Zoo de Lunaret;50 avenue Agropolis 34090 Mtp;;3,87388031141133;43,6395872778854
+```
+
+#### Output
+```
+Maison de la Prevention Sante
+```
+
+## Code Example
+
+```javascript
+function toRadians(degrees) {
+ return degrees * Math.PI / 180;
+}
+
+// Parse the user's longitude and latitude
+const LON = parseFloat(readline().replace(',', '.'));
+const LAT = parseFloat(readline().replace(',', '.'));
+
+// Number of defibrillators
+const N = parseInt(readline());
+
+let closestDefibName = '';
+let closestDistance = Infinity;
+
+// Loop over each defibrillator to calculate the distance
+for (let i = 0; i < N; i++) {
+ const DEFIB = readline().split(';');
+ const defibLon = parseFloat(DEFIB[4].replace(',', '.'));
+ const defibLat = parseFloat(DEFIB[5].replace(',', '.'));
+
+ // Calculate the distance using the provided formula
+ const x = (defibLon - LON) * Math.cos(toRadians((LAT + defibLat) / 2));
+ const y = defibLat - LAT;
+ const distance = Math.hypot(x, y) * 6371; // Earth's radius in kilometers
+
+ // Check if this defibrillator is closer than the current closest
+ if (distance < closestDistance) {
+ closestDistance = distance;
+ closestDefibName = DEFIB[1];
+ }
+}
+
+// Output the name of the closest defibrillator
+console.log(closestDefibName);
+
+```
diff --git a/puzzles/js/defibrillators/defib.js b/puzzles/js/defibrillators/defib.js
new file mode 100644
index 0000000..1e23959
--- /dev/null
+++ b/puzzles/js/defibrillators/defib.js
@@ -0,0 +1,34 @@
+function toRadians(degrees) {
+ return degrees * Math.PI / 180;
+}
+
+// Parse the user's longitude and latitude
+const LON = parseFloat(readline().replace(',', '.'));
+const LAT = parseFloat(readline().replace(',', '.'));
+
+// Number of defibrillators
+const N = parseInt(readline());
+
+let closestDefibName = '';
+let closestDistance = Infinity;
+
+// Loop over each defibrillator to calculate the distance
+for (let i = 0; i < N; i++) {
+ const DEFIB = readline().split(';');
+ const defibLon = parseFloat(DEFIB[4].replace(',', '.'));
+ const defibLat = parseFloat(DEFIB[5].replace(',', '.'));
+
+ // Calculate the distance using the provided formula
+ const x = (defibLon - LON) * Math.cos(toRadians((LAT + defibLat) / 2));
+ const y = defibLat - LAT;
+ const distance = Math.hypot(x, y) * 6371; // Earth's radius in kilometers
+
+ // Check if this defibrillator is closer than the current closest
+ if (distance < closestDistance) {
+ closestDistance = distance;
+ closestDefibName = DEFIB[1];
+ }
+}
+
+// Output the name of the closest defibrillator
+console.log(closestDefibName);
diff --git a/puzzles/kotlin/src/horse-racing-duals/README.md b/puzzles/kotlin/src/horse-racing-duals/README.md
index 0a34e79..4e37695 100644
--- a/puzzles/kotlin/src/horse-racing-duals/README.md
+++ b/puzzles/kotlin/src/horse-racing-duals/README.md
@@ -1,46 +1,70 @@
-# Horse Racing Duals
-
-This is a solution to the Horse Racing Duals puzzle on [CodinGame](https://www.codingame.com/ide/puzzle/horse-racing-duals).
+# Horse-racing Duals
## Problem Description
-Given `N` integers representing the strengths of `N` horses, your goal is to find the minimum absolute difference between the strengths of any two horses in a pair. You must output this minimum difference.
+The goal of this puzzle is to find the two horses with the closest strength among a given number of horses. The strength of each horse is given as an integer. The program should output the difference between the strengths of the two closest horses.
+
+### Inputs
+
+Line 1: An integer N, the number of horses
-## Solution
+The following N lines: The strength Pi of each horse, an integer
-The approach to solve this problem is to sort the list of horse strengths in ascending order and then compute the absolute difference between adjacent horses. The smallest difference found is the minimum absolute difference between the strengths of any two horses.
+### Output
-## Code Explanation
+The difference D between the two closest strengths. D is an integer greater than or equal to 0.
-The code begins with reading the integer `N` from the input. This is followed by reading `N` integers representing the strengths of the `N` horses. These strengths are stored in a list.
+### Constraints
-The list of horse strengths is then sorted in ascending order using the `sorted()` function. A new list is created by computing the absolute difference between adjacent strengths in the sorted list. The minimum absolute difference found in this new list is the minimum absolute difference between the strengths of any two horses.
+1 < N < 100000
+0 < Pi β€ 10000000
-Finally, the minimum absolute difference is printed to the console.
+### Example
+
+#### Input
+```
+3
+5
+8
+9
+```
+
+#### Output
+```
+1
+```
+
+## Code Example
```kotlin
import java.util.*
-fun main(args : Array) {
-
+fun main(args: Array) {
val input = Scanner(System.`in`)
- val n = input.nextInt()
-
+ val N = input.nextInt()
+
+ // Read all the horse strengths into a list
val strengths = mutableListOf()
- for (i in 0 until n) {
+ for (i in 0 until N) {
strengths.add(input.nextInt())
}
+ // Sort the list of strengths
strengths.sort()
- val differences = mutableListOf()
- for (i in 0 until n-1) {
- differences.add(strengths[i+1] - strengths[i])
+
+ // Initialize a large minimum difference
+ var minDifference = Int.MAX_VALUE
+
+ // Compute the minimum difference between adjacent horses
+ for (i in 0 until N - 1) {
+ val diff = strengths[i + 1] - strengths[i]
+ if (diff < minDifference) {
+ minDifference = diff
+ }
}
- println(differences.min())
+ // Output the minimum difference
+ println(minDifference)
}
-```
-## Conclusion
-
-This solution shows that sorting a list and then computing differences between adjacent elements is an effective way to solve this problem. The code is concise and easy to understand.
\ No newline at end of file
+```
diff --git a/puzzles/python3/ascii-art/README.md b/puzzles/python3/ascii-art/README.md
index cfe3374..c8bda47 100644
--- a/puzzles/python3/ascii-art/README.md
+++ b/puzzles/python3/ascii-art/README.md
@@ -2,15 +2,11 @@
## Description
-"ASCII Art" is a beginner-level coding challenge available on the CodinGame platform. In this challenge, the player is given a string of characters and a font size, and is asked to generate an ASCII art representation of the string using ASCII characters.
+The goal of this puzzle is to simulate an old airport terminal display by displaying a line of text in ASCII art. To solve this challenge, you'll learn how to manage strings and perform array arithmetics. You will practice splitting strings into separate parts, concatenating them into a new string, and using array indexes effectively. By leveraging data structures like arrays or hash tables, you can store and recreate strings to create the ASCII art representation of the input text.
-The ASCII art output should be a sequence of lines, each line representing a row of the output. Each row should contain the ASCII characters that correspond to the input string, with each character expanded to the specified font size. If a character in the input string is not a letter or cannot be represented in ASCII art, it should be replaced with a question mark.
+## Example Input/Output
-The challenge consists of writing a program that takes as input the string of characters, the font size, and the ASCII art characters to be used for each letter, and outputs the corresponding ASCII art representation.
-
-The challenge is designed to help players learn and practice programming skills such as string manipulation, input/output handling, and ASCII art rendering. It is a fun and engaging way to improve programming skills while solving a challenging and entertaining puzzle.
-
-### Example Input
+**Input**
```
4
@@ -24,7 +20,7 @@ CodinGame
```
-### Example Output
+**Output**
```
## # ## ### ### ## # # # ###
@@ -66,28 +62,61 @@ To solve this coding puzzle, you'll need to create a program that takes the widt
7. **Testing**:
- Test your program with different input cases, including different widths, heights, and text inputs, to ensure it works correctly.
-Here's a simplified Python code for the main part of the code:
+## Code Example
```python
-def ascii_art(L, H, T, ascii_dict):
- result = [''] * H
-
- for char in T:
- if char.isalpha():
- index = ord(char.upper()) - ord('A')
- else:
- index = 26 # '?' character
-
- start = index * L
- end = start + L
- for i in range(H):
- result[i] += ascii_dict[i][start:end]
+L = int(input()) # width of each character
+H = int(input()) # height of the ASCII art
+T = input() # input text to be converted to ASCII art
+
+# Read the ASCII art for A-Z and '?'
+ascii_art = []
+for i in range(H):
+ row = input()
+ ascii_art.append(row)
+
+# Create a dictionary to store the ASCII art for each character
+ascii_dict = {}
+
+for i in range(26): # for A-Z
+ ascii_dict[chr(i + ord('A'))] = [ascii_art[j][i*L:(i+1)*L] for j in range(H)]
+
+# '?' will represent any unknown character
+ascii_dict['?'] = [ascii_art[j][26*L:(27)*L] for j in range(H)]
+
+# Convert the input text T to uppercase and handle unknown characters
+result = ['' for _ in range(H)]
+for char in T:
+ if char.isalpha():
+ char = char.upper()
+ else:
+ char = '?'
- return '\n'.join(result)
+ for i in range(H):
+ result[i] += ascii_dict.get(char, ascii_dict['?'])[i]
+
+# Print the ASCII art for the input text T
+for line in result:
+ print(line)
+
```
-This pseudocode outlines the key steps to solve the coding puzzle. You need to implement the details, including reading the ASCII art representations and handling edge cases.
+## Explanation of Code Steps
+
+1. **Input Parsing**:
+ - Read `L` (width of each letter), `H` (height of letters), and `T` (input text).
+ - For `H` lines, read the ASCII art representing all characters from A to Z and `?`.
+
+2. **Store ASCII Art**:
+ - Use a list to store the ASCII art of each character in a structured way.
+ - For each character in the string `T`, extract the corresponding ASCII art from this list.
+
+3. **Handle Non-alphabet Characters**:
+ - Any character outside of the range `[A-Z]` or `[a-z]` should be replaced by the `?` character's ASCII art.
+
+4. **Print the ASCII Art**:
+ - For each line in the height `H`, concatenate and print the corresponding parts of the ASCII art for each character in `T`.
## Edge Cases
-Test your program by experimenting with an empty ASCII art representation for one or more characters to confirm that it appropriately manages missing character representations. Additionally, try inputting a combination of uppercase and lowercase letters to verify that the program handles case conversion and character lookup accurately. Test different combinations of widths and heights to ensure the program can handle various dimensions without errors or output distortion. Provide a single character input string to assess the program's handling of single-character input and its corresponding ASCII art output. Furthermore, examine input strings containing leading, trailing, and multiple consecutive whitespace characters to ensure proper whitespace handling. Lastly, test input strings where characters overlap in the ASCII art output to confirm the program handles such cases without merging characters or distorting the output. By conducting these tests, you can guarantee that the program gracefully handles various scenarios and produces correct ASCII art output under diverse conditions.
+Test your program by experimenting with an empty ASCII art representation for one or more characters to confirm that it appropriately manages missing character representations. Additionally, try inputting a combination of uppercase and lowercase letters to verify that the program handles case conversion and character lookup accurately. Test different combinations of widths and heights to ensure the program can handle various dimensions without errors or output distortion. Provide a single character input string to assess the program's handling of single-character input and its corresponding ASCII art output. Furthermore, examine input strings containing leading, trailing, and multiple consecutive whitespace characters to ensure proper whitespace handling. In summary, thoroughly test your program with various inputs, including empty ASCII art, mixed case letters, different dimensions, single characters, and strings with whitespace, to ensure it handles all cases accurately.
diff --git a/puzzles/python3/defibrillators/README.md b/puzzles/python3/defibrillators/README.md
index 83c0d0a..12dc6f5 100644
--- a/puzzles/python3/defibrillators/README.md
+++ b/puzzles/python3/defibrillators/README.md
@@ -2,12 +2,6 @@
"Defibrillators" is a beginner-level coding challenge available on the CodinGame platform. In this challenge, the player is given the location of a person and the location of several defibrillators in a city, and is asked to determine the closest defibrillator to the person.
-The input contains the location of the person as longitude and latitude, as well as the longitude and latitude of each defibrillator and its name. The player is asked to calculate the distance between the person and each defibrillator using the Haversine formula, which takes into account the curvature of the Earth's surface.
-
-The challenge consists of writing a program that takes as input the location of the person and the locations of the defibrillators, and outputs the name of the closest defibrillator to the person.
-
-The challenge is designed to help players learn and practice programming skills such as geographic coordinate manipulation, distance calculation, and data structures. It is a fun and engaging way to improve programming skills while solving a challenging and entertaining puzzle.
-
## Example Code
```python
diff --git a/puzzles/python3/defibrillators/input.txt b/puzzles/python3/defibrillators/input.txt
index 334d7b4..17449b3 100644
--- a/puzzles/python3/defibrillators/input.txt
+++ b/puzzles/python3/defibrillators/input.txt
@@ -1,6 +1,170 @@
-3,879483
-43,608177
-3
-1;Maison de la Prevention Sante;6 rue Maguelone 340000 Montpellier;;3,87952263361082;43,6071285339217
-2;Hotel de Ville;1 place Georges Freche 34267 Montpellier;;3,89652239197876;43,5987299452849
-3;Zoo de Lunaret;50 avenue Agropolis 34090 Mtp;;3,87388031141133;43,6395872778854
+3,88995587137398
+43,6260090150577
+167
+1;Maison de la Prevention Sante;6 rue Maguelone 340000 Montpellier;04 67 02 21 60;3,87952263361082;43,6071285339217
+2;Hotel de Ville;1 place Georges Freche 34267 Montpellier;04 67 34 44 93;3,89652239197876;43,5987299452849
+3;Zoo de Lunaret;50 avenue Agropolis 34090 Mtp;04 67 54 45 23;3,87388031141133;43,6395872778854
+4;Centre municipal Garosud;34000 Montpellier;04 67 34 74 62;3,85859221929501;43,5725732056683
+14;Service surveillance voie publique (ASVP); 8 Avenue Louis Blanc;04 99 58 80 31-32;3,87964814275905;43,6144971208687
+16;Poste de police Ecusson Centre ville;19 bis Rue durand 34000 Montpellier;04 67 34 70 89;3,87860749270054;43,6050174770208
+17;Unite Service Fourriere;1945 avenue de toulouse;04 67 06 10 51;3,85396082760103;43,5873825371736
+18;Poste de police Hotel de ville;789 chemin de moulares;;3,89399056177745;43,5988579879724
+20;Palais des sports Pierre-de-Coubertin;Avenue de Naples 34000 Montpellier;04 67 03 02 24;3,81388672389191;43,6382964524906
+21;Gymnase Francois Spinosi;Rue de la Cavalade 34000 Montpellier;04 67 15 90 35;3,91771560379933;43,5989740159529
+22;Plateau sportif de Grammont Terrain 9, 10, 11;Avenue Albert Einstein 34000 Montpellier;04 67 64 29 43;3,93528362675365;43,6141400501416
+23;Maison de la Democratie;16, rue de la Republique 34 Mtp;04 67 34 88 00;3,87908231371128;43,605322134559
+24;Gymnase Albert Batteux;150 rue Francois-Joseph-Gossec 34000 Montpellier;04 67 03 02 24;3,85685695958441;43,5740760521572
+25;Gymnase Bernard-Jouanique;Rue Jaques-Dalcroze 34080 Montpellier;04 67 54 63 99;3,84713719383276;43,6209657932612
+26;Stade Municipal Sabathe;Impasse Saint-Cleophas 34000 Montpellier;04 67 47 10 22;3,87069461025189;43,5979909515727
+27;Salle de Sports Alain Achille;1 place Marcel-Godechot 34000 Montpellier;04 67 15 90 35;3,86929208332712;43,6186500172655
+28;Gymnase Alain Le Hetet;237 route de Vauguieres 34 Montpellier;04 67 65 39 69;3,90623909083357;43,6056481110058
+29;Maison pour tous Albert Dubout;1071 avenue de la Justice de Castelnau 34090 Montpellier;04 67 02 68 58;3,88249943562772;43,6264526269792
+30;Maison pour tous Albert Camus;118 allee Maurice-Bonafos 34080 Montpellier;04 67 27 3341;3,86999152558735;43,5968636559527
+31;Mairie annexe de proximite Mosson;111 place de Tipasa Mas de la Paillade 34080 Montpellier;04 67 75 19 10;3,81644667226683;43,6280352697417
+32;Maison pour tous Francois Villon;Rue des Araucarias 34080 Montpellier;04 67 45 04 57;3,839535231275;43,6153516866351
+33;Maison pour tous Melina Mercouri;842 rue de la Vieille Poste 34 Montpellier;04 99 92 23 80;3,90822213186834;43,6134538722091
+35;Cimetiere Saint-lazare;2 rond-point du Souvenir Francais 34000 Montpellier;04 67 75 34 46;3,93613553570902;43,6154360341943
+36;Cimetiere Saint-Etienne;Avenue Albert Einstein 34000 Montpellier;04 99 52 87 35;3,88995587137398;43,6260090150577
+37;Piscine PITOT;40 Allee J.RAYMOND MONTPELLIER;04 67 52 58 89;3,870303933901;43,6123825678961
+38;Piscine A. NAKACHE;237 route de Vauguieres MONTPELLIER;04 67 22 57 05;3,90629916344486;43,6064087905768
+39;Piscine J. TARIS;67 rue L.Michel MONTPELLIER;04 67 79 03 11;3,90104518912559;43,6205269425253
+41;Piscine J. VIVES;1933 AVENUE DE Maurin MONTPELLIER;04 67 27 74 79;3,87258256366286;43,5878357304832
+40;Piscine M. SPILLIART;154 Rue C.DESMOULINS MONTPELLIER;04 67 42 00 92;3,8431426079266;43,5982457580602
+42;Piscine S. BERLIOUX;551 rue Metairie de Saysset MONTPELLIER;04 67 65 38 71;3,89523245626307;43,5904333774241
+43;Piscine NEPTUNE;Avenue de Heidelberg MONTPELLIER;04 67 75 34 93;3,89308118861399;43,6074454675728
+44;Piscine OLYMPIQUE ANTIGONE;195 avenue J.CARTIER MONTPELLIER;04 67 15 63 04;3,81486874802702;43,6203748477124
+45;STADE DE LA MOSSON;Avenue de Heidelberg MONTPELLIER; 04 67 75 74 16;3,81316555213326;43,6218734166524
+46;STADE Y. DU MANOIR;Avenue de la Vanniere MONTPELLIER;04 67 13 60 00;3,85003952312189;43,5936065771106
+47;PALAIS DES SPORTS R.BOUGNOL;1000, avenue du Val de Montferrand MONTPELLIER;04 67 52 76 14;3,87431554927809;43,6380433134334
+48;PATINOIRE VEGAPOLIS;Place de France MONTPELLIER;04 99 522 600;3,91489059571308;43,6029210639592
+49;CAP OMEGA;Rond point Benjamin Franklin MONTPELLIER;04 67 59 30 01;3,91427706121347;43,618609351242
+50;S.F.M.A.;Avenue Albert EINSTEIN MONTPELLIER;04 67 22 83 78;3,93573870254207;43,6156043738023
+51;MUSEE FABRE;13, rue Montpellieret 34000 Montpellier;04 67 14 83 00;3,88015202860524;43,6117202928099
+52;MEDIATHEQUE E.ZOLA;218 Bd de l'Aeroport International 34000 Montpellier;04 67 34 87 00;3,89315695628937;43,6084838193755
+53;DOMAINE DE LA PROVIDENCE;1784 Avenue de TOULOUSE MONTPELLIER;04 99 64 25 80;3,85389341433135;43,5886305406899
+54;RDC PAVILLON JUNON;50 Place Zeus MONTPELLIER;04 67 13 69 27;3,89083244140238;43,6081660748674
+55;RDC PAVILLON ZEUS;50 Place Zeus MONTPELLIER;04 67 13 69 27;3,89081696430097;43,6078670518814
+58;PAVILLON ZEUS (Salle Marianne);50 Place Zeus MONTPELLIER;04 67 13 69 27;3,89066621413495;43,6077521695801
+56;E.S.B.A.M.A.;130 , RUE YEHUDI MONTPELLIER;04 99 58 32 87;3,88438064294719;43,6169436571347
+57;MONTPELLIER DANCE;18 Rue Sainte Ursule MONTPELLIER;04 67 60 83 60;3,87836849830977;43,6139908031415
+59;CRR;14 Rue Eugene Lisbonne 34000 Montpellier;04 67 66 88 46;3,87409666178277;43,610433894746
+60;TAM;Parking comedie centre ville;04 67 07 63 79;3,88022104344314;43,6089439889165
+61;TAM;Parking Corum;04 67 07 63 79;3,88238703743398;43,6140271812289
+62;CCAS (Banque d'Acceuil);125 place Thermidor 34000 MONTPELLIER;04 99 52 77 53 06 14 09 40 21;3,89927443503256;43,6020241114814
+65;Universite Montpellier 1 UFR d'Economie (1er etage, a cote des bureaux de l'administration); Avenue Raymond Dugrand CS 79606 34960 MONTPELLIER Cedex 2;04 34 43 24 44;3,89956530126954;43,6037248716731
+66;Universite Montpellier 1 UFR AES (1er etage, en face de la salle des professeurs);Espace Richter Avenue Raymond Dugrand CS 59640 34960 MONTPELLIER Cedex 2;04 34 43 23 33;3,89991643490189;43,6031038225234
+64;Universite Montpellier 1 ISEM IPAG (Loge);Espace Richter Bat b Vendemiaire CS 19519 34960 MONTPELLIER Cedex 2;ISEM : 04 34 43 20 00 IPAG : 04 67 15 85 46;3,89904523736634;43,6042583430944
+63;Universite Montpellier 1 Services Mutualises Richter PC Securite;Espace Richter Bat E, BIU, MdE, Rue Vendemiaire CS 19519 34960 MONTPELLIER Cedex 2;;3,89848334164309;43,6041786988646
+67;Universite Montpellier 1 UFR Droit (accueil batiment1);39 rue de l'universite 34060 Montpellier Cedex 2;04 67 61 54 00;3,87717345678089;43,6140582253597
+68;Universite Montpellier 1 UFR Droit (accueil batiment2);;;3,87633518840488;43,6138609333465
+69;Universite Montpellier 1 UFR Medecine (Loge batiment Historique);2 rue Ecole de Medecine CS 59001 34060 MONTPELLIER Cedex 2;04 67 60 10 00;3,87354913287527;43,612951860071
+70;Universite Montpellier 1 UFR Medecine (Loge Institut biologie);;;3,87409700190794;43,6150688127327
+71;Universite Montpellier 1 UFR Odontologie (Hall Premier Etage Bat A);545, avenue du Professeur J.L Viala 34193 MONTPELLIER Cedex 5;04 67 10 44 70;3,82353507060243;43,6362497267334
+72;Universite Montpellier 1 UFR Pharmacie (LogeBat A);15, avenue Charles Flahault BP 14491 34093 MONTPELLIER Cedex 5;04 67 54 80 00;3,86189868456889;43,6232360922128
+73;Universite Montpellier 1 UFR Pharmacie (Galerie a cote de la pharmacie experimentale);;;3,86034021457447;43,6220496094564
+74;Universite Montpellier 1 UFR Staps (Batiment A);700, avenue du Pic Saint-Loup 34090 MONTPELLIER;04 67 41 57 00;3,8538650451542;43,640831368515
+75;Universite Montpellier 1 UFR Staps (P1);;;3,84875782514269;43,6393278958929
+76;Universite Montpellier 1 UFR Staps (Palais des Sports);;;3,84872346174789;43,6401970759746
+77;Universite Montpellier 2 PC Securite;;04 67 14 31 11;3,86080925535177;43,6320478884427
+79;Universite Montpellier 2 Secretariat IAE;place Eugene Bataillon 34095 MONTPELLIER CEDEX 5;04 67 14 31 11;3,86173924182999;43,6324310982988
+78;Universite Montpellier 2 Couloir de la presidence 1er etage;;04 67 14 31 11;3,86403637133178;43,6320955198071
+80;Universite Montpellier 2 Laboratoire AREVA;;04 67 14 31 11;3,86719128258212;43,6340354958767
+81;Universite Montpellier 2 SCOPPS;;04 67 14 31 11;3,86651938060978;43,6329423512668
+82;Universite Montpellier 2 Laboratoire L2C;;04 67 14 31 11;3,86500072175922;43,6325272513173
+86;Universite Montpellier 2 Centre Sportif Universitaire Piscine;;04 67 14 31 11;3,86372265447782;43,6347707699201
+85;Universite Montpellier 2 Centre Sportif Universitaire Gymnase;Rue Emile Jeanbreau;04 67 14 31 11;3,86411975731741;43,634431102342
+84;Universite Montpellier 2 HALL IEM;;04 67 14 31 11;3,86621601700653;43,6350134840932
+88;Universite paul valery montpellier 3 Loge Entree;Av. Val de montferrand 34199 MONTPELLIER;04 67 14 55 23;3,86987294089832;43,6310996420996
+89;Universite paul valery montpellier batiment Marc Bloch;Route de mende 34199 MONTPELLIER;04 67 14 55 23;3,86914576305111;43,6327403750896
+90;Universite Paul Valery montpellier 3 Site Saint Charles Loge Entree;Rue du Professeur Henri Serre 34080 MONTPELLIER Arret tram " albert 1er";04 67 14 55 23;3,87378574801668;43,6165624740146
+91;Montpellier Ecole National Superieure de Chimie;8, rue de l'ecole Normale 34000 MONTPELLIER;04 67 14 72 83;3,86759222312708;43,6208396831232
+92;Montpellier Ecole National Superieure de Chimie (Laboratoire);104, rue de la galera 34090 MONTPELLIER;04 67 14 72 83;3,83738323298412;43,6371761537967
+93;Montpellier Ecole National Superieure de Chimie;220 - 276 rue de la galera 34090 MONTPELLIER;04 67 14 72 83;3,83828534323613;43,6375710817093
+94;CROUS de MONTPELLIER Restaurants Universitaires Boutonnet;2, Rue Emile Duploye 34090 MONTPELLIER Cedex 01;04 67 63 52 06;3,86940780515415;43,6234756772261
+95;CROUS de MONTPELLIER Restaurants Universitaires Triolet;1061, av. Prof. Joseph Anglada 34090 MONTPELLIER;04 67 63 50 16;3,86018125270489;43,631191261367
+96;CROUS de MONTPELLIER Restaurants Universitaires Vert-Bois;205, rue de la Chenaie 34090 MONTPELLIER;04 67 63 66 45;3,87086361964785;43,6348289810456
+98;CROUS de MONTPELLIER Services Centraux;2, rue Monteil 34033 Montpellier; 04 67 41 50 08;3,87001135797271;43,6224491662391
+97;CROUS de MONTPELLIER Restaurants Universitaires Richter;80, rue Brumaire- 34000 Montpellier;04 67 15 84 47;3,89922794228039;43,6028938663275
+99;CREPS;2 Avenue Charles Flahault 34090 MONTPELLIER;;3,86618003917991;43,6191123089151
+100;Maison des sports (Sport Et Psychologie) Herault Sport;200 avenue du Pere Soulas 34090 MONTPELLIER;04 67 54 82 29;3,86583323268375;43,6183423905225
+101;Herault Sport;747 avenue des apothicaires Parc Euromedecine 34090 Montpellier;04 67 54 82 29;3,83559883662065;43,6416646402407
+103;Lycee Frederic Bazille;3224 route de Mende 34093 MONTPELLIER;04 67 63 89 87;3,8639010584102;43,6460180385688
+104;Lycee Jean Mermoz;717 avenue Jean Mermoz 34000 MONTPELLIER;04 67 20 60 00;3,89080547314588;43,610863473281
+106;Lycee Leonard de Vinci;Rue du Professeur Blayac 34085 MONTPELLIER cedex 4;04 67 10 40 10;3,82313209556008;43,6271809795402
+105;Lycee Jules Ferry;270 avenue de la colline 34070 MONTPELLIER;04 67 10 74 01;3,84226731025644;43,6052528635409
+107;Caisse Primaire d'Assurance Maladie;29 cours Gambetta 34000 MONTPELLIER;04 99 52 54 49;3,87110915929521;43,6065196099402
+108;Caisse Primaire d'Assurance Maladie;90 allee Almicare Calvetti 34000 Montpellier;04 99 52 54 49;3,82126953167633;43,6322018829039
+109;Caisse d'assurance retraite et de la Sante au travail;29 cours Gambetta 34000 MONTPELLIER;04 67 12 94 72;3,87064343057042;43,6068847626242
+110;Caisse d'assurance retraite et de la Sante au travail;Century 2 , 101 place pierre Duhem le millenaire 34000 MONTPELLIER;04 67 12 94 72;3,91465549573187;43,6068978500869
+111;Prefecture de l'Herault;34 Place des Martyrs de la resistance 34000 MONTPELLIER;04 67 61 60 45;3,87675679668135;43,6114960399587
+113;Cour d'appel;1 rue Foch 34000 MONTPELLIER;04 34 08 81 92;3,87282071734522;43,6112848970996
+112;Tribunal de grande instance;Place Pierre Flotte 34000 MONTPELLIER;04 67 12 61 09;3,86914794017784;43,6102006063269
+115;Gare Sncf de Montpellier St Roch;1, Place Auguste Gibert 34000 MONTPELLIER;06 25 91 00 28;3,88084502925211;43,6047523852628
+114;Hotel de Police de Montpellier;206 avenue du Comte de Melgueil 34000 MONTPELLIER;04 99 13 50 00;3,89161633267666;43,603513899768
+116;Pharmacie de L'Europe;2600 avenue de l'europe 34080 MONTPELLIER;04 67 75 16 37;3,82007583943153;43,6418758605771
+117;Pharmacie de l'ovalie;2750 Boulevard Paul Valery 34070 MONTPELLIER;04 67 27 71 72;3,84964180769663;43,5950383978097
+118;Pharmacie Ravoire;33, Rue du Faubourg Saint JAUMES 34000 MONTPELLIER;04 67 63 38 84;3,86983030264785;43,6147553510548
+119;Citroen montpellier;730 Avenue des pres d'arenes 34000 MONTPELLIER;04 67 12 67 01;3,88299732333175;43,5906567856049
+120;Grand Garage de l'Herault Peugeot Montpellier (commerce);905 rue de l'industrie 34007 MONTPELLIER;04 67 06 25 02 04 67 06 25 25;3,88118576492958;43,5829591529706
+121;Grand Garage de l'Herault Peugeot Montpellier (atelier);905 rue de l'industrie 34007 MONTPELLIER;04 67 06 25 02 04 67 06 25 25;3,88146330454406;43,5835668089934
+122;Centre commercial Polygone PC Securite (es1 montpellier);1 rue des Pertuisanes 34000 MONTPELLIER;04 67 99 41 60;3,88578382216927;43,6083221486189
+123;Fnac Montpellier;Centre cial Le Polygone 1 rue des Pertuisanes 34000 MONTPELLIER;04 34 09 06 55;3,88567011518647;43,6085330470563
+124;Galeries La Fayette;Centre cial Le Polygone 1 rue des Pertuisanes BP 3521 34000 MONTPELLIER;04 67 64 83 00;3,88553285006607;43,6081092231254
+125;Geant casino Pres d'Arenes (Pc Securite); 504 Avenue du mas d'argelliers 34070 MONTPELLIER;04 67 86 43 69;3,88808523342942;43,586264441135
+126;Geant casino Celleneuve (Pc Securite);129 bis avenue de Lodeve 34070 MONTPELLIER;04 67 86 43 69 04 99 77 34 00;3,83992052015185;43,6125224275035
+127;Centre Commercial Odysseum;2 place de Lisbonne 34000 MONTPELLIER;04 67 13 50 55;3,92046106179072;43,6045260331335
+128;Magasin IKEA;Odysseum 34000 MONTPELLIER;;3,92438329923687;43,6041477817148
+129;Chronopost;1129 Rue de la castelle 34070 MONTPELLIER;04 67 99 11 03 06 69 58 35 62;3,86885461893472;43,5772303319782
+130;DELL;1 rond-point Benjamin Franklin 34000 MONTPELLIER;06 58 57 85 24;3,91169360147975;43,6184228864032
+131;France 3 Sud Montpellier;10 allee John Napier 34000 MONTPELLIER;04 67 20 30 40;3,90921459780798;43,6145658661223
+132;France Telecom;245 rue de la Galera 34000 MONTPELLIER;04 67 14 66 66;3,83704301955449;43,6384175720502
+133;Sanofi Aventis;371 rue professeur Blayac 34000 MONTPELLIER;04 99 77 78 79;3,82943569760855;43,6234283430937
+134;Veolia Eau;765 rue Henri Becquerel BP41246 34965 MONTPELLIER CEDEX 2;04 67 20 73 73 06 20 69 33 70;3,91517278210411;43,612096722739
+135;Banque de France;98 avenue de Lodeve 34061 MONTPELLIER;04 67 06 79 74;3,85350136943136;43,6102729619807
+136;Mutuelle des motards;1056 rue de la croix verte 34294 MONTPELLIER;04 67 72 73 20;3,84315528199888;43,642457500046
+137;Mutuelle des motards;1027 rue de la croix verte 34294 MONTPELLIER;04 67 72 73 20;3,84351021937092;43,6430362920199
+138;Groupama Sud;Place Jean Antoine de Chaptal 34000 MONTPELLIER;04 67 34 78 86;3,86748181412747;43,6031265793569
+139;Montpellier beton SERVANT Prestations;1, Rue de la Premiere Ecluse 34070 MONTPELLIER;04 67 92 15 10;3,89578183610751;43,5877632296267
+140;Hotel IBIS Centre Comedie;Allee Jules Milhau Immeuble le Triangle 34000 MONTPELLIER;04 99 13 29 99;3,88315927070696;43,6089881225671
+141;Hotel IBIS Montpellier Sud;164 avenue palavas 34070 MONTPELLIER;04 67 58 82 30;3,89172749729087;43,5892502551644
+142;Hotel mercure;Carrefour de l'aeroport 34000 MONTPELLIER;04 67 20 63 63;3,8940718175978;43,6089445631649
+143;Hotel mercure centre;Rue de la Spirale 34000 MONTPELLIER;04 67 99 89 89;3,88547541488289;43,6090902690373
+144;Hotel NOVOTEL;125 avenue Palavas 34070 MONTPELLIER;04 99 52 34 34;3,89234991103325;43,5895487658564
+145;CRS 56;1 Rue Louis Lepine 34000 MONTPELLIER;04 67 13 17 00;3,90653250762828;43,6122198808195
+146;Accueil clinique du millenaire Accueil;220 bd penelope 34000 MONTPELLIER;04 99 53 61 03;3,91375491076165;43,6020754291092
+147;Accueil clinique du millenaire Urgences;220 bd penelope 34000 MONTPELLIER;04 99 53 61 03;3,91353989374935;43,6014966033821
+148;Ametra;201 place de Thessalie 34000 MONTPELLIER;04 67 84 76 40;3,89226740440157;43,6075603632208
+149;apec;170 rue leon blum 34000 MONTPELLIER;;3,89052741878513;43,6087911504281
+150;Arcade SFGE;1-55 Rue de la Constituante 34000 MONTPELLIER;;3,89422323604739;43,6019066687056
+151;ASPM SECTION AFPS;1635 Avenue Albert Einstein 34000 MONTPELLIER;;3,9167804322775;43,6113532636814
+152;Cafeteria UFR AES;257-269 Rue Vendemiaire 34000 MONTPELLIER;;3,89935218745248;43,603025020351
+153;Caisse MSA Languedoc;4 place Jean Antoine de Chaptal 34000 MONTPELLIER;;3,86725032663434;43,6029957496972
+154;Centre Mutualiste Neurologique PROPARA;263 Rue du Caducee 34000 MONTPELLIER;;3,83221040954412;43,6433843496942
+155;Communaute d Agglomeration de Montpellier;50 place Zeus;;3,8906414844389;43,6076132052153
+156;D.D.S.I.S. HERAULT;2 Rue Duval-Jouve 34000 MONTPELLIER;;3,86542459122745;43,610311327355
+157;DDTM34 - site du Millenaire;233 rue Guglielmo Marconi 34000 MONTPELLIER;;3,91125189536332;43,6121330162831
+158;Ecole Superieure Des Beaux Arts;130 Rue Yehudi Menuhin 34000 MONTPELLIER;;3,88398298908056;43,6171934153182
+159;Faculte de Droit;Rue de l'Ecole Mage 34000 MONTPELLIER;;3,87687944359565;43,6137132951212
+160;faculte de pharmacie;15 avenue charles flahault 34000 MONTPELLIER;;3,86185840432793;43,6239506766346
+161;fafsea;2460 avenue albert einstein 34000 MONTPELLIER;;3,92771433730696;43,6106200898298
+162;Hotel des impots;40 rue de louvois 34000 MONTPELLIER;;3,81969688714667;43,6323423132911
+163;Inset de Montpellier;76 Place de la Revolution 34000 MONTPELLIER;;3,89825148899358;43,6039740268785
+164;maison agriculture;place chaptal 34000 MONTPELLIER;;3,86633327325595;43,6038860913024
+165;TALCO LR;40 rue de Pinville 34000 MONTPELLIER;;3,90506063238055;43,6138087474829
+166;Zenith Sud;avenue Albert Einstein 34000 MONTPELLIER;;3,93074702939992;43,6128228432964
+168;Action d'Urgence Internationale;1401 rue de fontcouverte 34070 MONTPELLIER;;3,85255897515535;43,5935288046927
+169;Cfpmea;501 des metairies de saysset 34070 MONTPELLIER;;3,89423707713714;43,5906087749725
+172;Amphitheatre d'O;121 Rue de la Carrierasse 34090 MONTPELLIER;;3,83507767297601;43,6351213340499
+173;Batiment k Iut montpellier 2;139 Avenue d'Occitanie 34090 MONTPELLIER;;3,85149578101552;43,6350358178596
+174;Bibliotheque st charles;Rue auguste broussonnet 34090 MONTPELLIER;;3,87258316660111;43,6155361363529
+175;Centre de formation professionnel croix rouge;Rue de la valesiere 34090 MONTPELLIER;;3,83009545801086;43,6415334891597
+176;Chru;Avenue Augustin Fliche 34090 MONTPELLIER;;3,86151292659671;43,6295976450315
+177;Chru euromed;Rue du caduce 34090 MONTPELLIER;;3,8350137442276;43,6425510639908
+179;CHU Lapeyronie hall d'accueil;Pont Lapeyronie 34090 MONTPELLIER;;3,85207580919409;43,6301375533552
+178;Chru lapeyronie;Avenue du doyen gaston giraud 34090 MONTPELLIER;;3,85081289792181;43,6313023033573
+181;Ipl sante envirronement durable Mediterrranee;778 rue de la croix verte 34090 MONTPELLIER;;3,84083465416705;43,6447155674701
+182;Les Jardins de Grasse;1482 Rue de Saint-Priest 34090 MONTPELLIER;;3,83534242743301;43,6375404910418
+183;Parcs Nationaux de France;1037 rue Jean Francois Breton 34090 MONTPELLIER;;3,87871736858804;43,6474178784164
+187;Cirad;Avenue agropolis 34398 MONTPELLIER;;3,868430789818;43,6504884118088
+188;Mornay;26 allee jules milhau 34965 MONTPELLIER;;3,88335468006384;43,6090204423773
+189;Boulodrome Bernard Gasset;122 avenue Maurice Planes 34070 MONTPELLIER;;3,84329169898554;43,5967806501323
diff --git a/puzzles/python3/defibrillators/test-defibrillators.sh b/puzzles/python3/defibrillators/test-defibrillators.sh
index 3fbf9e0..79a3838 100755
--- a/puzzles/python3/defibrillators/test-defibrillators.sh
+++ b/puzzles/python3/defibrillators/test-defibrillators.sh
@@ -4,7 +4,7 @@
output=$(python3 puzzles/python3/defibrillators/defibrillators.py < puzzles/python3/defibrillators/input.txt)
# Expected output
-expected_output="Maison de la Prevention Sante"
+expected_output="Cimetiere Saint-Etienne"
# Compare the output with the expected output
if [[ "$output" == "$expected_output" ]]; then
diff --git a/puzzles/python3/mars-lander1/README.md b/puzzles/python3/mars-lander1/README.md
index 28a95ee..0675602 100644
--- a/puzzles/python3/mars-lander1/README.md
+++ b/puzzles/python3/mars-lander1/README.md
@@ -1,13 +1,16 @@
# Mars Lander - Episode 1
+## Description
+
"Mars Lander - Episode 1" is a beginner-level coding challenge available on the CodinGame platform. In this challenge, the player takes on the role of a spaceship pilot trying to safely land a spacecraft on the surface of Mars.
The player is given the coordinates and the speed of the spacecraft, as well as the angle of its trajectory and the thrust power to be used to adjust its speed and direction. The objective is to write a program that computes the optimal thrust power and angle for the spacecraft to land safely on the surface of Mars without crashing or running out of fuel.
The challenge consists of writing a program that takes as input the current state of the spacecraft and outputs the thrust power and angle that should be used to adjust its trajectory and speed for a safe landing. The program needs to take into account the gravitational pull of Mars, the speed of the spacecraft, the remaining fuel, and the altitude of the spacecraft above the surface of Mars.
-The challenge is designed to help players learn and practice programming skills such as physics calculations, conditional statements, and input/output handling. It is a fun and engaging way to improve programming skills while solving a challenging and entertaining puzzle.
+## 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
diff --git a/puzzles/python3/mime-type/README.md b/puzzles/python3/mime-type/README.md
index 9460282..206b63f 100644
--- a/puzzles/python3/mime-type/README.md
+++ b/puzzles/python3/mime-type/README.md
@@ -1,82 +1,81 @@
-# Mime Type
+# MIME Type
-This is a solution to the "Mime Type" problem on [Codingame](https://www.codingame.com/training/easy/mime-type).
+## Description
-## Problem Description
+The task involves creating a program to determine the MIME type of files based on their names. This involves associating file extensions with MIME types. The program reads an association table with N elements and a list of Q file names to be analyzed. For each file name, the program identifies the extension by finding the substring after the last dot character. If the extension is found in the association table (case insensitive), it prints the corresponding MIME type. If the MIME type cannot be determined or the file has no extension, it outputs UNKNOWN. The program takes the number of elements in the table, the number of file names, the extension-MIME associations, and the file names as input, and outputs the corresponding MIME types or UNKNOWN.
-You are given a list of file names and their corresponding MIME types. You need to read a list of file names and determine the corresponding MIME type for each file name. If the MIME type cannot be determined, the program should output `UNKNOWN`.
+## Solution Overview
-The MIME type is determined by the file extension. The table of file extensions and their corresponding MIME types is given.
+To solve this problem, we need to map file extensions to their respective MIME types, and then analyze the file names to determine the MIME type by extracting the extension from the file name. If the extension matches one in our table (case insensitive), we return the MIME type; otherwise, we return `UNKNOWN`.
-| Extension | MIME Type |
-|-----------|-----------|
-|html |text/html |
-|htm |text/html |
-|png |image/png |
-|jpeg |image/jpeg |
-|jpg |image/jpeg |
-|gif |image/gif |
-|bmp |image/bmp |
-|txt |text/plain|
-|pdf |application/pdf|
+### Explanation:
-The file name may have multiple periods (.) in it, but the extension is always the substring that follows the last period.
+- We use a dictionary `mime_table` to store the file extensions and their corresponding MIME types, converting extensions to lowercase to handle case insensitivity.
+- For each file name, the program finds the last occurrence of a `.` in the string, and extracts the file extension if valid.
+- The MIME type is printed if the extension is found in the dictionary, otherwise `UNKNOWN` is printed.
-## Solution
+### Edge Cases Handled:
-The solution reads the the number of MIME types, number of file names and the file names. It stores the MIME types in a map with the extension as the key. Then it reads a list of file names and determines the corresponding MIME type by looking up the extension in the map. If the extension is not found, it outputs `UNKNOWN`.
+- Files with no extension or a dot at the end.
+- Extensions in different cases (e.g., `.TXT`, `.txt`, `.tXt` all map to the same MIME type).
+- Files whose extensions aren't in the provided table result in `UNKNOWN`.
## Example Input/Output
-Input:
+**Input**
```
-4
-2
+3
+3
html text/html
png image/png
gif image/gif
-txt text/plain
-file.html
-file.txt
+animated.gif
+portrait.png
+index.html
```
-Output:
+**Output**
```
+image/gif
+image/png
text/html
-text/plain
```
-## Example Code
+## Code Example
```python
-# Read the number of elements in the association table
-n = int(input())
-
-# Read the number of file names to be analyzed
-q = int(input())
-
-# Create a dictionary to store the association table
-mime_types = {}
-
-# Read the association table
-for _ in range(n):
- ext, mime = input().split()
- mime_types[ext.lower()] = mime
-
-# Process each file name
-for _ in range(q):
- file_name = input().lower()
-
- # Find the extension of the file
- if '.' in file_name:
- extension = file_name.split('.')[-1]
- if extension in mime_types:
- print(mime_types[extension])
+# Number of elements which make up the association table.
+N = int(input())
+
+# Number of file names to be analyzed.
+Q = int(input())
+
+mime_table = {}
+
+# Reading the MIME type associations.
+for _ in range(N):
+ ext, mime_type = input().split()
+ mime_table[ext.lower()] = mime_type # Store extensions as lowercase for case-insensitivity.
+
+# Processing each file name.
+for _ in range(Q):
+ fname = input()
+
+ # Find the position of the last '.' in the file name.
+ last_dot_index = fname.rfind('.')
+
+ # If there's a '.' and it isn't the last character, extract the extension.
+ if last_dot_index != -1 and last_dot_index < len(fname) - 1:
+ file_ext = fname[last_dot_index + 1:].lower() # Get the file extension and convert to lowercase.
+
+ # Check if the extension exists in the mime_table.
+ if file_ext in mime_table:
+ print(mime_table[file_ext]) # Output the MIME type.
else:
- print("UNKNOWN")
+ print('UNKNOWN') # Output UNKNOWN if extension not found.
else:
- print("UNKNOWN")
+ print('UNKNOWN') # Output UNKNOWN if no extension or '.' at the end.
```
diff --git a/puzzles/python3/mime-type/mime_type.py b/puzzles/python3/mime-type/mime_type.py
index a8dfa12..e00eeca 100644
--- a/puzzles/python3/mime-type/mime_type.py
+++ b/puzzles/python3/mime-type/mime_type.py
@@ -1,27 +1,36 @@
-from typing import Dict
+def mime_type_puzzle():
+ # Number of elements which make up the association table.
+ N = int(input())
+ # Number of file names to be analyzed.
+ Q = int(input())
-def main():
- table: Dict[str, str] = {} # file extension => mime type
- nb_elements: int = int(input())
- nb_names: int = int(input())
+ mime_table = {}
- for _ in range(nb_elements):
- extension, mime_type = input().split()
- table[extension.lower()] = mime_type
+ # Reading the MIME type associations.
+ for _ in range(N):
+ ext, mime_type = input().split()
+ mime_table[ext.lower()] = mime_type # Store extensions as lowercase for case-insensitivity.
- for _ in range(nb_names):
- name: str = input().lower()
- dot_index: int = name.rfind(".")
- if dot_index == -1 or dot_index == len(name) - 1:
- print("UNKNOWN")
- else:
- extension: str = name[dot_index + 1 :]
- if extension in table:
- print(table[extension])
+ # Processing each file name.
+ for _ in range(Q):
+ fname = input()
+
+ # Find the position of the last '.' in the file name.
+ last_dot_index = fname.rfind('.')
+
+ # If there's a '.' and it isn't the last character, extract the extension.
+ if last_dot_index != -1 and last_dot_index < len(fname) - 1:
+ file_ext = fname[last_dot_index + 1:].lower() # Get the file extension and convert to lowercase.
+
+ # Check if the extension exists in the mime_table.
+ if file_ext in mime_table:
+ print(mime_table[file_ext]) # Output the MIME type.
else:
- print("UNKNOWN")
+ print('UNKNOWN') # Output UNKNOWN if extension not found.
+ else:
+ print('UNKNOWN') # Output UNKNOWN if no extension or '.' at the end.
if __name__ == "__main__":
- main()
+ mime_type_puzzle()
diff --git a/puzzles/python3/mime-type/test_mime_type.py b/puzzles/python3/mime-type/test_mime_type.py
index b1d34b3..5ac7ca9 100644
--- a/puzzles/python3/mime-type/test_mime_type.py
+++ b/puzzles/python3/mime-type/test_mime_type.py
@@ -1,9 +1,9 @@
from unittest.mock import patch, call
-from mime_type import main
+from mime_type import mime_type_puzzle
-def test_mime_type():
+def test_mime_type_with_unknown_extension():
# Set up
input_data = [
"3", # Number of elements
@@ -26,10 +26,71 @@ def test_mime_type():
# Execute
with patch("builtins.input", side_effect=input_data):
with patch("builtins.print") as mocked_print:
- main()
+ mime_type_puzzle()
# Assert
mocked_print.assert_has_calls([call(output) for output in expected_output])
-test_mime_type()
+def test_mime_type_with_no_extension_or_dot_character():
+ # Set up
+ input_data = [
+ "3", # Number of elements
+ "4", # Number of names
+ "html text/html", # Extension and mime type mapping
+ "png image/png", # Extension and mime type mapping
+ "gif image/gif", # Extension and mime type mapping
+ "file", # Input name
+ "image", # Input name
+ "file.", # Input name with no extension
+ "image.", # Input name with no extension
+ ]
+ expected_output = [
+ "UNKNOWN",
+ "UNKNOWN",
+ "UNKNOWN",
+ "UNKNOWN",
+ ]
+
+ # Execute
+ with patch("builtins.input", side_effect=input_data):
+ with patch("builtins.print") as mocked_print:
+ mime_type_puzzle()
+
+ # Assert
+ mocked_print.assert_has_calls([call(output) for output in expected_output])
+
+
+def test_mime_type_with_different_cases():
+ # Set up
+ input_data = [
+ "3", # Number of elements
+ "4", # Number of names
+ "txt text/plain", # Extension and mime type mapping
+ "jpg image/jpeg", # Extension and mime type mapping
+ "png image/png", # Extension and mime type mapping
+ "file.TXT", # Input name
+ "image.JPG", # Input name
+ "file.tXt", # Input name
+ "image.Png", # Input name
+ ]
+ expected_output = [
+ "text/plain",
+ "image/jpeg",
+ "text/plain",
+ "image/png",
+ ]
+
+ # Execute
+ with patch("builtins.input", side_effect=input_data):
+ with patch("builtins.print") as mocked_print:
+ mime_type_puzzle()
+
+ # Assert
+ mocked_print.assert_has_calls([call(output) for output in expected_output])
+
+
+if __name__ == "__main__":
+ test_mime_type_with_unknown_extension()
+ test_mime_type_with_no_extension_or_dot_character()
+ test_mime_type_with_different_cases()
diff --git a/puzzles/python3/onboarding/README.md b/puzzles/python3/onboarding/README.md
index 0ac7fea..5649b91 100644
--- a/puzzles/python3/onboarding/README.md
+++ b/puzzles/python3/onboarding/README.md
@@ -1,17 +1,51 @@
-Here's a possible solution to the "Onboarding" challenge on CodinGame using Python:
+# Onboarding Puzzle
+
+## Description
+
+In this problem, you need to choose which enemy to shoot based on their distance from your ship. You can compare the distances of the two enemies and then shoot at the closest one.
+
+## Algorithm
+
+The solution uses a `while` loop to continuously read input from the standard input until the program is terminated. In each iteration of the loop, we read in the name and distance of two enemies using the `input()` function, and then compare their distances using an `if` statement. If the distance of the first enemy is less than the distance of the second enemy, we print the name of the first enemy. Otherwise, we print the name of the second enemy.
+
+## Example Input/Output
+
+**Input**
+
+```
+Nobody
+Rock
+9999
+70
+```
+
+**Output**
+
+```
+Rock
+```
+
+## Code Example
+
+The following code example provides a solution to the Onboarding puzzle. It reads input from the standard input, compares the distances of two enemies, and prints the name of the closest enemy to the standard output.
```python
+import sys
+import math
+
+# game loop
while True:
enemy_1 = input() # name of enemy 1
dist_1 = int(input()) # distance to enemy 1
enemy_2 = input() # name of enemy 2
dist_2 = int(input()) # distance to enemy 2
- # Determine which enemy is closer and print its name
+ # Compare the distances of the two enemies
if dist_1 < dist_2:
+ # If enemy 1 is closer, shoot enemy 1
print(enemy_1)
else:
+ # If enemy 2 is closer or at the same distance, shoot enemy 2
print(enemy_2)
-```
-In this solution, we use a `while` loop to continuously read input from the standard input until the program is terminated. In each iteration of the loop, we read the name and distance of two enemies, and then determine which one is closer based on their distances. Finally, we print the name of the closer enemy using `print()`.
+```
diff --git a/puzzles/python3/onboarding/onboarding.py b/puzzles/python3/onboarding/onboarding.py
index 86d082e..416c785 100644
--- a/puzzles/python3/onboarding/onboarding.py
+++ b/puzzles/python3/onboarding/onboarding.py
@@ -1,13 +1,14 @@
-if __name__ == "__main__":
- # game loop
+if __name__ == '__main__':
while True:
- enemy1: str = input() # name of enemy 1
- distance1: int = int(input()) # distance to enemy 1
- enemy2: str = input() # name of enemy 2
- distance2: int = int(input()) # distance to enemy 2
+ enemy_1 = input() # name of enemy 1
+ dist_1 = int(input()) # distance to enemy 1
+ enemy_2 = input() # name of enemy 2
+ dist_2 = int(input()) # distance to enemy 2
- # Display enemy1 name when enemy1 is the closest, enemy2 otherwise
- if distance1 < distance2:
- print(enemy1)
+ # Compare the distances of the two enemies
+ if dist_1 < dist_2:
+ # If enemy 1 is closer, shoot enemy 1
+ print(enemy_1)
else:
- print(enemy2)
+ # If enemy 2 is closer or at the same distance, shoot enemy 2
+ print(enemy_2)
diff --git a/puzzles/python3/power-of-thor1/README.md b/puzzles/python3/power-of-thor1/README.md
index 714d6a1..0abfa21 100644
--- a/puzzles/python3/power-of-thor1/README.md
+++ b/puzzles/python3/power-of-thor1/README.md
@@ -1,8 +1,6 @@
-# Power of Thor
+# Power of Thor - Episode 1
-This is a solution to the Power of Thor puzzle on [Codingame](https://www.codingame.com/training/easy/power-of-thor-episode-1).
-
-## Problem Description
+## 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.
@@ -10,40 +8,45 @@ In this puzzle, Thor is stranded on a rectangular grid and needs to reach a ligh
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.
-## Code Example
+## Example Input/Output
-```python
-# light_x: the X position of the light of power
-# light_y: the Y position of the light of power
-# initial_tx: Thor's starting X position
-# initial_ty: Thor's starting Y position
-light_x, light_y, initial_tx, initial_ty = [int(i) for i in input().split()]
+**Initialization input**
-# game loop
-while True:
- remaining_turns = int(input()) # The remaining amount of turns Thor can move. Do not remove this line.
+```
+31 4 5 4
+```
- move = ""
+**Output for a game round**
- # Check the relative position of Thor and the light of power to determine the move direction
- if initial_ty > light_y:
- move += "N"
- initial_ty -= 1
- elif initial_ty < light_y:
- move += "S"
- initial_ty += 1
+```
+E
+```
- if initial_tx > light_x:
- move += "W"
- initial_tx -= 1
- elif initial_tx < light_x:
- move += "E"
- initial_tx += 1
+## Code Example
- print(move)
+```python
+light_x, light_y, thor_x, thor_y = map(int, input().split())
+while True:
+ remaining_turns = int(input())
+
+ direction = ""
+
+ # Determine the vertical direction (N or S) and update position
+ if thor_y > light_y:
+ direction += "N"
+ thor_y -= 1
+ elif thor_y < light_y:
+ direction += "S"
+ thor_y += 1
+
+ # Determine the horizontal direction (E or W) and update position
+ if thor_x > light_x:
+ direction += "W"
+ thor_x -= 1
+ elif thor_x < light_x:
+ direction += "E"
+ thor_x += 1
+
+ print(direction)
```
-
-## Conclusion
-
-This solution demonstrates how to solve the Power of Thor puzzle on Codingame. The program reads in input values from standard input, enters a loop to calculate the direction in which Thor should move, and outputs the direction in which he should move. This solution can be used as a starting point to solve other puzzles on Codingame or similar platforms.
diff --git a/puzzles/python3/temperatures/README.md b/puzzles/python3/temperatures/README.md
index 845b1c0..fe65a25 100644
--- a/puzzles/python3/temperatures/README.md
+++ b/puzzles/python3/temperatures/README.md
@@ -41,3 +41,18 @@ print(closest_temp if n > 0 else 0)
## Edge Cases
These include scenarios such as an empty input list, all negative temperatures, all positive temperatures, temperatures equidistant from zero with opposite signs, a single temperature in the list, and a large range of temperatures. Testing with an empty list ensures the program outputs 0 as expected, while all negative and positive temperatures verify whether the program identifies the closest positive temperature to zero correctly. Similarly, testing temperatures equidistant from zero with opposite signs checks the program's output in such cases. Additionally, testing with a single temperature ensures the program handles single-item lists accurately, and providing a large range of temperatures evaluates the program's efficiency and performance.
+
+## Example Input/Output
+
+**Input**
+
+```
+5
+1 -2 -8 4 5
+```
+
+**Output**
+
+```
+1
+```
diff --git a/puzzles/python3/the-descent/README.md b/puzzles/python3/the-descent/README.md
index d8e6b61..b7c94ab 100644
--- a/puzzles/python3/the-descent/README.md
+++ b/puzzles/python3/the-descent/README.md
@@ -2,21 +2,28 @@
## Description
-In "The Descent" puzzle, you are given an array of integers representing the heights of a set of mountains. Your goal is to determine which mountain is the tallest and shoot it down by printing its index to the console.
+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.
-## Approach
+## Algorithm
-The approach for solving "The Descent" puzzle is simple. You iterate over the array of mountains and keep track of the tallest mountain seen so far. Once you have iterated over all the mountains, you print the index of the tallest mountain to the console.
+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
-Let's consider the following array of mountains:
+**Input for one game turn**
```
-[9, 8, 6, 7, 3, 5, 4, 1, 2]
+9
+8
+7
+6
+5
+4
+3
+2
```
-Here, the tallest mountain is the one with a height of `9`. The index of this mountain in the array is `0`. Therefore, the output of the program should be:
+**Output for one game turn**
```
0
@@ -25,22 +32,19 @@ Here, the tallest mountain is the one with a height of `9`. The index of this mo
## Code Example
```python
-import sys
-
-# Game loop
while True:
- heights = []
-
- # Read the heights of the mountains
- for _ in range(8):
- mountain_height = int(input()) # Height of the mountain
- heights.append(mountain_height)
-
- # Find the index of the highest mountain
- max_height = max(heights)
- max_height_index = heights.index(max_height)
-
- # Output the index of the highest mountain to shoot
- print(max_height_index)
+ highest_index = 0
+ highest_height = -1
+
+ # Read the heights of the mountains and determine the highest
+ for i in range(8):
+ mountain_height = int(input())
+
+ # Check if this mountain is the highest so far
+ if mountain_height > highest_height:
+ highest_height = mountain_height
+ highest_index = i
+ # Output the index of the highest mountain to shoot
+ print(highest_index)
```
diff --git a/puzzles/python3/the-descent/test_the_descent.py b/puzzles/python3/the-descent/test_the_descent.py
deleted file mode 100644
index 81b1fbe..0000000
--- a/puzzles/python3/the-descent/test_the_descent.py
+++ /dev/null
@@ -1,39 +0,0 @@
-import unittest
-
-from the_descent import solve
-
-
-class TestSolve(unittest.TestCase):
- def test_single_mountain(self):
- mountain_heights = [5]
- expected = 0
- result = solve(mountain_heights)
- self.assertEqual(result, expected)
-
- def test_equal_heights(self):
- mountain_heights = [3, 3, 3, 3]
- expected = 0
- result = solve(mountain_heights)
- self.assertEqual(result, expected)
-
- def test_increasing_heights(self):
- mountain_heights = [1, 2, 3, 4, 5]
- expected = 4
- result = solve(mountain_heights)
- self.assertEqual(result, expected)
-
- def test_decreasing_heights(self):
- mountain_heights = [5, 4, 3, 2, 1]
- expected = 0
- result = solve(mountain_heights)
- self.assertEqual(result, expected)
-
- def test_random_heights(self):
- mountain_heights = [3, 5, 2, 6, 1, 4]
- expected = 3
- result = solve(mountain_heights)
- self.assertEqual(result, expected)
-
-
-if __name__ == "__main__":
- unittest.main()
diff --git a/puzzles/python3/the-descent/the_descent.py b/puzzles/python3/the-descent/the_descent.py
index e37ff32..3207e60 100644
--- a/puzzles/python3/the-descent/the_descent.py
+++ b/puzzles/python3/the-descent/the_descent.py
@@ -1,17 +1,15 @@
-from typing import List
-
-
-def solve(mountain_heights: List[int]) -> int:
- index_to_fire = 0
- max_mountain_height = -1
- for index, mountain_height in enumerate(mountain_heights):
- if mountain_height > max_mountain_height:
- max_mountain_height = mountain_height
- index_to_fire = index
- return index_to_fire
-
-
-if __name__ == "__main__":
- while True:
- mountain_heights = [int(input()) for _ in range(8)]
- print(solve(mountain_heights))
+while True:
+ highest_index = 0
+ highest_height = -1
+
+ # Read the heights of the mountains and determine the highest
+ for i in range(8):
+ mountain_height = int(input())
+
+ # Check if this mountain is the highest so far
+ if mountain_height > highest_height:
+ highest_height = mountain_height
+ highest_index = i
+
+ # Output the index of the highest mountain to shoot
+ print(highest_index)
diff --git a/puzzles/ruby/temperatures/README.md b/puzzles/ruby/temperatures/README.md
index 6ba87a7..8fea628 100644
--- a/puzzles/ruby/temperatures/README.md
+++ b/puzzles/ruby/temperatures/README.md
@@ -1,9 +1,59 @@
# Temperatures
+## Description
+
"Temperatures" is a beginner-level coding challenge available on the CodinGame platform. In this challenge, the player is given a list of integers representing temperature readings in Celsius degrees for a city during a certain period of time.
The objective is to write a program that finds and outputs the closest temperature to zero. If there are two temperatures that are equally close to zero, the program should output the positive one.
The challenge consists of writing a program that takes as input the list of temperature readings and outputs the temperature closest to zero. If the list is empty, the program should output 0.
-The challenge is designed to help players learn and practice programming skills such as array manipulation, looping, and conditional statements. It is a fun and engaging way to improve programming skills while solving a challenging and entertaining puzzle.
+## Solution Overview
+
+The solution to this challenge involves iterating over the list of temperatures and keeping track of the absolute difference between each temperature and zero. The closest temperature to zero is the one with the smallest absolute difference. If there are two temperatures with the same absolute difference, the solution should output the positive one.
+
+## Example Input/Output
+
+**Input**
+
+```
+5
+1 -2 -8 4 5
+```
+
+**Output**
+
+```
+1
+```
+
+## Code Example
+
+```ruby
+# Initialize variables
+closest_temp = nil
+closest_diff = nil
+
+# Read the number of temperatures to analyze
+n = gets.to_i
+
+# Read the temperatures as a string and split it into a list of integers
+temperatures = gets.split(" ").map(&:to_i)
+
+# Find the temperature closest to zero
+temperatures.each do |temperature|
+ # Calculate the absolute difference between the temperature and zero
+ diff = (temperature - 0).abs
+ # Check if the current temperature is closer to zero, handling the case where the closest difference is unknown
+ if closest_temp.nil? || diff < closest_diff
+ closest_temp = temperature
+ closest_diff = diff
+ # choose the positive one by comparing the temperature with zero
+ elsif diff == closest_diff && temperature > 0
+ closest_temp = temperature
+ end
+end
+
+# Print the closest temperature
+puts closest_temp || 0
+```
diff --git a/puzzles/ts/mime-type/README.md b/puzzles/ts/mime-type/README.md
index 87614d3..e4f346f 100644
--- a/puzzles/ts/mime-type/README.md
+++ b/puzzles/ts/mime-type/README.md
@@ -1,9 +1,89 @@
# MIME Type
-"MIME Type" is a beginner-level coding challenge available on the CodinGame platform. In this challenge, the player is given a list of file names and their corresponding MIME types, and is asked to determine the MIME type of a given file name.
+## Description
-A MIME type is a type of Internet standard that is used to indicate the type of data that a file contains. It is typically represented as a two-part identifier, with the first part indicating the type of data (such as "image" or "text") and the second part indicating the specific format or subtype (such as "jpeg" or "html").
+The task involves creating a program to determine the MIME type of files based on their names. This involves associating file extensions with MIME types. The program reads an association table with N elements and a list of Q file names to be analyzed. For each file name, the program identifies the extension by finding the substring after the last dot character. If the extension is found in the association table (case insensitive), it prints the corresponding MIME type. If the MIME type cannot be determined or the file has no extension, it outputs UNKNOWN. The program takes the number of elements in the table, the number of file names, the extension-MIME associations, and the file names as input, and outputs the corresponding MIME types or UNKNOWN.
-The challenge consists of writing a program that takes as input a list of file names and their corresponding MIME types, as well as the name of a file, and outputs the corresponding MIME type for that file. If the file type is not known, the program should output "UNKNOWN".
+## Solution Overview
-The challenge is designed to help players learn and practice programming skills such as string manipulation, conditional statements, and data structures. It is a fun and engaging way to improve programming skills while solving a challenging and entertaining puzzle.
+To solve this problem, we need to map file extensions to their respective MIME types, and then analyze the file names to determine the MIME type by extracting the extension from the file name. If the extension matches one in our table (case insensitive), we return the MIME type; otherwise, we return `UNKNOWN`.
+
+### Explanation:
+
+1. **Input Parsing:**
+ - The number of MIME type associations (`N`) and the number of file names to analyze (`Q`) are read first.
+ - Then, the MIME type associations are stored in an object (`mimeTable`), where the key is the file extension and the value is the MIME type. Extensions are stored in lowercase to ensure case insensitivity.
+
+2. **File Name Analysis:**
+ - For each file name, we determine if it has a valid extension by checking for the last occurrence of a `.` (dot) character.
+ - If the file has an extension (i.e., the `.` is not the last character), we extract the extension, convert it to lowercase, and look it up in the MIME type table.
+ - If the extension exists in the table, the corresponding MIME type is printed; otherwise, `UNKNOWN` is printed.
+
+### Edge Cases Handled:
+
+- Files with no extension or a dot at the end.
+- Extensions in different cases (e.g., `.TXT`, `.txt`, `.tXt` all map to the same MIME type).
+- Files whose extensions aren't in the provided table result in `UNKNOWN`.
+
+## Example Input/Output
+
+**Input**
+
+```
+3
+3
+html text/html
+png image/png
+gif image/gif
+animated.gif
+portrait.png
+index.html
+```
+
+**Output**
+
+```
+image/gif
+image/png
+text/html
+```
+
+## Code Example
+
+```typescript
+const N: number = parseInt(readline()); // Number of elements which make up the association table.
+const Q: number = parseInt(readline()); // Number Q of file names to be analyzed.
+
+const mimeTable: { [key: string]: string } = {};
+
+// Reading the MIME type associations.
+for (let i = 0; i < N; i++) {
+ const inputs: string[] = readline().split(' ');
+ const EXT: string = inputs[0].toLowerCase(); // file extension (converted to lowercase for case-insensitivity)
+ const MT: string = inputs[1]; // MIME type
+ mimeTable[EXT] = MT; // Store the MIME type with the extension as the key
+}
+
+// Processing each file name.
+for (let i = 0; i < Q; i++) {
+ const FNAME: string = readline();
+
+ // Find the position of the last '.' in the file name.
+ const lastDotIndex = FNAME.lastIndexOf('.');
+
+ // If there's a '.' and it isn't the last character, extract the extension.
+ if (lastDotIndex !== -1 && lastDotIndex < FNAME.length - 1) {
+ const fileExt = FNAME.slice(lastDotIndex + 1).toLowerCase(); // Get the file extension and convert to lowercase
+
+ // Check if the extension exists in the mimeTable.
+ if (mimeTable.hasOwnProperty(fileExt)) {
+ console.log(mimeTable[fileExt]); // Output the MIME type
+ } else {
+ console.log('UNKNOWN'); // Output UNKNOWN if extension not found
+ }
+ } else {
+ console.log('UNKNOWN'); // Output UNKNOWN if no extension or '.' at the end
+ }
+}
+
+```
diff --git a/puzzles/ts/mime-type/mime-type.ts b/puzzles/ts/mime-type/mime-type.ts
deleted file mode 100644
index 6d47e65..0000000
--- a/puzzles/ts/mime-type/mime-type.ts
+++ /dev/null
@@ -1,23 +0,0 @@
-const nbElements: number = Number(readline()); // Number of elements which make up the association table.
-const nbNames: number = Number(readline()); // Number of file names to be analyzed.
-let map = new Map(); // file extension => mime type
-for (let i: number = 0; i < nbElements; i++) {
- const [extension, mimeType]: [string, string] = readline().split(' ');
- map.set(extension.toLowerCase(), mimeType);
-}
-
-// For each of the filenames, display on a line the corresponding MIME type. If there is no corresponding type, then display UNKNOWN.
-for (let i: number = 0; i < nbNames; i++) {
- const name: string = readline();
- const dotIndex: number = name.lastIndexOf('.');
- if (dotIndex === -1 || dotIndex === name.length - 1) {
- console.log("UNKNOWN");
- } else {
- const extension: string = name.substring(dotIndex + 1).toLowerCase();
- if (map.has(extension)) {
- console.log(map.get(extension));
- } else {
- console.log("UNKNOWN");
- }
- }
-}
diff --git a/puzzles/ts/mime-type/mime_type.ts b/puzzles/ts/mime-type/mime_type.ts
new file mode 100644
index 0000000..3d2025b
--- /dev/null
+++ b/puzzles/ts/mime-type/mime_type.ts
@@ -0,0 +1,36 @@
+// @ts-nocheck
+
+const N: number = parseInt(readline()); // Number of elements which make up the association table.
+const Q: number = parseInt(readline()); // Number Q of file names to be analyzed.
+
+const mimeTable: { [key: string]: string } = {};
+
+// Reading the MIME type associations.
+for (let i = 0; i < N; i++) {
+ const inputs: string[] = readline().split(' ');
+ const EXT: string = inputs[0].toLowerCase(); // file extension (converted to lowercase for case-insensitivity)
+ const MT: string = inputs[1]; // MIME type
+ mimeTable[EXT] = MT; // Store the MIME type with the extension as the key
+}
+
+// Processing each file name.
+for (let i = 0; i < Q; i++) {
+ const FNAME: string = readline();
+
+ // Find the position of the last '.' in the file name.
+ const lastDotIndex = FNAME.lastIndexOf('.');
+
+ // If there's a '.' and it isn't the last character, extract the extension.
+ if (lastDotIndex !== -1 && lastDotIndex < FNAME.length - 1) {
+ const fileExt = FNAME.slice(lastDotIndex + 1).toLowerCase(); // Get the file extension and convert to lowercase
+
+ // Check if the extension exists in the mimeTable.
+ if (mimeTable.hasOwnProperty(fileExt)) {
+ console.log(mimeTable[fileExt]); // Output the MIME type
+ } else {
+ console.log('UNKNOWN'); // Output UNKNOWN if extension not found
+ }
+ } else {
+ console.log('UNKNOWN'); // Output UNKNOWN if no extension or '.' at the end
+ }
+}
diff --git a/puzzles/ts/mime-type/tsconfig.json b/puzzles/ts/mime-type/tsconfig.json
deleted file mode 100644
index 9478490..0000000
--- a/puzzles/ts/mime-type/tsconfig.json
+++ /dev/null
@@ -1,6 +0,0 @@
-{
- "compilerOptions": {
- "target": "es6",
- },
- "files": ["mime-type.ts"]
-}