1
0
mirror of https://github.com/theoludwig/programming-challenges.git synced 2025-12-11 00:21:24 +01:00

chore: better Prettier config for easier reviews

This commit is contained in:
2023-10-23 23:16:24 +02:00
parent d7d5f9a5ac
commit 1e2736b8aa
70 changed files with 1476 additions and 1382 deletions
+2 -2
View File
@@ -17,8 +17,8 @@ make?
- **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.
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
@@ -1,20 +1,20 @@
import readline from 'node:readline'
import readline from "node:readline"
const input = []
const readlineInterface = readline.createInterface({
input: process.stdin,
output: process.stdout
output: process.stdout,
})
readlineInterface.on('line', (value) => {
readlineInterface.on("line", (value) => {
input.push(value)
})
readlineInterface.on('close', solution)
readlineInterface.on("close", solution)
function solution() {
const string = input[0]
const output = string
.trim()
.split(' ')
.split(" ")
.map((word, index) => {
const isFirstElement = index === 0
if (isFirstElement) {
@@ -22,6 +22,6 @@ function solution() {
}
return word[0].toUpperCase() + word.slice(1)
})
.join('')
.join("")
console.log(output)
}
+1 -1
View File
@@ -21,7 +21,7 @@ This data is comprised of lines, each of which represents a defibrillator. Each
- Contact Phone number
- Longitude (degrees)
- Latitude (degrees)
These fields are separated by a semicolon (`;`).
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.
@@ -1,14 +1,14 @@
import readline from 'node:readline'
import readline from "node:readline"
const input = []
const readlineInterface = readline.createInterface({
input: process.stdin,
output: process.stdout
output: process.stdout,
})
readlineInterface.on('line', (value) => {
readlineInterface.on("line", (value) => {
input.push(value)
})
readlineInterface.on('close', solution)
readlineInterface.on("close", solution)
const firstNonRepeatingCharacter = (string) => {
const lettersCount = {}
@@ -18,7 +18,7 @@ const firstNonRepeatingCharacter = (string) => {
lettersCount[character] = {
total: 1,
firstIndex: index,
value: character
value: character,
}
} else {
lettersCount[character].total += 1
@@ -36,7 +36,7 @@ const firstNonRepeatingCharacter = (string) => {
}
}
if (result == null) {
return ''
return ""
}
return result.value
}
@@ -7,7 +7,7 @@ export const getMaximumFrequencyDeviation = (string) => {
/** @type {string[]} */
const subStrings = []
for (let index = 0; index < string.length; index++) {
let subString = ''
let subString = ""
for (let subIndex = index; subIndex < string.length; subIndex++) {
subString += string[subIndex]
subStrings.push(subString)
@@ -1,13 +1,13 @@
import readline from 'node:readline'
import readline from "node:readline"
import { getMaximumFrequencyDeviation } from './getMaximumFrequencyDeviation.js'
import { getMaximumFrequencyDeviation } from "./getMaximumFrequencyDeviation.js"
const input = []
const readlineInterface = readline.createInterface({
input: process.stdin,
output: process.stdout
output: process.stdout,
})
readlineInterface.on('line', (value) => {
readlineInterface.on("line", (value) => {
input.push(value)
})
@@ -15,4 +15,4 @@ const solution = () => {
console.log(getMaximumFrequencyDeviation(input[0]))
}
readlineInterface.on('close', solution)
readlineInterface.on("close", solution)
@@ -1,14 +1,14 @@
import readline from 'node:readline'
import readline from "node:readline"
const input = []
const readlineInterface = readline.createInterface({
input: process.stdin,
output: process.stdout
output: process.stdout,
})
readlineInterface.on('line', (value) => {
readlineInterface.on("line", (value) => {
input.push(value)
})
readlineInterface.on('close', solution)
readlineInterface.on("close", solution)
function solution() {
console.log(`Hello, ${input[0]}!`)
@@ -1,14 +1,14 @@
import readline from 'node:readline'
import readline from "node:readline"
const input: string[] = []
const readlineInterface = readline.createInterface({
input: process.stdin,
output: process.stdout
output: process.stdout,
})
readlineInterface.on('line', (value) => {
readlineInterface.on("line", (value) => {
input.push(value)
})
readlineInterface.on('close', solution)
readlineInterface.on("close", solution)
function solution(): void {
console.log(`Hello, ${input[0]}!`)
@@ -1,17 +1,17 @@
import readline from 'node:readline'
import readline from "node:readline"
const input = []
const readlineInterface = readline.createInterface({
input: process.stdin,
output: process.stdout
output: process.stdout,
})
readlineInterface.on('line', (value) => {
readlineInterface.on("line", (value) => {
input.push(value)
})
readlineInterface.on('close', solution)
readlineInterface.on("close", solution)
function solution() {
const string = input[0].replace(/ /g, '').toLowerCase()
const isPalindrome = string.split('').reverse().join('') === string
const string = input[0].replace(/ /g, "").toLowerCase()
const isPalindrome = string.split("").reverse().join("") === string
console.log(isPalindrome)
}
@@ -1,4 +1,4 @@
import readline from 'node:readline'
import readline from "node:readline"
/**
*
@@ -12,7 +12,7 @@ const leftPad = (string, resultLength, padString) => {
if (resultLength <= 0) {
return string
}
let pad = ''
let pad = ""
while (resultLength !== 0) {
if (resultLength & 1) {
pad += padString
@@ -32,9 +32,9 @@ const solution = () => {
const input = []
const readlineInterface = readline.createInterface({
input: process.stdin,
output: process.stdout
output: process.stdout,
})
readlineInterface.on('line', (value) => {
readlineInterface.on("line", (value) => {
input.push(value)
})
readlineInterface.on('close', solution)
readlineInterface.on("close", solution)
@@ -1,23 +1,23 @@
import readline from 'node:readline'
import readline from "node:readline"
const input = []
const readlineInterface = readline.createInterface({
input: process.stdin,
output: process.stdout
output: process.stdout,
})
readlineInterface.on('line', (value) => {
readlineInterface.on("line", (value) => {
input.push(value)
})
readlineInterface.on('close', solution)
readlineInterface.on("close", solution)
const operations = {
'+': (number1, number2) => number1 + number2,
'-': (number1, number2) => number1 - number2,
'*': (number1, number2) => number1 * number2,
'/': (number1, number2) => number1 / number2
"+": (number1, number2) => number1 + number2,
"-": (number1, number2) => number1 - number2,
"*": (number1, number2) => number1 * number2,
"/": (number1, number2) => number1 / number2,
}
function solution () {
function solution() {
console.log(reversePolishNotation(input[0]))
}
@@ -26,7 +26,7 @@ function reversePolishNotation(value) {
return 0
}
const stack = []
const values = value.split(' ')
const values = value.split(" ")
values.forEach((value) => {
const number = Number(value)
if (!isNaN(number)) {
+3 -3
View File
@@ -26,9 +26,9 @@ Here are the rules for building a Roman numeral:
- `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 |
| Symbol | I | V | X | L | C | D | M |
| ------ | --- | --- | --- | --- | --- | --- | ---- |
| Value | 1 | 5 | 10 | 50 | 100 | 500 | 1000 |
### Input
@@ -2,6 +2,6 @@
Created by [@theoludwig](https://github.com/theoludwig) on 29 June 2021.
| Algorithm | Best Case | Average Case | Worst Case |
| ----------------------------------------------------------- | ----------- | ------------ | ----------- |
| [Bubble sort](https://wikipedia.org/wiki/Bubble_sort) | O(n) | O(n²) | O(n²) |
| Algorithm | Best Case | Average Case | Worst Case |
| ----------------------------------------------------- | --------- | ------------ | ---------- |
| [Bubble sort](https://wikipedia.org/wiki/Bubble_sort) | O(n) | O(n²) | O(n²) |
@@ -2,6 +2,6 @@
Created by [@theoludwig](https://github.com/theoludwig) on 29 June 2021.
| Algorithm | Best Case | Average Case | Worst Case |
| ----------------------------------------------------------- | ----------- | ------------ | ----------- |
| [Insertion sort](https://wikipedia.org/wiki/Insertion_sort) | O(n) | O(n²) | O(n²) |
| Algorithm | Best Case | Average Case | Worst Case |
| ----------------------------------------------------------- | --------- | ------------ | ---------- |
| [Insertion sort](https://wikipedia.org/wiki/Insertion_sort) | O(n) | O(n²) | O(n²) |
@@ -2,6 +2,6 @@
Created by [@theoludwig](https://github.com/theoludwig) on 29 June 2021.
| Algorithm | Best Case | Average Case | Worst Case |
| ----------------------------------------------------------- | ----------- | ------------ | ----------- |
| [Merge sort](https://wikipedia.org/wiki/Merge_sort) | O(n log(n)) | O(n log(n)) | O(n log(n)) |
| Algorithm | Best Case | Average Case | Worst Case |
| --------------------------------------------------- | ----------- | ------------ | ----------- |
| [Merge sort](https://wikipedia.org/wiki/Merge_sort) | O(n log(n)) | O(n log(n)) | O(n log(n)) |
@@ -2,6 +2,6 @@
Created by [@theoludwig](https://github.com/theoludwig) on 29 June 2021.
| Algorithm | Best Case | Average Case | Worst Case |
| ----------------------------------------------------------- | ----------- | ------------ | ----------- |
| [Bubble sort](https://wikipedia.org/wiki/Bubble_sort) | O(n) | O(n²) | O(n²) |
| Algorithm | Best Case | Average Case | Worst Case |
| ----------------------------------------------------- | --------- | ------------ | ---------- |
| [Bubble sort](https://wikipedia.org/wiki/Bubble_sort) | O(n) | O(n²) | O(n²) |
@@ -2,6 +2,6 @@
Created by [@theoludwig](https://github.com/theoludwig) on 29 June 2021.
| Algorithm | Best Case | Average Case | Worst Case |
| ----------------------------------------------------------- | ----------- | ------------ | ----------- |
| [Insertion sort](https://wikipedia.org/wiki/Insertion_sort) | O(n) | O(n²) | O(n²) |
| Algorithm | Best Case | Average Case | Worst Case |
| ----------------------------------------------------------- | --------- | ------------ | ---------- |
| [Insertion sort](https://wikipedia.org/wiki/Insertion_sort) | O(n) | O(n²) | O(n²) |
@@ -2,6 +2,6 @@
Created by [@theoludwig](https://github.com/theoludwig) on 29 June 2021.
| Algorithm | Best Case | Average Case | Worst Case |
| ----------------------------------------------------------- | ----------- | ------------ | ----------- |
| [Merge sort](https://wikipedia.org/wiki/Merge_sort) | O(n log(n)) | O(n log(n)) | O(n log(n)) |
| Algorithm | Best Case | Average Case | Worst Case |
| --------------------------------------------------- | ----------- | ------------ | ----------- |
| [Merge sort](https://wikipedia.org/wiki/Merge_sort) | O(n log(n)) | O(n log(n)) | O(n log(n)) |
@@ -2,6 +2,6 @@
Created by [@theoludwig](https://github.com/theoludwig) on 29 June 2021.
| Algorithm | Best Case | Average Case | Worst Case |
| ----------------------------------------------------------- | ----------- | ------------ | ----------- |
| [Bubble sort](https://wikipedia.org/wiki/Bubble_sort) | O(n) | O(n²) | O(n²) |
| Algorithm | Best Case | Average Case | Worst Case |
| ----------------------------------------------------- | --------- | ------------ | ---------- |
| [Bubble sort](https://wikipedia.org/wiki/Bubble_sort) | O(n) | O(n²) | O(n²) |
@@ -1,14 +1,14 @@
import readline from 'node:readline'
import readline from "node:readline"
const numbers = []
const readlineInterface = readline.createInterface({
input: process.stdin,
output: process.stdout
output: process.stdout,
})
readlineInterface.on('line', (value) => {
readlineInterface.on("line", (value) => {
numbers.push(Number(value))
})
readlineInterface.on('close', solution)
readlineInterface.on("close", solution)
function solution() {
const sortedNumbers = bubbleSort(numbers.slice(1))
@@ -17,7 +17,7 @@ function solution() {
})
}
function bubbleSort (numbersInput) {
function bubbleSort(numbersInput) {
const numbers = [...numbersInput]
for (let index1 = 0; index1 < numbers.length; index1++) {
for (let index2 = 0; index2 < numbers.length - index1 - 1; index2++) {
@@ -1,14 +1,14 @@
import readline from 'node:readline'
import readline from "node:readline"
const numbers = []
const readlineInterface = readline.createInterface({
input: process.stdin,
output: process.stdout
output: process.stdout,
})
readlineInterface.on('line', (value) => {
readlineInterface.on("line", (value) => {
numbers.push(Number(value))
})
readlineInterface.on('close', solution)
readlineInterface.on("close", solution)
function solution() {
const sortedNumbers = nativeSort(numbers.slice(1))
@@ -17,6 +17,6 @@ function solution() {
})
}
function nativeSort (numbers) {
function nativeSort(numbers) {
return numbers.sort((number1, number2) => number1 - number2)
}
@@ -2,6 +2,6 @@
Created by [@theoludwig](https://github.com/theoludwig) on 29 June 2021.
| Algorithm | Best Case | Average Case | Worst Case |
| ----------------------------------------------------------- | ----------- | ------------ | ----------- |
| [Insertion sort](https://wikipedia.org/wiki/Insertion_sort) | O(n) | O(n²) | O(n²) |
| Algorithm | Best Case | Average Case | Worst Case |
| ----------------------------------------------------------- | --------- | ------------ | ---------- |
| [Insertion sort](https://wikipedia.org/wiki/Insertion_sort) | O(n) | O(n²) | O(n²) |
@@ -1,14 +1,14 @@
import readline from 'node:readline'
import readline from "node:readline"
const numbers = []
const readlineInterface = readline.createInterface({
input: process.stdin,
output: process.stdout
output: process.stdout,
})
readlineInterface.on('line', (value) => {
readlineInterface.on("line", (value) => {
numbers.push(Number(value))
})
readlineInterface.on('close', solution)
readlineInterface.on("close", solution)
function solution() {
const sortedNumbers = insertionSort(numbers.slice(1))
@@ -2,6 +2,6 @@
Created by [@theoludwig](https://github.com/theoludwig) on 29 June 2021.
| Algorithm | Best Case | Average Case | Worst Case |
| ----------------------------------------------------------- | ----------- | ------------ | ----------- |
| [Merge sort](https://wikipedia.org/wiki/Merge_sort) | O(n log(n)) | O(n log(n)) | O(n log(n)) |
| Algorithm | Best Case | Average Case | Worst Case |
| --------------------------------------------------- | ----------- | ------------ | ----------- |
| [Merge sort](https://wikipedia.org/wiki/Merge_sort) | O(n log(n)) | O(n log(n)) | O(n log(n)) |
@@ -1,14 +1,14 @@
import readline from 'node:readline'
import readline from "node:readline"
const numbers = []
const readlineInterface = readline.createInterface({
input: process.stdin,
output: process.stdout
output: process.stdout,
})
readlineInterface.on('line', (value) => {
readlineInterface.on("line", (value) => {
numbers.push(Number(value))
})
readlineInterface.on('close', solution)
readlineInterface.on("close", solution)
function solution() {
const sortedNumbers = mergeSort(numbers.slice(1))
@@ -17,14 +17,14 @@ function solution() {
})
}
function divideArray (numbers) {
function divideArray(numbers) {
const middle = Math.round(numbers.length / 2)
const left = numbers.slice(0, middle)
const right = numbers.slice(middle)
return [left, right]
}
function merge (numbers1, numbers2) {
function merge(numbers1, numbers2) {
let indexNumbers1 = 0
let indexNumbers2 = 0
const result = []
@@ -46,7 +46,7 @@ function merge (numbers1, numbers2) {
return result
}
function mergeSort (numbers) {
function mergeSort(numbers) {
if (numbers.length <= 1) {
return numbers
}
@@ -2,6 +2,6 @@
Created by [@theoludwig](https://github.com/theoludwig) on 29 June 2021.
| Algorithm | Best Case | Average Case | Worst Case |
| ----------------------------------------------------------- | ----------- | ------------ | ----------- |
| [Bubble sort](https://wikipedia.org/wiki/Bubble_sort) | O(n) | O(n²) | O(n²) |
| Algorithm | Best Case | Average Case | Worst Case |
| ----------------------------------------------------- | --------- | ------------ | ---------- |
| [Bubble sort](https://wikipedia.org/wiki/Bubble_sort) | O(n) | O(n²) | O(n²) |
@@ -2,6 +2,6 @@
Created by [@theoludwig](https://github.com/theoludwig) on 29 June 2021.
| Algorithm | Best Case | Average Case | Worst Case |
| ----------------------------------------------------------- | ----------- | ------------ | ----------- |
| [Insertion sort](https://wikipedia.org/wiki/Insertion_sort) | O(n) | O(n²) | O(n²) |
| Algorithm | Best Case | Average Case | Worst Case |
| ----------------------------------------------------------- | --------- | ------------ | ---------- |
| [Insertion sort](https://wikipedia.org/wiki/Insertion_sort) | O(n) | O(n²) | O(n²) |
@@ -2,6 +2,6 @@
Created by [@theoludwig](https://github.com/theoludwig) on 29 June 2021.
| Algorithm | Best Case | Average Case | Worst Case |
| ----------------------------------------------------------- | ----------- | ------------ | ----------- |
| [Merge sort](https://wikipedia.org/wiki/Merge_sort) | O(n log(n)) | O(n log(n)) | O(n log(n)) |
| Algorithm | Best Case | Average Case | Worst Case |
| --------------------------------------------------- | ----------- | ------------ | ----------- |
| [Merge sort](https://wikipedia.org/wiki/Merge_sort) | O(n log(n)) | O(n log(n)) | O(n log(n)) |