Maailmantutkija

Kasvatuskirja uteliaalle mielelle

Overview

Distribution generators for creating triples of positive integers (≄1) with various mathematical properties. All generators ensure only positive integers are produced.

Available Generators

1. uniformRandom(maxElement = 20)

Generates three completely random positive integers.

uniformRandom(20)  // e.g., [7, 14, 3]

2. uniformRandomSum(maxSum = 30)

Generates three random positive integers where their sum ≀ maxSum.

uniformRandomSum(30)  // e.g., [5, 8, 12] (sum = 25)

3. randomSequence(options)

Generates sequences with configurable properties.

Options:

Examples:

// Strictly increasing with random differences
randomSequence({ strictly: true, direction: 'increasing' })
// → [3, 7, 15]

// Non-strict increasing arithmetic sequence with difference 3
randomSequence({ strictly: false, arithmetic: 3 })
// → [4, 7, 10]

// Strictly decreasing
randomSequence({ strictly: true, direction: 'decreasing' })
// → [18, 12, 5]

// Non-strict increasing arithmetic (allows equal consecutive elements)
randomSequence({ strictly: false, arithmetic: 0 })
// → [7, 7, 7]

4. constantSequence(maxElement = 20)

Generates three equal values.

constantSequence(20)  // e.g., [8, 8, 8]

5. linearMultiples(maxElement = 30)

Generates sequence of form (a, 2a, 3a) in random order.

linearMultiples(30)  // e.g., [4, 8, 12] or [12, 4, 8] (shuffled)

6. exponentialMultiples(maxElement = 40)

Generates sequence of form (a, 2a, 4a) in random order.

exponentialMultiples(40)  // e.g., [3, 6, 12] or [12, 3, 6] (shuffled)

7. extremumAtPosition(options)

Places smallest or largest value at specific position.

Options:

Examples:

// Largest at position 0 (first)
extremumAtPosition({ extremum: 'largest', position: 0 })
// → [18, 7, 3]

// Smallest at position 2 (last)
extremumAtPosition({ extremum: 'smallest', position: 2 })
// → [15, 9, 2]

8. equalAtPositions(options)

Makes two specific positions equal.

Options:

Examples:

// First and last equal
equalAtPositions({ position1: 0, position2: 2 })
// → [7, 14, 7]

// First and middle equal
equalAtPositions({ position1: 0, position2: 1 })
// → [11, 11, 5]

9. largestIsSum(options)

Creates triple where largest = smallest + middle.

Options:

Examples:

// Largest at end: [3, 5, 8] where 8 = 3 + 5
largestIsSum({ position: 2 })
// → [3, 5, 8]

// Largest at beginning: [10, 3, 7] where 10 = 3 + 7
largestIsSum({ position: 0 })
// → [10, 3, 7]

10. withEvenCount(options)

Generates triple with specified number of even integers.

Options:

Examples:

// Exactly 2 even numbers
withEvenCount({ numEven: 2 })
// → [8, 14, 7] or [3, 12, 18]

// All even
withEvenCount({ numEven: 3 })
// → [6, 10, 14]

// All odd
withEvenCount({ numEven: 0 })
// → [3, 7, 11]

Helper: sampleFromDistribution(distributions)

Samples from weighted distribution of generators.

Example:

const distributions = [
    { weight: 0.5, generator: () => uniformRandom(20) },
    { weight: 0.3, generator: () => constantSequence(15) },
    { weight: 0.2, generator: () => linearMultiples(30) }
];

sampleFromDistribution(distributions);
// Returns result from one generator based on weights

Current Rules (25 total)

Rules 1-22 (Existing)

  1. Aidosti kasvava (a < b < c)
  2. Kaikki samaa kokoa
  3. Aidosti vÀhenevÀ (a > b > c)
  4. Aritmeettinen ja kasvava
  5. Tuplaantuu aina kahdella (b = 2a, c = 4a)
  6. Suurin kasa on lopussa
  7. Suurin kasa on keskellÀ
  8. Tarkalleen kaksi on samaa kokoa
  9. EnsimmÀinen ja viimeinen samaa kokoa
  10. Kaikki eri suuret
  11. Summa on alle 15
  12. Summa on yli 20
  13. Aina +1 (esim. 3, 4, 5)
  14. Erotus suurimman ja pienimmÀn vÀlillÀ on enintÀÀn 5
  15. Kaikki ovat parillisia
  16. Löytyy parillinen luku
  17. Kaikki ovat alle 10
  18. EnsimmÀinen + toinen = kolmas
  19. Kolme perÀkkÀistÀ kokonaislukua jossakin jÀrjestyksessÀ
  20. Mediaani on 5
  21. Muodostavat kolmion (kolmioepÀyhtÀlö)
  22. Jokainen luku on edellisen monikerta

Rules 23-25 (New)

  1. Suurin luku on yli kaksinkertainen toiseksi suurimpaan
    • Check: sorted[2] > 2 * sorted[1]
    • Example: [2, 3, 7] where 7 > 2*3
  2. Kaikki ovat vÀliltÀ 5 ja 15
    • Check: 5 ≀ a,b,c ≀ 15
    • Example: [7, 10, 12]
  3. Lukujen suurin yhteinen tekijÀ on suurempi kuin 1
    • Check: gcd(a,b,c) > 1
    • Example: [6, 9, 12] where gcd = 3

Design Principles

  1. All positive integers: Every generated number is ≄ 1
  2. Configurable ranges: Most generators accept maxElement parameter
  3. Clear semantics: Generator names describe what they produce
  4. Composable: Can combine generators in weighted distributions
  5. Educational: Generators map to mathematical concepts (arithmetic sequences, multiples, GCD, etc.)

Usage in Game

import { ThreeNumberDistributions } from './three-numbers-distributions.js';

// For a rule "strictly increasing"
const positive = ThreeNumberDistributions.randomSequence({
    strictly: true,
    direction: 'increasing'
});

// For negative examples, mix different types
const distributions = [
    { weight: 0.3, generator: () => ThreeNumberDistributions.uniformRandom(20) },
    { weight: 0.3, generator: () => ThreeNumberDistributions.constantSequence(15) },
    { weight: 0.2, generator: () => ThreeNumberDistributions.randomSequence({
        strictly: true,
        direction: 'decreasing'
    })},
    { weight: 0.2, generator: () => ThreeNumberDistributions.randomSequence({
        strictly: false,
        direction: 'increasing'
    })}
];

const negative = ThreeNumberDistributions.sampleFromDistribution(distributions);

Future Extensions

Possible additional generators:

Testing Checklist

When adding distributions to rules: