diff --git a/src/utils/helpers.ts b/src/utils/helpers.ts index c35c637..9a64e46 100644 --- a/src/utils/helpers.ts +++ b/src/utils/helpers.ts @@ -3,4 +3,8 @@ export const range = (start: number, stop: number, step = 1) => export function classNames(...classes: (string | null | undefined)[]) { return classes.filter(Boolean).join(" "); +} + +export function sum(a: number, b: number): number { + return a + b; } \ No newline at end of file diff --git a/src/utils/math.ts b/src/utils/math.ts new file mode 100644 index 0000000..98b883e --- /dev/null +++ b/src/utils/math.ts @@ -0,0 +1,10 @@ +import {range, sum} from "@/utils/helpers"; + +export function failureProbability(boxCount: number, attempts: number): number { + const upperRange = boxCount - attempts; + return range(attempts + 1, attempts + upperRange).map(n => 1.0 / n).reduce(sum); +} + +export function successProbability(boxCount: number, attempts: number) { + return 1.0 - failureProbability(boxCount, attempts); +} \ No newline at end of file