Skip to content

Commit

Permalink
Puzzles - documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
charlesfranciscodev committed Apr 7, 2023
1 parent 6ab252b commit 1d499bf
Show file tree
Hide file tree
Showing 101 changed files with 1,172 additions and 778 deletions.
65 changes: 29 additions & 36 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# Solutions to CodinGame Puzzles

CodinGame is a challenge-based training platform for programmers where you can improve your coding skills with fun exercises.
The repository contains a number of solutions to programming challenges from CodinGame. These solutions are written in various programming languages, including Python, C++, and Java. Each solution is contained in its own file, with a name that describes the challenge it solves.

This repository contains solutions to CodinGame puzzles, contests and Clash of Code.
In addition to the solutions, the repository also includes some other files, such as a README.md file that provides information about the repository and its contents, as well as some configuration files that are specific to CodinGame.

Note: A "★" next to the solution means this is my personal favorite solution.
It's worth noting that CodinGame is a website that provides programming challenges and puzzles for developers to solve. The challenges are designed to help developers improve their coding skills by providing them with interesting and engaging problems to solve. The website supports a number of different programming languages, and developers can compete with each other to see who can solve the challenges the fastest and most efficiently.

![](https://img.shields.io/github/languages/count/charlesfranciscodev/codingame.svg) ![](https://img.shields.io/github/languages/top/charlesfranciscodev/codingame.svg) ![](https://img.shields.io/badge/code%20style-flake8-black)

Expand All @@ -13,53 +13,46 @@ Note: A "★" next to the solution means this is my personal favorite soluti
### Easy Puzzles
| Title | Solution(s) | Topic(s) |
| :---: | :------: | :------: |
| Onboarding 🏄 | [Python](./puzzles/python3/onboarding.py) ★, [JavaScript](./puzzles/js/onboarding.js), [C++](./puzzles/cpp/onboarding.cpp) | Variables, Input/Output, Conditions |
| The Descent ⛰️ | [Python](./puzzles/python3/the-descent) ★, [Kotlin](./puzzles/kotlin/src/the-descent.kt), [TypeScript](./puzzles/ts/the-descent/the-descent.ts), [C++](./puzzles/cpp/the-descent.cpp) | Conditions, Loops |
| Power of Thor 1 ⚡ | [Python](./puzzles/python3/power-of-thor1) ★, [Kotlin](./puzzles/kotlin/src/power-of-thor1.kt), [JavaScript](./puzzles/js/power-of-thor1.js), [C++](./puzzles/cpp/power-of-thor1.cpp) | Conditions |
| Temperatures 🌡️ | [Python](./puzzles/python3/temperatures) ★, [Kotlin](./puzzles/kotlin/src/temperatures.kt), [JavaScript](./puzzles/js/temperatures.js), [C++](./puzzles/cpp/temperatures.cpp) | Arrays, Absolute Values |
| Mars Lander 1 🚀 | [Python](./puzzles/python3/mars_lander1.py), [Kotlin](./puzzles/kotlin/src/mars-lander1.kt), [JavaScript](./puzzles/js/mars-lander1) ★, [C++](./puzzles/cpp/mars-lander1.cpp) | Conditions, Loops |
| ASCII Art 🎨 | [Python](./puzzles/python3/ascii-art) ★, [Kotlin](./puzzles/kotlin/src/ascii-art.kt), [JavaScript](./puzzles/js/ascii-art.js), [C++](./puzzles/cpp/ascii-art.cpp) | Strings |
| Unary 1️⃣ | [Python](./puzzles/python3/unary.py), [TypeScript](./puzzles/ts/unary) ★ | Strings, Encoding |
| MIME Type 🎶 | [Python](./puzzles/python3/mime_type.py), [Kotlin](./puzzles/kotlin/src/mime-type.kt), [TypeScript](./puzzles/ts/mime-type) ★ | Strings, Hash Tables |
| Defibrillators 💖 | [Python](./puzzles/python3/defibrillators) ★, [Kotlin](./puzzles/kotlin/src/defibrillators.kt), [JavaScript](./puzzles/js/defibrillators.js) | Strings, Trigonometry |
| Horse-racing Duals 🐎 | [Python](./puzzles/python3/horse_racing_duals.py), [Kotlin](./puzzles/kotlin/src/horse-racing-duals.kt), [JavaScript](./puzzles/js/horse-racing-duals.js), [Ruby](./puzzles/ruby/horse-racing-duals) ★ | Arrays, Sorting |
| Onboarding 📚 | [Python](./puzzles/python3/onboarding), [Kotlin](./puzzles/kotlin/src/onboarding), [JavaScript](./puzzles/js/onboarding), [C++](./puzzles/cpp/onboarding), [Go](./puzzles/go/onboarding), [Swift](./puzzles/swift/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/cpp/the-descent.cpp) | 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) | Conditions |
| Temperatures 🌡️ | [Python](./puzzles/python3/temperatures) ★, [Kotlin](./puzzles/kotlin/src/temperatures), [TypeScript](./puzzles/ts/temperatures), [C++](./puzzles/cpp/temperatures.cpp) | Arrays, Absolute Values |
| Mars Lander 1 🚀 | [Python](./puzzles/python3/mars_lander1.py), [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), [C++](./puzzles/cpp/ascii-art.cpp) | Strings |
| Unary 1️⃣ | [Python](./puzzles/python3/unary.py) ★, [Haskell](./puzzles/haskell/unary) | Strings, Encoding |
| MIME Type 🎶 | [Python](./puzzles/python3/mime_type.py) ★, [Kotlin](./puzzles/kotlin/src/mime-type), [TypeScript](./puzzles/ts/mime-type) | Strings, Hash Tables |
| Defibrillators 💖 | [Python](./puzzles/python3/defibrillators) ★, [Kotlin](./puzzles/kotlin/src/defibrillators), [TypeScript](./puzzles/ts/defibrillators) | Strings, Trigonometry |
| Horse-racing Duals 🎠 | [Python](./puzzles/python3/horse_racing_duals.py), [Kotlin](./puzzles/kotlin/src/horse-racing-duals), [TypeScript](./puzzles/ts/horse-racing-duals), [Ruby](./puzzles/ruby/horse-racing-duals) ★ | Arrays, Sorting |

### Medium Puzzles
| Title | Solution(s) | Topic(s) |
| :---: | :------: | :------: |
| Shadows of the Knight 1 | [Python](./puzzles/python3/shadows_knight1.py), [Kotlin](./puzzles/kotlin/src/shadows-knight1.kt), [TypeScript](./puzzles/ts/shadows-knight1/shadows-knight1.ts), [Ruby](./puzzles/ruby/shadows-knight1) ★ | Binary Search, 2D Arrays |
| There is no Spoon 1 🥄 | [Python](./puzzles/python3/there-is-no-spoon1) ★, [Kotlin](./puzzles/kotlin/src/there-is-no-spoon1.kt), [TypeScript](./puzzles/ts/there-is-no-spoon1/there-is-no-spoon1.ts), [C++](./puzzles/cpp/there-is-no-spoon1.cpp) | 2D Arrays |
| DFS 1 🌃 | [Python](./puzzles/python3/skynet-revolution1) ★, [JavaScript](./puzzles/js/skynet-revolution1.js) | Graphs, BFS |
| Don't Panic 1 🕶️ | [Python](./puzzles/python3/dont_panic1.py) ★, [Kotlin](./puzzles/kotlin/src/dont-panic1.kt), [TypeScript](./puzzles/ts/dont-panic1/dont-panic1.ts) | Conditions |
| War | [Python](./puzzles/python3/war) ★, [Kotlin](./puzzles/kotlin/src/war.kt), [TypeScript](./puzzles/ts/war/war.ts), [C++](./puzzles/cpp/war.cpp) | Queues, Card Games |
| Shadows of the Knight 1 🦇 | [Python](./puzzles/python3/shadows-knight1) ★, [Kotlin](./puzzles/kotlin/src/shadows-knight1), [TypeScript](./puzzles/ts/shadows-knight1/shadows-knight1.ts) | Binary Search, 2D Arrays |
| There is no Spoon 1 🥄 | [Python](./puzzles/python3/there-is-no-spoon1) ★, [Kotlin](./puzzles/kotlin/src/there-is-no-spoon1), [TypeScript](./puzzles/ts/there-is-no-spoon1/there-is-no-spoon1.ts), [C++](./puzzles/cpp/there-is-no-spoon1.cpp) | 2D Arrays |
| DFS 1 🌆 | [Python](./puzzles/python3/skynet-revolution1) ★, [JavaScript](./puzzles/js/skynet-revolution1.js) | Graphs, BFS |
| Don't Panic 1 🕶️ | [Python](./puzzles/python3/dont_panic1.py) ★, [Kotlin](./puzzles/kotlin/src/dont-panic1), [TypeScript](./puzzles/ts/dont-panic1/dont-panic1.ts) | Conditions |
| War | [Python](./puzzles/python3/war) ★, [Kotlin](./puzzles/kotlin/src/war), [TypeScript](./puzzles/ts/war/war.ts), [C++](./puzzles/cpp/war.cpp) | Queues, Card Games |
| Stock Exchange Losses 📈 | [Python](./puzzles/python3/stock_exchange.py) ★ | Conditions, Loops |
| The Fall 1 💎 | [Python](./puzzles/python3/the_fall1.py), [JavaScript](./puzzles/js/the-fall1) ★ | 2D Arrays |
| Network Cabling 🏘️ | [Python](./puzzles/python3/network_cabling.py) ★ | Sorting, Median |
| Conway Sequence 👀 | [Python](./puzzles/python3/conway_sequence.py), [Kotlin](./puzzles/kotlin/src/conway-sequence.kt), [Haskell](./puzzles/haskell/conway-sequence) ★ | Sequences |
| Network Cabling 🔌 | [Python](./puzzles/python3/network_cabling.py) ★ | Sorting, Median |
| Conway Sequence 👀 | [Python](./puzzles/python3/conway_sequence.py), [Kotlin](./puzzles/kotlin/src/conway-sequence), [Haskell](./puzzles/haskell/conway-sequence) ★ | Sequences |
| Telephone Numbers 📱 | [Python](./puzzles/python3/telephone_numbers.py) ★ | Tries |
| Dwarfs standing on giants 🐉 | [Python](./puzzles/python3/dwarfs_giants.py) ★, [TypeScript](./puzzles/ts/dwarfs-giants) | Graphs, Recursion |
| Blunder 1 🤖 | [Python](./puzzles/python3/blunder1) ★ | 2D Arrays, State Machine, Simulation |
| Scrabble 🧵 | [Python](./puzzles/python3/scrabble) ★, [Kotlin](./puzzles/kotlin/src/scrabble.kt), [TypeScript](./puzzles/ts/scrabble/scrabble.ts) | Strings, Hash Tables |
| Mayan Calculation 🧮 | [Python](./puzzles/python3/mayan_calc.py), [Kotlin](./puzzles/kotlin/src/mayan-calc) ★, [Ruby](./puzzles/ruby/mayan-calc.rb) | Strings |
| Blunder 1 🍺 | [Python](./puzzles/python3/blunder1) ★ | 2D Arrays, State Machine, Simulation |
| Scrabble 🔤 | [Python](./puzzles/python3/scrabble) ★, [Kotlin](./puzzles/kotlin/src/scrabble), [TypeScript](./puzzles/ts/scrabble/scrabble.ts) | Strings, Hash Tables |
| Mayan Calculation 2️⃣0️⃣ | [Python](./puzzles/python3/mayan_calc.py), [Kotlin](./puzzles/kotlin/src/mayan-calc) ★, [Ruby](./puzzles/ruby/mayan-calc) | Strings |

### Hard Puzzles
| Title | Solution(s) | Topic(s) |
| :---: | :------: | :------: |
| The Labyrinth 🧩 | [Python](./puzzles/python3/the-labyrinth) ★ | 2D Arrays, Graphs, BFS |
| DFS 2 🌃 | [Python](./puzzles/python3/skynet-revolution2) ★, [Kotlin](./puzzles/kotlin/src/skynet-revolution2.kt) | Graphs |
| Vox Codei 1 🧨 | [Python](./puzzles/python3/vox-codei1) ★, [C++](./puzzles/cpp/vox-codei1.cpp) | Simulation |
| Super Computer 📅 | [Python](./puzzles/python3/super-computer) ★ | Sorting, Greedy Algorithms, Scheduling |
| DFS 2 🌆 | [Python](./puzzles/python3/skynet-revolution2) ★, [Kotlin](./puzzles/kotlin/src/skynet-revolution2) | Graphs |
| Vox Codei 1 🎭 | [Python](./puzzles/python3/vox-codei1) ★, [C++](./puzzles/cpp/vox-codei1.cpp) | Simulation |
| Super Computer 📅 | [Python](./puzzles/python3/super-computer), [Kotlin](./puzzles/kotlin/src/super-computer) | Sorting, Greedy Algorithms, Scheduling |
| Roller Coaster 🎢 | [Python](./puzzles/python3/roller-coaster) ★ | Queues, Dynamic Programming, Simulation |
| Surface 🌊 | [Python](./puzzles/python3/surface) ★, [Kotlin](./puzzles/kotlin/src/surface.kt) | 2D Arrays, Graphs, Flood Fill |
| Surface 🌊 | [Python](./puzzles/python3/surface) ★, [Kotlin](./puzzles/kotlin/src/surface) | 2D Arrays, Graphs, Flood Fill |
| CGX Formatter 🎻 | [Python](./puzzles/python3/cgx_formatter.py) ★ | Strings, Parsing |
| TAN Network 🌴 | [Python](./puzzles/python3/tan-network) ★, [Kotlin](./puzzles/kotlin/src/tan-network.kt) | Graphs, Pathfinding |
| TAN Network 🚞 | [Python](./puzzles/python3/tan-network) ★, [Kotlin](./puzzles/kotlin/src/tan-network) | Graphs, Pathfinding |
| Genome Sequencing 🧬 | [Python](./puzzles/python3/genome_sequencing.py) ★ | Strings, Shortest Common Supersequence |
| Blunder 2 🪙 | [Python](./puzzles/python3/blunder2) ★ | Pathfinding |
| Blunder 2 🎱 | [Python](./puzzles/python3/blunder2) ★ | Pathfinding |
| Blunder 3 ⌛ | [Python](./puzzles/python3/blunder3.py) ★ | Time Complexity |

There are solutions available for other puzzles/programming languages as well in this repository.

## Link(s)
* [ethiery](https://ethiery.github.io/codingame/index.html)
* [Genome Sequencing](https://www.xarg.org/puzzle/codingame/genome-sequencing/)
* [CodinGame Profile](https://www.codingame.com/profile/8111ec5700e5b6591daabfc46fd79e278747932)
31 changes: 31 additions & 0 deletions puzzles/cpp/onboarding/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
Here's a possible solution to the "Onboarding" challenge on CodinGame using C++:

```c++
#include <iostream>
#include <string>

using namespace std;

int main()
{
while (true) {
string enemy1;
int dist1;
string enemy2;
int dist2;

cin >> enemy1 >> dist1 >> enemy2 >> dist2;

// Determine which enemy is closer and print its name
if (dist1 < dist2) {
cout << enemy1 << endl;
} else {
cout << enemy2 << endl;
}
}

return 0;
}
```

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 using `cin`, and then determine which one is closer based on their distances. Finally, we print the name of the closer enemy using `cout`. Note that we use `endl` to add a newline character at the end of each output line.
File renamed without changes.
25 changes: 25 additions & 0 deletions puzzles/go/onboarding/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
This Go code uses a `for` loop to continuously read input from standard input and print the name of the closest enemy.

In each iteration of the loop, we use the `Scan` function from the `fmt` package to read in the name and distance of the first enemy into the `enemy1` and `dist1` variables, respectively. We do the same for the second enemy, storing their name and distance in the `enemy2` and `dist2` variables.

We then compare the distances of the two enemies, and print the name of the one that is closest. The `Scan` function reads input from standard input and automatically parses the input into the specified variable types.

```go
package main

import "fmt"

func main() {
for {
var enemy1, enemy2 string
var dist1, dist2 int
fmt.Scan(&enemy1, &dist1, &enemy2, &dist2)

if dist1 < dist2 {
fmt.Println(enemy1)
} else {
fmt.Println(enemy2)
}
}
}
```
File renamed without changes.
8 changes: 7 additions & 1 deletion puzzles/haskell/conway-sequence/README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# Conway Sequence

The task is to display the last line of a conway sequence.
## Problem Description

Conway's Sequence is a sequence of numbers, starting with a 1, such that each subsequent number is a description of the previous number.

To generate a member of Conway's Sequence from the previous member, read off the digits of the previous member, counting the number of digits in groups of the same digit. For example, 1 is read off as "one 1" or 11, 11 is read off as "two 1s" or 21, 21 is read off as "one 2, then one 1" or 1211, and so on.

Your task is to implement a function that generates the nth member of Conway's Sequence.
7 changes: 7 additions & 0 deletions puzzles/haskell/unary/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Unary

"Unary" is a beginner-level coding challenge available on the CodinGame platform. In this challenge, the player is given a string of characters representing a unary number, and is asked to convert it to decimal notation.

A unary number is a number system in which each integer is represented by a corresponding number of symbols or characters. In this challenge, the unary number is represented by a string of the same character, and the value of the number is equal to the length of the string.

The challenge consists of writing a program that takes as input a string of characters representing a unary number and outputs the corresponding decimal notation.
File renamed without changes.
15 changes: 15 additions & 0 deletions puzzles/js/horse-racing-duals/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Horse Racing Duals

You have a list of N horses, each with a strength value, represented by an integer. You need to find the minimum difference in strength between two horses out of all possible pairs of horses. In other words, you need to find the two horses with the closest strength values.

For example, given the following list of horses with their corresponding strength values:

5 8 9 14 21

The minimum difference in strength between two horses is 1, which is the difference between 5 and 8.

The input for the problem consists of two lines. The first line contains an integer N, the number of horses. The second line contains N space-separated integers, representing the strength values of the N horses.

The output should be a single integer, the minimum difference in strength between two horses.

The solution to this problem involves sorting the list of horses in ascending order, and then computing the difference between adjacent horses in the sorted list. The minimum difference is the smallest of these computed differences.
File renamed without changes.
19 changes: 19 additions & 0 deletions puzzles/js/onboarding/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
Here's a possible solution to the "Onboarding" challenge on CodinGame using JavaScript:

```javascript
while (true) {
const enemy1 = readline(); // name of enemy 1
const dist1 = parseInt(readline()); // distance to enemy 1
const enemy2 = readline(); // name of enemy 2
const dist2 = parseInt(readline()); // distance to enemy 2

// Determine which enemy is closer and print its name
if (dist1 < dist2) {
console.log(enemy1);
} else {
console.log(enemy2);
}
}
```

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 `console.log()`.
File renamed without changes.
20 changes: 20 additions & 0 deletions puzzles/kotlin/src/ascii-art/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
Sure, here is a modified version of the documentation for `ascii-art.kt` without the license section:

# ASCII Art

ASCII Art is a Kotlin program that takes in a string of characters and outputs a stylized version of the input using ASCII art. The program works by converting the input string into a series of characters and then replacing each character with a corresponding ASCII art representation.

## Usage

To use ASCII Art, you need to provide a string of characters and a font size. The font size specifies the height of the ASCII art characters in rows. Here is an example usage of the program:

```kotlin
fun main() {
val input = "HELLO"
val fontSize = 5
val asciiArt = AsciiArt(input, fontSize)
println(asciiArt)
}
```

This will output the ASCII art representation of the string "HELLO" with a font size of 5.
File renamed without changes.
19 changes: 19 additions & 0 deletions puzzles/kotlin/src/conway-sequence/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@


# Conway Sequence

This is the Kotlin implementation for the "Conway Sequence" puzzle on CodinGame.

## Problem Description

Conway's Sequence is a sequence of numbers, starting with a 1, such that each subsequent number is a description of the previous number.

To generate a member of Conway's Sequence from the previous member, read off the digits of the previous member, counting the number of digits in groups of the same digit. For example, 1 is read off as "one 1" or 11, 11 is read off as "two 1s" or 21, 21 is read off as "one 2, then one 1" or 1211, and so on.

Your task is to implement a function that generates the nth member of Conway's Sequence.

## Solution

The solution to this problem is to generate each member of the sequence, starting from 1, until we reach the nth member. To generate each member, we need to read off the digits of the previous member, counting the number of digits in groups of the same digit.

We can do this using two nested loops. The outer loop generates each member of the sequence, while the inner loop reads off the digits of the previous member and counts the number of digits in groups of the same digit.
File renamed without changes.
Loading

0 comments on commit 1d499bf

Please sign in to comment.