Skip to content

Commit

Permalink
Easy & Medium Puzzles - Review
Browse files Browse the repository at this point in the history
  • Loading branch information
charlesfranciscodev committed May 12, 2023
1 parent 1d499bf commit d8935de
Show file tree
Hide file tree
Showing 92 changed files with 2,447 additions and 274 deletions.
44 changes: 22 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,46 +13,46 @@ It's worth noting that CodinGame is a website that provides programming challeng
### Easy Puzzles
| Title | Solution(s) | Topic(s) |
| :---: | :------: | :------: |
| 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 |
| 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), [Swift](./puzzles/swift/the-descent), [Bash](./puzzles/bash/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), [C++](./puzzles/cpp/temperatures.cpp), [Swift](./puzzles/swift/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 |
| 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), [TypeScript](./puzzles/ts/horse-racing-duals), [Ruby](./puzzles/ruby/horse-racing-duals) ★, [Bash](./puzzles/bash/horse-racing-duals) | Arrays, Sorting |

### Medium Puzzles
| Title | Solution(s) | Topic(s) |
| :---: | :------: | :------: |
| 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), [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 |
| Don't Panic 1 🕶️ | [Python](./puzzles/python3/dont-panic1) ★, [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) ★ | Conditions, Loops |
| The Fall 1 💎 | [Python](./puzzles/python3/the-fall1), [JavaScript](./puzzles/js/the-fall1) ★ | 2D Arrays |
| Network Cabling 🔌 | [Python](./puzzles/python3/network-cabling) ★ | Sorting, Median |
| Conway Sequence 👀 | [Python](./puzzles/python3/conway-sequence), [Kotlin](./puzzles/kotlin/src/conway-sequence), [Haskell](./puzzles/haskell/conway-sequence) ★ | Sequences |
| Telephone Numbers 📱 | [Python](./puzzles/python3/telephone-numbers) ★ | Tries |
| Dwarfs standing on giants 🏞️ | [Python](./puzzles/python3/dwarfs-giants) ★, [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), [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 |
| Mayan Calculation 2️⃣0️⃣ | [Python](./puzzles/python3/mayan-calc), [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) | Graphs |
| The Labyrinth 🌟 | [Python](./puzzles/python3/the-labyrinth) ★ | 2D Arrays, Graphs, BFS |
| 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) | 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) | 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 3 ⌛ | [Python](./puzzles/python3/blunder3.py) ★ | Time Complexity |
62 changes: 62 additions & 0 deletions community-puzzles/1d-spreadsheet/1d-spreadsheet.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
VALUE_TYPE = "VALUE"
REFERENCE_TYPE = "REFERENCE"
EMPTY_TYPE = "EMPTY"

VALUE_PATTERN = /^-?[0-9]+$/
REFERENCE_PATTERN = /^\$[0-9]+$/

def get_arg_type(arg)
return VALUE_TYPE if VALUE_PATTERN.match(arg)
return REFERENCE_TYPE if REFERENCE_PATTERN.match(arg)

return EMPTY_TYPE
end

def value(arg_type, arg, formulas, values)
if arg_type == REFERENCE_TYPE
index = arg[1..-1].to_i
parse_formula(index, formulas, values) unless values.key?(index)
return values[index]
end
return arg.to_i
end

def parse_formula(i, formulas, values)
formula = formulas[i]
operation, arg1, arg2 = formula.split
arg_type1 = get_arg_type(arg1)
arg_type2 = get_arg_type(arg2)

if operation == "VALUE"
values[i] = value(arg_type1, arg1, formulas, values)
else
value1 = value(arg_type1, arg1, formulas, values)
value2 = value(arg_type2, arg2, formulas, values)
if operation == "ADD"
values[i] = value1 + value2
elsif operation == "SUB"
values[i] = value1 - value2
else
values[i] = value1 * value2
end
end
end

formulas = []
values = {}

# read input formulas
nb_cells = gets.to_i
nb_cells.times do
formulas << gets.chomp
end

# parse formulas
nb_cells.times do |i|
parse_formula(i, formulas, values)
end

# output values
nb_cells.times do |i|
puts values[i]
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
def print_tree(tree):
output = ""
if not tree:
return
i = 0
while i < len(tree) - 1:
output += tree[i] + " > "
i += 1
output += tree[i]
print(output)


nb_people = int(input())
tree = [] # partial family tree

for _ in range(nb_people):
line = input().strip()
name = line.replace(".", "").rstrip()
name_level = len(line) - len(name)
tree_level = len(tree)

if name_level == 0:
if tree:
print_tree(tree)
tree.clear()
elif name_level < tree_level:
print_tree(tree)
while name_level < len(tree):
tree.pop()

tree.append(name)

print_tree(tree)
19 changes: 0 additions & 19 deletions community-puzzles/micro-assembly/.gitignore

This file was deleted.

135 changes: 135 additions & 0 deletions community-puzzles/micro-assembly/micro-assembly.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
using System;

class Solution
{
static int[] registers;
static string[] instructions;
static int curLine = 0;
const string names = "abcd";

static void Main(string[] args)
{
const int NB_REGISTERS = 4;
var inStr = Console.ReadLine();
var inArr = inStr.Split(' ');
registers = new int[NB_REGISTERS];
for (int i = 0; i < NB_REGISTERS; ++i)
registers[i] = int.Parse(inArr[i]);

int nbLines = int.Parse(Console.ReadLine());
instructions = new string[nbLines];
for (int i = 0; i < nbLines; ++i)
instructions[i] = Console.ReadLine();

do
{
string line = instructions[curLine];
interpret(line);
Console.Error.WriteLine(curLine + " " + line);
// printRegisters();
} while (curLine != nbLines);

string output = "";
foreach (int register in registers)
output += register.ToString() + " ";

Console.WriteLine(output.Trim());
}

static void interpret(string line)
{
string[] instruction = line.Split(' ');
switch (instruction[0])
{
case "MOV": move(instruction); ++curLine; break;
case "ADD": add(instruction); ++curLine; break;
case "SUB": sub(instruction); ++curLine; break;
case "JNE": jumpNotEqual(instruction); break;
}
}

static void move(string[] instruction)
{
int dest = index(instruction[1]);
string value = instruction[2];
if (names.Contains(value))
{
int source = index(value);
registers[dest] = registers[source];
}
else
{
registers[dest] = int.Parse(value);
}
}

static void operation(string[] instruction, int sign)
{
int result;

int dest = index(instruction[1]);
string value = instruction[2];
if (names.Contains(value))
{
int source = index(value);
result = registers[source];
}
else
{
result = int.Parse(value);
}

value = instruction[3];
if (names.Contains(value))
{
int source = index(value);
result += sign * registers[source];
}
else
{
result += sign * int.Parse(value);
}

registers[dest] = result;
}

static void add(string[] instruction)
{
operation(instruction, 1);
}

static void sub(string[] instruction)
{
operation(instruction, -1);
}

static void jumpNotEqual(string[] instruction)
{
int operand1 = registers[index(instruction[2])];
int operand2;
string value2 = instruction[3];
if (names.Contains(value2))
operand2 = registers[index(value2)];
else
operand2 = int.Parse(value2);

if (operand1 != operand2)
curLine = int.Parse(instruction[1]);
else
++curLine;
}

static int index(string register)
{
return char.ToLower(register[0]) - 'a';
}

static void printRegisters()
{
string output = "";
foreach (int register in registers)
output += register.ToString() + " ";

Console.Error.WriteLine(output.Trim());
}
}
Loading

0 comments on commit d8935de

Please sign in to comment.