PROGRAMMING CHALLENGES
=====================

Generated on: 2025-06-08T08:43:48.583Z


=== a-phone-code ===
# a-phone-code

Created by [@theoludwig](https://github.com/theoludwig) on 13 May 2025.

## Instructions

Polycarpus has n friends in Tarasov city. Polycarpus knows phone numbers of all his friends: they are strings s1, s2, ..., sn. All these strings consist only of digits and have the same length.

Once Polycarpus needed to figure out Tarasov city phone code. He assumed that the phone code of the city is the longest common prefix of all phone numbers of his friends. In other words, it is the longest string c which is a prefix (the beginning) of each si for all i. Help Polycarpus determine the length of the city phone code.

### Input

The first line of the input contains an integer n — the number of Polycarpus's friends. The following n lines contain strings — the phone numbers of Polycarpus's friends. It is guaranteed that all strings consist only of digits and have the same length from 1 to 20, inclusive. It is also guaranteed that all strings are different.

### Output

Print the number of digits in the city phone code.

## Source

[Codeforces - A. Phone Code](https://codeforces.com/problemset/problem/172/A)

## Examples

See the `test` folder for examples of input/output.


=== acronyms ===
# acronyms

Created by [@theoludwig](https://github.com/theoludwig) on 30 June 2021.

## Instructions

Convert a given sentence to its acronym.

## Examples

### Example 1

### Input

```txt
Programming Challenges is really cool
```

### Output

```txt
PCIRC
```

#### Output

See the `test` folder for examples of input/output.


=== ascii-art ===
# ascii-art

Created by [@theoludwig](https://github.com/theoludwig) on 1 May 2022.

## Instructions

### Goal

In stations and airports you often see this type of screen:

![Led Display](./led_display.jpg)

Have you ever asked yourself how it might be possible to simulate this display on a good old terminal? We have: with ASCII art!

### Rules

ASCII art allows you to represent forms by using characters. To be precise, in our case, these forms are words. For example, the word "MANHATTAN" could be displayed as follows in ASCII art:

```txt
# #  #  ### # #  #  ### ###  #  ###
### # # # # # # # #  #   #  # # # #
### ### # # ### ###  #   #  ### # #
# # # # # # # # # #  #   #  # # # #
# # # # # # # # # #  #   #  # # # #
```

​Your mission is to write a program that can display a line of text in ASCII art in a style you are given as input.

### Input

- **Line 1:** The width `W` of a letter represented in ASCII art. All letters are the same width.
- **Line 2:** The height `H` of a letter represented in ASCII art. All letters are the same height.
- **Line 3:** The line of text `T`, composed of `N` ASCII characters.
- **Following lines:** the string of characters `ABCDEFGHIJKLMNOPQRSTUVWXYZ?` Represented in ASCII art.

### Output

The text `T` in ASCII art.

The characters a to z are shown in ASCII art by their equivalent in upper case.

The characters that are not in the intervals `[a-z]` or `[A-Z]` will be shown as a question mark in ASCII art.

### Constraints

- $$0 < W < 30$$
- $$0 < H < 30$$
- $$0 < N < 200$$

## Source

[CodinGame](https://www.codingame.com/training/easy/ascii-art)

## Examples

See the `test` folder for examples of input/output.


=== caesar-cipher ===
# caesar-cipher

Created by [@theoludwig](https://github.com/theoludwig) on 25 June 2021.

## Instructions

In cryptography, a Caesar cipher, also known as Caesar's cipher, the shift cipher, Caesar's code or Caesar shift, is one of the simplest and most widely known encryption techniques. It is a type of substitution cipher in which each letter in the plaintext is replaced by a letter some fixed number of positions down the alphabet. For example, with a left shift of -3, D would be replaced by A, E would become B, and so on. The method is named after Julius Caesar, who used it in his private correspondence.

### Example of the alphabet with a shift of +3 (shift to the right)

```text
Alphabet original   : ABCDEFGHIJKLMNOPQRSTUVWXYZ
Alphabet rotated +3 : DEFGHIJKLMNOPQRSTUVWXYZABC
```

Create a function that will return the sentence after shifting the alphabet.

- If it is a **positive** number then we shift the alphabet to the **right**
- If it is a **negative** number then we shift the alphabet to the **left**

### Example of Inputs

```py
'ANTHONY' # a character string (all capital letters)
'-2' # an integer, the shift in the alphabet
```

## Source

[Wikipedia - Caesar cipher](https://en.wikipedia.org/wiki/Caesar_cipher)

## Examples

See the `test` folder for examples of input/output.


=== cakes-swerc-2020-2021 ===
# cakes-swerc-2020-2021

Created by [@theoludwig](https://github.com/theoludwig) on 23 April 2022.

## Instructions

This summer, you plan to organize a large party and invite many
friends. They have a sweet tooth, so you plan to bake nice cakes for them.
You know the recipe for a nice chocolate cake, and you want to cook as
many of them as possible.

Given the `N` ingredients needed to make a single cake and the
ingredients that you have in your kitchen, how many cakes can you
make?

### Input

- **Line 1:** Single integer `N` for the number of ingredients.
- **`N` next lines:** One for each ingredient. Each of these lines contains two positive integers: the first one is the required quantity of this ingredient per cake, the second one is the quantity of this ingredient you have in your kitchen.

### Output

The output should contain a single integer: the maximum number of cakes you can make using the
available ingredients.

### Constraints

- $$1 \leq N \leq 10$$
- All ingredient quantities will be integers between 1 and 10 000.

## Source

[SWERC 2020-2021 - Problem E: Cake](https://swerc.eu/2020/problems/)

## Examples

See the `test` folder for examples of input/output.

### Example 1

#### Input

```txt
3
100 500
2 5
70 1000
```

#### Output

```txt
2
```

### Example 2

#### Input

```txt
3
100 50
2 5
70 1000
```

#### Output

```txt
0
```


=== camel-case ===
# camel-case

Created by [@theoludwig](https://github.com/theoludwig) on 5 July 2020.

## Instructions

Write a simple camelCase function for strings. All words (except the first) must have their first letter capitalized without spaces.

**Note:** camelCase is the practice of writing phrases such that each word in the middle of the phrase begins with a capital letter, with no intervening spaces or punctuation.

## Examples

See the `test` folder for examples of input/output.


=== consecutive-numbers ===
# consecutive-numbers

Created by [@theoludwig](https://github.com/theoludwig) on 28 June 2021.

## Instructions

Write a function which takes a list of integers, and which returns the list of of successive consecutive integers that there may be in the list.

First input, is the number of consecutive numbers needed to consider it as "consecutive", the second input is the list of integers.

## Examples

See the `test` folder for examples of input/output.

### Example 1

#### Input

```txt
2
5 ; 1 ; 2 ; 3 ; 8 ; -5 ; -4 ; 7
```

#### Output

```txt
1 ; 2
2 ; 3
-5 ; -4
```

### Example 2

#### Input

```txt
3
5 ; 1 ; 2 ; 3 ; 8 ; -5 ; -4 ; 7
```

#### Output

```txt
1 ; 2 ; 3
```


=== convert-number-from-base-to-another ===
# convert-number-from-base-to-another

Created by [@theoludwig](https://github.com/theoludwig) on 20 October 2021.

## Instructions

Convert a natural number (`number`) from a certain base (`base_from`) to another base (`base_target`).

For bases up to and including 10, we use the digits 0, 1, 2, 3, 4, 5, 6, 7, 8 and 9.

For bases between 11 and 36, we use the 10 digits then the letters (capitals). For example, for base 16, the symbols used are 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F. For base 36, we uses the symbols 0,1,2,3,4,5,6,7,8,9, A, B, C, D, E, F, G, H, I, J, K, L, M, N , O, P, Q, R, S, T, U, V, W, X, Y, Z.

### Input

- **Line 1:** The `number` to be converted (natural number)
- **Line 2:** The base of the number `base_from`
- **Line 3:** The base to convert to `base_target`

### Output

The converted number.

## Examples

### Example 1

#### Input

```txt
15
10
16
```

#### Output

```txt
F
```

### Example 2

#### Input

```txt
100000000
2
16
```

#### Output

```txt
100
```

See the `test` folder for examples of input/output.


=== defibrillators ===
# defibrillators

Created by [@theoludwig](https://github.com/theoludwig) on 28 June 2021.

## Instructions

### Goal

The city of Montpellier has equipped its streets with defibrillators to help save victims of cardiac arrests. The data corresponding to [the position of all defibrillators](http://data.montpellier3m.fr/dataset/d%C3%A9fibrillateurs-de-montpellier) is available online.

Based on the data we provide in the tests, write a program that will allow users to find the defibrillator nearest to their location using their mobile phone.

### Rules

The input data you require for your program is provided in text format.
This data is comprised of lines, each of which represents a defibrillator. Each defibrillator is represented by the following fields:

- A number identifying the defibrillator
- Name
- Address
- Contact Phone number
- Longitude (degrees)
- Latitude (degrees)

These fields are separated by a semicolon (`;`).

**Beware:** the decimal numbers use the comma (,) as decimal separator. Remember to turn the comma (,) into dot (.) if necessary in order to use the data in your program.

### Distance

The distance `d` between two points `A` and `B` will be calculated using the following formula:

![Distance Formula](./distance-formula.png)

**Note:** In this formula, the latitudes and longitudes are expressed in radians. 6371 corresponds to the radius of the earth in km.

The program will display the name of the defibrillator located the closest to the user’s position. This position is given as input to the program.

### Input

- **Line 1:** User's longitude (in degrees)
- **Line 2:** User's latitude (in degrees)
- **Line 3:** The number `N` of defibrillators located in the streets of Montpellier
- **`N` next lines:** a description of each defibrillator

### Output

The name of the defibrillator located the closest to the user’s position.

### Constraints

- $$0 < N < 10 000$$

## Source

[CodinGame](https://www.codingame.com/training/easy/defibrillators)

## Examples

See the `test` folder for examples of input/output.


=== fibonacci ===
# fibonacci

Created by [@theoludwig](https://github.com/theoludwig) on 5 July 2020.

## Instructions

The function should return an array of fibonacci numbers. The function takes a `number` as an argument to decide how many number of elements to produce.

**Note:** The Fibonacci Sequence is the series of numbers: 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, ... Each subsequent number is the sum of the previous two.

## Examples

See the `test` folder for examples of input/output.


=== find-closest-number ===
# find-closest-number

Created by [@theoludwig](https://github.com/theoludwig) on 1 May 2022.

## Instructions

Given an array of `n` integers, find the closest value to the given number (`given_number`).

## Input

- **Line 1:** An integer `given_number` for the number to find the closest value to
- **Line 2:** An integer `n` for the length of the list of integers
- **`n` next lines:** the integers

## Output

The closest value in the array to the given number.

## Examples

See the `test` folder for examples of input/output.

### Example 1

#### Input

```txt
3
6
1
2
3
4
5
6
```

#### Output

```txt
3
```

**Explanation:** The given number is `3` and `3` is in the array, so the closest value is `3`.

### Example 2

#### Input

```txt
0
14
7
-10
13
8
4
-7
-12
-3
3
-9
6
-1
-6
7
```

#### Output

```txt
-1
```


=== find-outlier-number ===
# find-outlier-number

Created by [@theoludwig](https://github.com/theoludwig) on 5 July 2020.

## Instructions

You are given an array (which will have a length of at least 3, but could be very large) containing integers. The array is either entirely comprised of odd integers or entirely comprised of even integers except for a single integer `N`. Write a function that takes the array as an argument and returns this "outlier" `N`.

## Examples

See the `test` folder for examples of input/output.


=== first-non-repeating-character ===
# first-non-repeating-character

Created by [@theoludwig](https://github.com/theoludwig) on 15 November 2020.

## Instructions

Write a function that takes a string input, and returns the first character that is not repeated anywhere in the string.

For example, if given the input `'stress'`, the function should return `'t'`, since the letter `'t'` only occurs once in the string, and occurs first in the string.

If a string contains all repeating characters, it should return an empty string (`""`).

## Source

[First non-repeating character - Codewars](https://www.codewars.com/kata/52bc74d4ac05d0945d00054e/)

## Examples

See the `test` folder for examples of input/output.


=== fizzbuzz ===
# fizzbuzz

Created by [@theoludwig](https://github.com/theoludwig) on 30 June 2021.

## Instructions

Write a program that print the numbers from 1 to `n` but:

- if number is divisible by 3, print `Fizz`
- if number is divisible by 5, print `Buzz`
- if number is divisible by both 3 and 5, print `FizzBuzz`
- otherwise print the number

## Examples

### Example 1

#### Input

```txt
5
```

#### Output

```txt
1
2
Fizz
4
Buzz
```

See the `test` folder for examples of input/output.


=== frequency-deviation ===
# frequency-deviation

Created by [@theoludwig](https://github.com/theoludwig) on 16 September 2023.

## Instructions

Given a string consisting of lowercase English letters, we define the frequency deviation of a substring as the difference between the maximum and the minimum frequencies of the characters in that substring.

A substring of a string is formed by any contiguous segment of the string. For example, given "bbacccc", the character appearing most frequently is 'c' with $4$ occurrences. The character that appears the fewest times is 'a' with $1$ occurrence. The frequency deviation of the entire string is $4 - 1 = 3$.

Given a string, $s$, representing the input string, find the maximum possible frequency deviation of any of its substrings.

### Constraints

- $$1 \leq s.length \leq 10^4$$
- $s$ consists of lowercase English letters.

## Source

- [LeetCode - Substring With Largest Variance](https://leetcode.com/problems/substring-with-largest-variance/)
- [Twitter @CoderNolimit](https://twitter.com/CoderNolimit/status/1668147202173050881)

## Examples

See the `test` folder for examples of input/output.

### Example 1

#### Input

```txt
bbacccc
```

#### Output

```txt
3
```

### Example 2

#### Input

```txt
aabb
```

#### Output

```txt
1
```

### Example 3

#### Input

```txt
aaaaa
```

#### Output

```txt
0
```


=== heap-algorithm ===
# heap-algorithm

Created by [@theoludwig](https://github.com/theoludwig) on 8 November 2021.

## Instructions

Write a program that generates all possible unique permutations of a string.

The order of the generated permutations is important, see the example below.

## Source

[Heap's Algorithm - Wikipedia](https://en.wikipedia.org/wiki/Heap%27s_algorithm)

## Examples

### Example 1

#### Input

```txt
abc
```

#### Output

```txt
abc
bac
cab
acb
bca
cba
```

See the `test` folder for examples of input/output.


=== hello-world ===
# hello-world

Created by [@theoludwig](https://github.com/theoludwig) on 6 June 2021.

## Instructions

Your function should return Hello depending of the parameter.

## Examples

See the `test` folder for examples of input/output.


=== is-palindrome ===
# is-palindrome

Created by [@theoludwig](https://github.com/theoludwig) on 5 July 2020.

## Instructions

The function should return `true` if a given string (case insensitive) is a palindrome and `false` if it's not the case.

**Note:** a **Palindrome** is a word, phrase, or sequence that reads the **same backwards as forwards**, e.g. Kayak.

## Examples

See the `test` folder for examples of input/output.


=== is-prime-number ===
# is-prime-number

Created by [@theoludwig](https://github.com/theoludwig) on 5 July 2020.

## Instructions

The function should return `true` if a given number is a prime number and `false` otherwise.

**Note :** A prime number is a natural integer which admits exactly two distinct positive divisors. (1 and itself). Example: 2, 3, 5, 7, 11, 13, 17, 19 ...

## Examples

See the `test` folder for examples of input/output.


=== is-valid-array-subsequence ===
# is-valid-array-subsequence

Created by [@theoludwig](https://github.com/theoludwig) on 23 April 2022.

## Instructions

Given two non-empty arrays of integers, write a function that determines whether the second array is a subsequence of the first one.

A subsequence of an array is a set of numbers that aren't necessarily adjacent in the array but that are in the same order as they appear in the array. For instance, the numbers `[1, 3, 4]` form a subsequence of the array `[1, 2, 3, 4]`, and so do the numbers `[2, 4]`. Note that a single number in an array and the array itself are both valid subsequences of the array.

### Input

- **Line 1:** `array` Integers separated by spaces
- **Line 2:** `sequence` Integers separated by spaces

### Output

The output should return `true` if the `sequence` is a subsequence of `array` and `false` otherwise.

## Examples

See the `test` folder for examples of input/output.

### Example 1

#### Input

```txt
5 1 22 25 6 -1 8 10
1 6 -1 10
```

#### Output

```txt
true
```

### Example 2

#### Input

```txt
5 1 22 25 6 -1 8 10
5 1 22 25 6 -1 8 10 12
```

#### Output

```txt
false
```


=== left-pad ===
# left-pad

Created by [@theoludwig](https://github.com/theoludwig) on 21 May 2023.

## Instructions

Create a function that pads the current string with another string (multiple times, if needed) until the resulting string reaches the given length. The padding is applied from the start (left) of the current string.

Inspired from [left-pad (JavaScript npm package)](https://www.npmjs.com/package/left-pad).

### Input

- **Line 1:** The current string
- **Line 2:** The length of the resulting string
- **Line 3:** The string to pad the current string with

## Examples

See the `test` folder for examples of input/output.

### Example 1

#### Input

```txt
foo
12
-
```

#### Output

```txt
---------foo
```


=== look-and-say-sequence-conway ===
# look-and-say-sequence-conway

Created by [@theoludwig](https://github.com/theoludwig) on 30 November 2021.

## Instructions

In mathematics, the **look-and-say sequence** is the sequence of integers beginning as follows: `1, 11, 21, 1211, 111221, 312211, 13112221, 1113213211, ...`.

The look-and-say sequence was introduced and analyzed by John **Conway**.

To generate a member of the 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.
- `1211` is read off as "one 1, one 2, then two 1s" or 111221.
- `111221` is read off as "three 1s, two 2s, then one 1" or 312211.

Write a program that prints the next term of the **look-and-say sequence**.

## Source

[Look-and-say sequence - Wikipedia](https://en.wikipedia.org/wiki/Look-and-say_sequence)

## Examples

### Example 1

#### Input

```txt
11
```

#### Output

```txt
21
```

### Example 2

#### Input

```txt
1211
```

#### Output

```txt
111221
```

See the `test` folder for examples of input/output.


=== maximum-subarray-sum ===
# maximum-subarray-sum

Created by [@theoludwig](https://github.com/theoludwig) on 1 May 2022.

## Instructions

Given an array of `n` integers, find the contiguous subarray with the largest sum.

Contiguous subarray is any sub series of elements in a given array that are contiguous ie their indices are continuous. The problem is interesting when there may be negative values in the array, because if the array only contains positive values, the maximum subarray sum is basically the sum of the array (the subarray being the complete array).

## Input

- **Line 1:** An integer `n` for the length of the list of integers
- **`n` next lines:** the integers

## Output

The largest sum of a contiguous subarray.

## Examples

See the `test` folder for examples of input/output.

### Example 1

#### Input

```txt
6
1
2
3
4
5
6
```

#### Output

```txt
21
```

**Explanation:** The subarray with the largest sum is the array itself (as there is no negative values) `[1, 2, 3, 4, 5, 6]` which has a sum of `21`.

### Example 2

#### Input

```txt
8
-1
2
4
-3
5
2
-5
2
```

#### Output

```txt
10
```

**Explanation:** The subarray with the largest sum is `[2, 4, -3, 5, 2]` which has a sum of `10`.


=== offset-arrays ===
# offset-arrays

Created by [@theoludwig](https://github.com/theoludwig) on 29 June 2021.

## Instructions

### Goal

To settle the debate of 0-based vs 1-based indexing I have created a language where you must explicitly state the range of indices an array should have.

For example, given an array definition "A[-1..1] = 1 2 3", you would have:

- A[-1] = 1
- A[0] = 2
- A[1] = 3

You are given a list of `n` array definitions and your job is to figure out what number is found in a given index `i` of an array `arr`. Note that the indexing operations may be nested (in the above example, A[A[-1]] would produce result 3).

### Input

- **Line 1:** An integer `n` for the number of array assignments
- **`n` next lines:** One array assignment per line: `array_identifier` [ `first_index` .. `last_index` ] = `last_index - first_index + 1` integers separated by space
- **Line `n+2`:** Element to print: `arr` [ `i` ]

### Constraints

- $$1 \leq n \leq 100$$
- Array names consist only of uppercase letters A to Z.
- Array lengths are between 1 and 100 (no empty arrays).
- Indexing operations have at most 50 levels of nesting.
- Indices are always within bounds in the test cases.

## Source

[CodinGame](https://www.codingame.com/ide/puzzle/offset-arrays)

## Examples

See the `test` folder for examples of input/output.

### Example 1

#### Input

```txt
3
A[-1..1] = 1 2 3
B[3..7] = 3 4 5 6 7
C[-2..1] = 1 2 3 4
A[0]
```

#### Output

```txt
2
```


=== prefix-suffix ===
# prefix-suffix

Created by [@theoludwig](https://github.com/theoludwig) on 2 December 2021.

## Instructions

A prefix is an affix which is placed before the stem of a word. Adding it to the beginning of one word changes it into another word. For example, when the prefix un- is added to the word happy, it creates the word unhappy.

A suffix is an affix which is placed after the stem of a word. Common examples are case endings, which indicate the grammatical case of nouns, adjectives, and verb endings, which form the conjugation of verbs. Suffixes can carry grammatical information or lexical information.

Write a programs that takes 2 strings ("words") and prints if one is a prefix/suffix of the other.

### Input

- **Line 1:** The word to be checked
- **Line 2:** The potential prefix/suffix

### Output

- **Line 1:** `true` if the second word is a **prefix** of the first, `false` otherwise
- **Line 1:** `true` if the second word is a **suffix** of the first, `false` otherwise

## Sources

- [Wikipedia - Prefix](https://en.wikipedia.org/wiki/Prefix)
- [Wikipedia - Suffix](https://en.wikipedia.org/wiki/Suffix)

## Examples

### Example 1

#### Input

```txt
Py
AlgoPy
```

#### Output

```txt
false
false
```

### Example 2

#### Input

```txt
AlgoPy
Py
```

#### Output

```txt
false
true
```

### Example 3

#### Input

```txt
same-word
same-word
```

#### Output

```txt
true
true
```

See the `test` folder for examples of input/output.


=== prime-numbers-decomposition ===
# prime-numbers-decomposition

Created by [@theoludwig](https://github.com/theoludwig) on 16 October 2021.

## Instructions

## Definition

In mathematics, product decomposition of prime factors (also known as integer factorization into prime numbers) involves writing a strictly positive integer as a product of prime numbers.

This factorization is unique and exists for all numbers and has many applications, particularly in RSA cryptography.

**Note :** A prime number is a natural integer which admits exactly two distinct positive divisors. (1 and itself). Example: 2, 3, 5, 7, 11, 13, 17, 19...

## How to decompose a number into a product of factors of prime numbers?

To find the product decomposition of prime factors of a number `N`, there is no mathematical formula. To achieve this, there are algorithms, the most basic of which attempts to divide the number `N` by the set of prime factors `p` which are less than `N`.
If `p` is a divisor of `N` then start again by taking a new `N = N / p` as long as there are possible prime divisors.

## Examples

### Example

#### Input

```txt
32
```

#### Output

```txt
2 * 2 * 2 * 2 * 2
```

See the `test` folder for examples of input/output.


=== print-pyramid ===
# print-pyramid

Created by [@theoludwig](https://github.com/theoludwig) on 21 September 2021.

## Instructions

Display a pyramid of stars (`*`) whose height is given and in the right order (`normal` or `reverse`).

### Input

- **Line 1:** The string : `normal` or `reverse` to determine how to show the pyramid.
- **Line 2:** The integer : height of the pyramid.

## Examples

See the `test` folder for examples of input/output.


=== reverse-polish-notation ===
# reverse-polish-notation

Created by [@theoludwig](https://github.com/theoludwig) on 29 September 2020.

## Instructions

Your job is to create a calculator which evaluates expressions in Reverse Polish notation (a mathematical notation in which operators follow their operands. It does not need any parentheses as long as each operator has a fixed number of operands).

For example expression 5 3 + (which is equivalent to 5 + 3 in normal notation) should evaluate to 8.

For your convenience, the input is formatted such that a space is provided between every token.

Empty expression should evaluate to 0.

Valid operations are +, -, \*, /.

You may assume that there won't be exceptional situations (like stack underflow or division by zero).

All the numbers are integers; you don't need to worry about floating point numbers.

## Source

[Reverse polish notation - Codewars](https://www.codewars.com/kata/52f78966747862fc9a0009ae)

## Examples

See the `test` folder for examples of input/output.


=== roman-numerals ===
# roman-numerals

Created by [@theoludwig](https://github.com/theoludwig) on 30 June 2021.

## Instructions

The objective of this challenge is to create a function that translates a number into Roman numerals or the other way around.

We will use the letters `I`, `V`, `X`, `L`, `C`, `D`, `M` to build the Roman numerals.

Here are the rules for building a Roman numeral:

- The numbers `1`, `2` and `3` are written respectively as `I`, `II` and `III`
- The number `5` is written as `V`
- The number `10` is written as `X`
- The number `50` is written as `L`
- The number `100` is written as `C`
- The number `500` is written as `D`
- The number `1000` is written as `M`
- When writing two letters in a row, if the numerical value of the first is greater than the numerical value of the second, their numerical values ​​are added. For example the number `6` is written `VI`. We add `V` (5) + `I` (1) = 6.
- When writing two letters in a row, if the numerical value of the first is less than the numerical value of the second, the value of the first is subtracted from the second. For example the number `4` is written `IV`. We subtract `V` (5) - `I` (1) = 4.
- Subtractions of values ​​are limited to 2 letters only. For example we **cannot** write `8` while doing `IIX`. We must use the addition of letters like this `VIII`.
- Therefore, the first ten numbers are written as `I`, `II`, `III`, `IV`, `V`, `VI`, `VII`, `VIII`, `IX`, `X` . Larger numbers follow the same pattern.
- You can associate as many symbols as you want to write larger numbers, for example:
    - `36` is written as `XXXVI`
    - `42` is written as `XLII`
    - `2448` is written as `MMCDXLVIII`.

| Symbol | I   | V   | X   | L   | C   | D   | M    |
| ------ | --- | --- | --- | --- | --- | --- | ---- |
| Value  | 1   | 5   | 10  | 50  | 100 | 500 | 1000 |

### Input

- **Line 1:** The string : `arabic to roman` or `roman to arabic` to determine how to convert the number
- **Line 2:** The number to convert

## Sources

- [Wikipedia - Roman numerals](https://en.wikipedia.org/wiki/Roman_numerals)
- [Wikipedia - Arabic numerals](https://en.wikipedia.org/wiki/Arabic_numerals)

## Examples

See the `test` folder for examples of input/output.


=== rotate-2-dimensional-array-90-degrees ===
# rotate-2-dimensional-array-90-degrees

Created by [@theoludwig](https://github.com/theoludwig) on 3 December 2021.

## Instructions

Given a square/rectangle matrix representing an image and a direction of rotation (`clockwise` or `anticlockwise`), rotate the image by 90 degrees.

### Input

- **Line 1:** The direction (`clockwise` or `anticlockwise`) of rotation
- **Next Lines:** The matrix of the image

### Output

- **Lines:** The rotated matrix

## Examples

### Example 1

#### Input

```txt
clockwise
1 2 3
4 5 6
7 8 9
```

#### Output

```txt
7 4 1
8 5 2
9 6 3
```

### Example 2

#### Input

```txt
anticlockwise
1 2 3
4 5 6
7 8 9
```

#### Output

```txt
1 4 7
2 5 8
3 6 9
```

See the `test` folder for examples of input/output.


=== single-number ===
# single-number

Created by [@theoludwig](https://github.com/theoludwig) on 21 August 2023.

## Instructions

Given a **non-empty** array of integers, every element appears twice except for one. Find that single one.

You must implement a solution with a linear runtime complexity and use only constant extra space.

### Constraints

- $$1 \leq numbers.length \leq 3 \times 10^4$$
- $$-3 \times 10^4 \leq numbers[index] \leq 3 \times 10^4$$
- Each element in the array appears twice except for one element which appears only once.

## Source

[LeetCode - Single Number](https://leetcode.com/problems/single-number/)

## Examples

See the `test` folder for examples of input/output.

### Example 1

#### Input

```txt
4
1
2
1
2
```

#### Output

```txt
4
```


=== slugify ===
# slugify

Created by [@theoludwig](https://github.com/theoludwig) on 10 November 2021.

## Instructions

Write a function that generates a slug from a string.

A Slug is the unique identifying part of a web address, typically at the end of the URL.

The rules for generating a slug are as follows (`kebab-case`):

- Replace spaces with hyphens.
- Remove all non-alphanumeric characters.

## Examples

### Example 1

#### Input

```txt
hello world
```

#### Output

```txt
hello-world
```

### Example 2

#### Input

```txt
--hello world--
```

### Output

```txt
hello-world
```

### Example 3

#### Input

```txt
😄 emoji
```

### Output

```txt
emoji
```

See the `test` folder for examples of input/output.


=== sorting-algorithms ===
# sorting-algorithms

Created by [@theoludwig](https://github.com/theoludwig) on 29 June 2021.

## Instructions

In computer science, a sorting algorithm is an algorithm that puts elements of a list in a certain order.
We will use the [numerical order](https://en.wikipedia.org/wiki/Numerical_order).

Write a function that takes a list of integers and sort them in ascending order.

## Input

- **Line 1:** An integer $n$ for the length of the list of integers
- **$n$ next lines:** the numbers to sort

### Constraints

- $$n \leq 25 000$$

## Source

[Wikipedia - Sorting algorithm](https://en.wikipedia.org/wiki/Sorting_algorithm)

## Examples

See the `test` folder for examples of input/output.


=== sudoku ===
# sudoku

Created by [@theoludwig](https://github.com/theoludwig) on 6 July 2021.

## Instructions

Sudoku is a logic-based, combinatorial number-placement puzzle.

The objective is to fill a 9×9 grid with digits so that each column, each row, and each of the nine 3×3 subgrids that compose the grid (also called "boxes", "blocks", or "regions") contains all of the digits from 1 to 9. The puzzle setter provides a partially completed grid, which for a well-posed puzzle has a single solution.

You can't use the same numbers twice in a:

- row
- column
- square of 3x3

Write a program that solves the Sudoku given in input.

The empty cells are represented by 0.

## Source

[Wikipedia - Sudoku](https://en.wikipedia.org/wiki/Sudoku)

## Examples

See the `test` folder for examples of input/output.

### Example 1

#### Input

```txt
5 3 0 0 7 0 0 0 0
6 0 0 1 9 5 0 0 0
0 9 8 0 0 0 0 6 0
8 0 0 0 6 0 0 0 3
4 0 0 8 0 3 0 0 1
7 0 0 0 2 0 0 0 6
0 6 0 0 0 0 2 8 0
0 0 0 4 1 9 0 0 5
0 0 0 0 8 0 0 7 9
```

#### Output

```txt
5 3 4 6 7 8 9 1 2
6 7 2 1 9 5 3 4 8
1 9 8 3 4 2 5 6 7
8 5 9 7 6 1 4 2 3
4 2 6 8 5 3 7 9 1
7 1 3 9 2 4 8 5 6
9 6 1 5 3 7 2 8 4
2 8 7 4 1 9 6 3 5
3 4 5 2 8 6 1 7 9
```


=== triangle-type ===
# triangle-type

Created by [@theoludwig](https://github.com/theoludwig) on 30 June 2021.

## Instructions

Given the lengths of the 3 sides of a triangle, your function should return whether it is `equilateral`, `isosceles`, `scalene` or `impossible`.

- A triangle is `equilateral` when its 3 sides are equal
- A triangle is `isosceles` when 2 of its sides are equal
- A triangle is `scalene` when none of its sides is equal to another side
- A triangle is `impossible` when the sum of two of its sides is strictly less than the third side

## Input

- **Line 1 to 3:** The length of each side of the triangle

## Examples

See the `test` folder for examples of input/output.


=== valid-parentheses ===
# valid-parentheses

Created by [@theoludwig](https://github.com/theoludwig) on 18 November 2024.

## Instructions

Given a string containing just the characters `'('`, `')'`, `'{'`, `'}'`, `'['` and `']'`, determine if the input string is valid.

An input string is valid if:

- Open brackets must be closed by the same type of brackets.
- Open brackets must be closed in the correct order.
- Every close bracket has a corresponding open bracket of the same type.

## Source

[LeetCode - Valid Parentheses](https://leetcode.com/problems/valid-parentheses)

## Examples

See the `test` folder for examples of input/output.

### Example 1

#### Input

```txt
()
```

#### Output

```txt
true
```

### Example 2

#### Input

```txt
(]
```

#### Output

```txt
false
```

