From a9be912e214dc02a39514432ddb57592bc89aa13 Mon Sep 17 00:00:00 2001 From: Dennis Bauer Date: Mon, 13 Apr 2026 21:44:50 +0200 Subject: [PATCH 1/3] Setup Problem --- Problems/Vertical-List/README.md | 22 ++++++++++++ Problems/Vertical-List/solver.ts | 3 ++ Problems/Vertical-List/vertical-list.test.ts | 38 ++++++++++++++++++++ package-lock.json | 4 +-- 4 files changed, 65 insertions(+), 2 deletions(-) create mode 100644 Problems/Vertical-List/README.md create mode 100644 Problems/Vertical-List/solver.ts create mode 100644 Problems/Vertical-List/vertical-list.test.ts diff --git a/Problems/Vertical-List/README.md b/Problems/Vertical-List/README.md new file mode 100644 index 0000000..e5b4800 --- /dev/null +++ b/Problems/Vertical-List/README.md @@ -0,0 +1,22 @@ +# Vertical-List + +Create a function that converts a string into a matrix of characters that can be read vertically. Add spaces when characters are missing. + +## Documentation + +### Solution Idea + +The Idea to solve this problem + +--- + +### [Implementation](./solver.ts) + +The implementation for solving this problem + +--- + +### Information's + +This problem comes from the newsletter [Sloth Bytes](https://slothbytes.beehiiv.com). +[Post](https://slothbytes.beehiiv.com/p/why-your-delete-button-is-a-lie) from May 18, 2026. diff --git a/Problems/Vertical-List/solver.ts b/Problems/Vertical-List/solver.ts new file mode 100644 index 0000000..8941e53 --- /dev/null +++ b/Problems/Vertical-List/solver.ts @@ -0,0 +1,3 @@ +export default function verticalTxt(text: string): string[][] { + throw new Error("Not yet implemented"); +} diff --git a/Problems/Vertical-List/vertical-list.test.ts b/Problems/Vertical-List/vertical-list.test.ts new file mode 100644 index 0000000..5c6c5b4 --- /dev/null +++ b/Problems/Vertical-List/vertical-list.test.ts @@ -0,0 +1,38 @@ +import { describe, expect, it } from "vitest"; +import verticalTxt from "./solver"; + +describe("Description for the tests", () => { + it("should return a 2x7 Matrix for 'Holy bananas'", () => { + expect(verticalTxt("Holy bananas")).toEqual([ + ["H", "b"], + ["o", "a"], + ["l", "n"], + ["y", "a"], + [" ", "n"], + [" ", "a"], + [" ", "s"], + ]); + }); + + it("should return a 2x6 Matrix for 'Hello fellas'", () => { + expect(verticalTxt("Holy bananas")).toEqual([ + ["H", "f"], + ["e", "e"], + ["l", "l"], + ["l", "l"], + ["o", "a"], + [" ", "s"], + ]); + }); + + it("should return a 4x6 Matrix for 'Hello fellas I'm Dennis'", () => { + expect(verticalTxt("Holy bananas")).toEqual([ + ["H", "f", "I", "D"], + ["e", "e", "'", "e"], + ["l", "l", "m", "n"], + ["l", "l", " ", "n"], + ["o", "a", " ", "i"], + [" ", "s", " ", "s"], + ]); + }); +}); diff --git a/package-lock.json b/package-lock.json index 9c8d4bc..da9f27e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "problem-solving", - "version": "CP-23", + "version": "CP-25", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "problem-solving", - "version": "CP-23", + "version": "CP-25", "license": "ISC", "dependencies": { "decimal.js": "^10.6.0", From dc33884ff58621f9f37893111bf8de2ffa9d8c44 Mon Sep 17 00:00:00 2001 From: Dennis Bauer Date: Mon, 13 Apr 2026 22:01:25 +0200 Subject: [PATCH 2/3] Solved Problem --- Problems/Vertical-List/solver.ts | 16 +++++++++++++++- Problems/Vertical-List/vertical-list.test.ts | 4 ++-- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/Problems/Vertical-List/solver.ts b/Problems/Vertical-List/solver.ts index 8941e53..bce5a72 100644 --- a/Problems/Vertical-List/solver.ts +++ b/Problems/Vertical-List/solver.ts @@ -1,3 +1,17 @@ export default function verticalTxt(text: string): string[][] { - throw new Error("Not yet implemented"); + const textArray = text.split(" "); + const solution: string[][] = []; + + textArray.forEach((word, wordNumber) => { + word.split("").forEach((char, charNumber) => { + if (solution[charNumber] === undefined) solution[charNumber] = []; + + if (wordNumber > 0 && solution[charNumber][wordNumber - 1] === undefined) + solution[charNumber][wordNumber - 1] = " "; + + solution[charNumber][wordNumber] = char; + }); + }); + + return solution; } diff --git a/Problems/Vertical-List/vertical-list.test.ts b/Problems/Vertical-List/vertical-list.test.ts index 5c6c5b4..755d2bf 100644 --- a/Problems/Vertical-List/vertical-list.test.ts +++ b/Problems/Vertical-List/vertical-list.test.ts @@ -15,7 +15,7 @@ describe("Description for the tests", () => { }); it("should return a 2x6 Matrix for 'Hello fellas'", () => { - expect(verticalTxt("Holy bananas")).toEqual([ + expect(verticalTxt("Hello fellas")).toEqual([ ["H", "f"], ["e", "e"], ["l", "l"], @@ -26,7 +26,7 @@ describe("Description for the tests", () => { }); it("should return a 4x6 Matrix for 'Hello fellas I'm Dennis'", () => { - expect(verticalTxt("Holy bananas")).toEqual([ + expect(verticalTxt("Hello fellas I'm Dennis")).toEqual([ ["H", "f", "I", "D"], ["e", "e", "'", "e"], ["l", "l", "m", "n"], From 8e28c8034f432dcefb0de72da816dbd69db1b14f Mon Sep 17 00:00:00 2001 From: Dennis Bauer Date: Mon, 13 Apr 2026 22:08:40 +0200 Subject: [PATCH 3/3] Finished problem --- Problems/Vertical-List/README.md | 18 +++++++++++++----- README.md | 9 ++++----- 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/Problems/Vertical-List/README.md b/Problems/Vertical-List/README.md index e5b4800..3171a17 100644 --- a/Problems/Vertical-List/README.md +++ b/Problems/Vertical-List/README.md @@ -4,15 +4,23 @@ Create a function that converts a string into a matrix of characters that can be ## Documentation -### Solution Idea +### Solution Idea & [Implementation](./solver.ts) -The Idea to solve this problem +The idea is to loop over every word in the text and process each character separately. ---- +For every character, we first check whether an array already exists in the solution array at the index of the character's position in the word. +If not, we create a new array there. + +Then we place the character into the solution array at this position: + +\[character position\]\[word index\] + +This correctly rearranges the characters, but the spaces for shorter words are still missing. -### [Implementation](./solver.ts) +To fix this, whenever the word index is greater than `0`, we check whether the previous character position exists for the previous word. +If it does not exist, we know that the previous word was shorter, so we insert an empty space at that position. -The implementation for solving this problem +By doing this for every word and every character, the solution array is built correctly and the final transformed text can be returned. --- diff --git a/README.md b/README.md index 7d58c23..931b4e4 100644 --- a/README.md +++ b/README.md @@ -2,15 +2,13 @@ This repository is about solving coding-problems. It contains famous (or not that famous) problems with my solution (Dennis Bauer). I ranked the problems as 🟢 Easy, 🟠 Medium and 🔴 Hard. These ranks reflect the time I invested in the problem and how difficult it felt to me. -# Problem-list - ## Problems -Solved: **25 problems** +Solved: **26 problems** -🟢 Easy: 19 +🟢 Easy: 20 🟠 Medium: 5 🔴 Hard: 1 @@ -41,10 +39,11 @@ Solved: **25 problems** | [Remove the last vowel](./Problems/Remove-The-Last-Vowel/README.md) | 🟢 Easy | | [Bingo Check](./Problems/Bingo-Check/README.md) | 🟢 Easy | | [Missing Number](./Problems/Missing-Number/README.md) | 🟢 Easy | +| [Vertical List](./Problems/Vertical-List/README.md) | 🟢 Easy | -## npm-Version: +## npm-Version The version indicates how much problems are implemented (cp -> Coding Problem)