diff --git a/src/components/BoxLoop.tsx b/src/components/BoxLoop.tsx
new file mode 100644
index 0000000..54ebe83
--- /dev/null
+++ b/src/components/BoxLoop.tsx
@@ -0,0 +1,74 @@
+import React, {FunctionComponent, useState} from "react";
+import Chance from "chance";
+import {classNames, getColor, range} from "@/utils/helpers";
+import {create} from "domain";
+import BoxGraphic from "@/components/BoxGraphic";
+import Xarrow from "react-xarrows";
+
+interface BoxLoopProps {
+
+}
+
+/**
+ * Creates a loop of numbers in the given range & length.
+ * @param loopRange An array describing the range of numbers to pick from.
+ * @param count The number of items in the loop.
+ */
+function createLoop(loopRange: [number, number], count: number): { start: number, loop: Record
@@ -53,6 +54,39 @@ const Home: NextPage = () => {
this challenge to be impossible - but it turns out there is a strategy that guarantees a
31% chance of success!
+ Here's how it works:
+
+
+ Due to an interesting mathematical quirk of some (assumed) properties of the game,
+ the boxes have an interesting structure to their existence.
+
+ No matter what number of configuration of boxes is given, a loop, a sequence of numbers that
+ will
+ return to the first one you picked, will exist.
+
+ Given that there are only 100 boxes, you won't find a loop that goes on forever,
+ and you won't find a box without a number under it (one that goes nowhere).
+
+
+ Essentially, by following the boxes, it is certain that you will find your slip. +
+ diff --git a/src/utils/helpers.ts b/src/utils/helpers.ts index 9a64e46..2dd0e9a 100644 --- a/src/utils/helpers.ts +++ b/src/utils/helpers.ts @@ -1,3 +1,25 @@ +import Chance from "chance"; + +const colors = [ + "#EF4444", + "#F97316", + "#F59E0B", + "#EAB308", + "#84CC16", + "#22C55E", + "#10B981", + "#14B8A6", + "#06B6D4", + "#0EA5E9", + "#3B82F6", + "#6366F1", + "#8B5CF6", + "#A855F7", + "#D946EF", + "#EC4899", + "#F43F5E", +] + export const range = (start: number, stop: number, step = 1) => Array.from({length: (stop - start) / step + 1}, (_, i) => start + i * step); @@ -7,4 +29,9 @@ export function classNames(...classes: (string | null | undefined)[]) { export function sum(a: number, b: number): number { return a + b; +} + +export function getColor(seed: number) { + const chance = Chance(seed); + return chance.pickone(colors); } \ No newline at end of file