1
1
mirror of https://github.com/theoludwig/programming-challenges.git synced 2025-05-18 12:02:53 +02: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

View File

@ -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²) |

View File

@ -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²) |

View File

@ -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)) |

View File

@ -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²) |

View File

@ -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²) |

View File

@ -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)) |

View File

@ -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²) |

View File

@ -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++) {

View File

@ -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)
}

View File

@ -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²) |

View File

@ -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))

View File

@ -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)) |

View File

@ -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
}

View File

@ -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²) |

View File

@ -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²) |

View File

@ -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)) |