Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions Problems/Bingo-Check/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# Bingo-Check

Create a function that takes a 5x5 2D list and returns True if it has at least one Bingo, and False If it doesn't.

## Infos which are maybe needed

A board has a bingo, when a horizontal, vertical or diagonal 5 `x` line exists.

## Documentation

### Solution Idea

The board is represented as a 2D array (an array containing other arrays).

First, we check whether any inner array is completely filled with `"x"`.
If such an array exists, it means there is a horizontal line and we return `true`.

If not, we check for vertical lines.
For each possible index (0 → 4), we check the same index in every inner array.
If all arrays contain `"x"` at that index, we have a vertical line and return `true`.

Finally, we check the two diagonals:

- positions `[i, i]`
- positions `[i, 4 - i]`

For each index `i`, we verify whether all elements on one of these diagonals are `"x"`.
If either diagonal contains only `"x"`, we return `true`.

If none of these checks succeed, no winning line exists and the function returns `false`.

---

### [Implementation](./solver.ts)

It`s really simple. There are just 3 different for-loops. I don't think there is a description necessary :)

---

### Information's

This problem comes from the newsletter [Sloth Bytes](https://slothbytes.beehiiv.com).
[Post](https://slothbytes.beehiiv.com/p/managing-data-is-complicated) from January 27, 2026.
79 changes: 79 additions & 0 deletions Problems/Bingo-Check/bingo-check.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
import { describe, expect, it } from "vitest";
import type { FixedArray } from "../../utilities/types/fixedArray";
import bingoCheck from "./solver";

type CardType = FixedArray<FixedArray<"x" | number, 5>, 5>;

describe("Validates correctly if a Bingo-Card has a bingo on it or not", () => {
const firstCard: CardType = [
[45, "x", 31, 74, 87],
[64, "x", 47, 32, 90],
[37, "x", 68, 83, 54],
[67, "x", 98, 39, 44],
[21, "x", 24, 30, 52],
];

it("should return true for the horizontal bingo", () => {
expect(bingoCheck(firstCard)).toEqual(true);
});

const secondCard: CardType = [
["x", 43, 31, 74, 87],
[64, "x", 47, 32, 90],
[37, 65, "x", 83, 54],
[67, 98, 39, "x", 44],
[21, 59, 24, 30, "x"],
];

it("should return true for the diagonal bingo", () => {
expect(bingoCheck(secondCard)).toEqual(true);
});

const thirdCard: CardType = [
["x", "x", "x", "x", "x"],
[64, 12, 47, 32, 90],
[37, 16, 68, 83, 54],
[67, 19, 98, 39, 44],
[21, 75, 24, 30, 52],
];

it("should return true for the diagonal bingo", () => {
expect(bingoCheck(thirdCard)).toEqual(true);
});

const forthCard: CardType = [
[45, "x", 31, 74, 87],
[64, 78, 47, "x", 90],
[37, "x", 68, 83, 54],
[67, "x", 98, "x", 44],
[21, "x", 24, 30, 52],
];

it("should return false for no bingo", () => {
expect(bingoCheck(forthCard)).toEqual(false);
});

const fifthCard: CardType = [
[45, 43, 31, 74, 87],
["x", 29, 47, 32, 90],
[37, "x", 41, 83, 54],
[67, 98, "x", 58, 44],
[21, 59, 24, "x", 59],
];

it("should return false for a wrong vertical bingo", () => {
expect(bingoCheck(fifthCard)).toEqual(false);
});

const sixthCard: CardType = [
[21, 59, 24, 30, "x"],
[67, 98, 39, "x", 44],
[37, 65, "x", 83, 54],
[64, "x", 47, 32, 90],
["x", 43, 31, 74, 87],
];

it("should return true for the other diagonal bingo", () => {
expect(bingoCheck(sixthCard)).toEqual(true);
});
});
22 changes: 22 additions & 0 deletions Problems/Bingo-Check/solver.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import type { FixedArray } from "../../utilities/types/fixedArray";

export default function bingoCheck(card: FixedArray<FixedArray<"x" | number, 5>, 5>): boolean {
if (
card.reduce(
(preVal, row) => (preVal ? true : row.reduce((p, element) => (p ? element === "x" : false), true)),
false
)
)
return true;

let leftDiagonal = true;
let rightDiagonal = true;
for (let i = 0; i < card.length; i++) {
if (card.reduce((preVal, val) => (preVal ? val[i] === "x" : false), true)) return true;

if (!(leftDiagonal && card[i][i] === "x")) leftDiagonal = false;
if (!(rightDiagonal && card[i][4 - i] === "x")) rightDiagonal = false;
}

return rightDiagonal || leftDiagonal;
}
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ This repository is about solving coding-problems. It contains famous (or not tha

## Problems

Solved: **23 problems**
Solved: **24 problems**

🟢 Easy: 17
🟢 Easy: 18
🟠 Medium: 5
🔴 Hard: 1

Expand Down Expand Up @@ -39,6 +39,7 @@ Solved: **23 problems**
| [One Two Skip a Few](./Problems/One-Two-Skip-A-Few/README.md) | 🟢 Easy |
| [Day number of year](./Problems/Day-Number-Of-Year/README.md) | 🟢 Easy |
| [Remove the last vowel](./Problems/Remove-The-Last-Vowel/README.md) | 🟢 Easy |
| [Bingo Check](./Problems/Bingo-Check/README.md) | 🟢 Easy |

<!-- PROBLEMS_END -->

Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
"test:file": "vitest",
"test:ci": "vitest --run --passWithNoTests --reporter=json > vitest-report.json",
"build": "tsc",
"normalize": "biome check --write --unsafe",
"clear": "rm -rf ./build",
"normalize": "npm run clear && biome check --write --unsafe",
"prepare": "husky install"
},
"dependencies": {
Expand Down
11 changes: 11 additions & 0 deletions utilities/types/fixedArray.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// Source - https://stackoverflow.com/a/60762482
// Posted by Tomasz Gawel, modified by community. See post 'Timeline' for change history
// Retrieved 2026-03-14, License - CC BY-SA 4.0

type Grow<T, A extends Array<T>> = ((x: T, ...xs: A) => void) extends (...a: infer X) => void ? X : never;
type GrowToSize<T, A extends Array<T>, N extends number> = {
0: A;
1: GrowToSize<T, Grow<T, A>, N>;
}[A["length"] extends N ? 0 : 1];

export type FixedArray<T, N extends number> = GrowToSize<T, [], N>;
Loading