English Puzzle Solver - London Underground Edition

Interactive London Underground station name puzzle solver using binary bitmask algorithms for efficient letter matching. Features quiz questions, word finding, and data visualization.

v0.0.1
🍰
🏃
🎓
Advanced

English Puzzle Solver

A general-purpose puzzle solver using binary bitmask algorithms for efficient letter matching. This component can work with any dataset of words or names to solve puzzles by finding unique letter combinations. The London Underground stations are used as a default example dataset.

Overview

The English Puzzle Solver uses a clever binary bitmask algorithm to quickly match words and solve puzzles. Each letter A-Z is represented as a bit position (0-25) in a 26-bit integer, enabling O(1) letter matching through bitwise operations.

How It Works

  1. Binary Encoding: Each item name is converted to a 26-bit mask where each bit represents a letter (A=bit 0, B=bit 1, ..., Z=bit 25)
  2. Filter Finding: The algorithm finds the shortest combination of letters that uniquely identifies an item
  3. Word Matching: Uses pre-encoded binary word data to instantly find words matching filter criteria
  4. Data Visualization: Interactive table showing letter frequency and presence across all items

Example Puzzle (London Underground Dataset)

"Name the only London Underground station that doesn't share any letters with the word 'Mackerel'?"

The answer is St John's Wood - it's the only station that doesn't contain any letters from "Mackerel" (M, A, C, K, E, R, L).

This puzzle solver can work with any dataset - cities, countries, words, or any collection of text items!

Binary Mask Algorithm

The core innovation uses binary masks for O(1) letter matching:

  • Each letter A-Z maps to bit position 0-25
  • Item names converted to 26-bit masks
  • Bitwise AND/OR operations enable instant filtering
  • Example: "BANK" = bits 1,0,13,10 set = 0b00000010000010000000000011

Technical Details

// Convert item name to binary mask
function convertToBinaryMask(itemName: string): number {
  let binaryMask = 0;
  for (let char of itemName) {
    binaryMask |= 1 << (char.charCodeAt(0) - 'A'.charCodeAt(0));
  }
  return binaryMask;
}

// Check if filter matches item
const filterMask = convertToBinaryMask("ABC");
const itemMask = convertToBinaryMask("BANK");
const matches = (itemMask & filterMask) === filterMask; // true if item contains all filter letters

Features

  • Interactive Quiz: Rotating quiz questions with reveal animations (configurable per dataset)
  • Item Filtering: Find unique letter combinations that identify items in your dataset
  • Word Matching: Find English words matching filter criteria using binary search
  • Data Visualization: Filterable table showing letter presence across all items
  • Letter Analysis: Frequency ranking and occurrence counts for each letter
  • Configurable: Works with any dataset - just provide CSV data and configuration

Data Generation

The component uses pre-processed data files. For the London Underground example:

  1. LND_UG.csv: Station data with line information (can be any CSV with your data)
  2. 130k.txt: Processed word list (130,000 words sorted by frequency)
  3. words.base64.txt: Binary encoded word data for fast bitwise matching

Data generation scripts are available in /scripts/:

  • _processWordList.js: Processes raw word frequency data
  • _convertTxtToBinary.js: Converts word list to binary format
  • _combinedFilter.js: Testing utility for filter algorithm

You can use your own CSV file - just configure the component with the path and the column key to extract items from.

Details

  • Title: English Puzzle Solver - London Underground Edition
  • Author: Mangle Kuo
  • GitHub: ghcpuman902
  • Tags: react, tailwind, london, underground, puzzle, word-matching, binary, algorithm, data-visualization, interactive
  • Version: 0.0.1
  • Complexity: advanced
  • Category: components

Example Usage

Default (London Underground)

import { EnglishPuzzleSolver } from './english-puzzle-solver';

export default function Page() {
  return <EnglishPuzzleSolver />;
}

Custom Dataset

import { EnglishPuzzleSolver, PuzzleConfig } from './english-puzzle-solver';

export default function Page() {
  const config: PuzzleConfig = {
    title: 'World Capitals Puzzle',
    itemName: 'Capital',
    dataSource: {
      csvPath: 'public/data/capitals.csv',
      csvKey: 'Capital',
    },
    wordListPath: 'public/london-underground/130k.txt',
    wordListBinaryPath: 'public/london-underground/words.base64.txt',
    questions: [
      {
        question: "Which capital city doesn't share any letters with 'Tokyo'?",
        answer: 'Paris',
      },
    ],
  };
  
  return <EnglishPuzzleSolver config={config} />;
}

Credits

  • Station data: London Underground network
  • Word list: Processed from Leipzig Wortschatz (https://wortschatz.uni-leipzig.de/de/download/English)

London Underground Station Names

🧩 Puzzle Solver

Find unique letter combinations that identify items! 🧠✨

Discover the data

Station
A
B
C
D
E
F
G
H
I
J
K
L
M
N
O
P
Q
R
S
T
U
V
W
X
Y
Z
Acton Town
Aldgate
Aldgate East
Alperton
Amersham
Angel
Archway
Arnos Grove
Arsenal
Baker Street
Balham
Bank
Barbican
Barking
Barkingside
Barons Court
Battersea Power Station
Bayswater
Becontree
Belsize Park
Bermondsey
Bethnal Green
Blackfriars
Blackhorse Road
Bond Street
Borough
Boston Manor
Bounds Green
Bow Road
Brent Cross
Brixton
Bromley-by-Bow
Buckhurst Hill
Burnt Oak
Caledonian Road
Camden Town
Canada Water
Canary Wharf
Canning Town
Cannon Street
Canons Park
Chalfont & Latimer
Chalk Farm
Chancery Lane
Charing Cross
Chesham
Chigwell
Chiswick Park
Chorleywood
Clapham Common
Clapham North
Clapham South
Cockfosters
Colindale
Colliers Wood
Covent Garden
Croxley
Dagenham East
Dagenham Heathway
Debden
Dollis Hill
Ealing Broadway
Ealing Common
Earl's Court
East Acton
East Finchley
East Ham
East Putney
Eastcote
Edgware
Edgware Road
Elephant & Castle
Elm Park
Embankment
Epping
Euston
Euston Square
Fairlop
Farringdon
Finchley Central
Finchley Road
Finsbury Park
Fulham Broadway
Gants Hill
Gloucester Road
Golders Green
Goldhawk Road
Goodge Street
Grange Hill
Great Portland Street
Greenford
Green Park
Gunnersbury
Hainault
Hammersmith
Hampstead
Hanger Lane
Harlesden
Harrow & Wealdstone
Harrow-on-the-Hill
Hatton Cross
Heathrow Terminals 2 & 3
Heathrow Terminal 4
Heathrow Terminal 5
Hendon Central
High Barnet
Highbury & Islington
Highgate
High Street Kensington
Hillingdon
Holborn
Holland Park
Holloway Road
Hornchurch
Hounslow Central
Hounslow East
Hounslow West
Hyde Park Corner
Ickenham
Kennington
Kensal Green
Kensington (Olympia)
Kentish Town
Kenton
Kew Gardens
Kilburn
Kilburn Park
Kingsbury
King's Cross St Pancras
Knightsbridge
Ladbroke Grove
Lambeth North
Lancaster Gate
Latimer Road
Leicester Square
Leyton
Leytonstone
Liverpool Street
London Bridge
Loughton
Maida Vale
Manor House
Mansion House
Marble Arch
Marylebone
Mile End
Mill Hill East
Monument
Moorgate
Moor Park
Morden
Mornington Crescent
Neasden
Newbury Park
Nine Elms
North Acton
North Ealing
North Greenwich
North Harrow
North Wembley
Northfields
Northolt
Northwick Park
Northwood
Northwood Hills
Notting Hill Gate
Oakwood
Old Street
Osterley
Oval
Oxford Circus
Paddington
Park Royal
Parsons Green
Perivale
Piccadilly Circus
Pimlico
Pinner
Plaistow
Preston Road
Putney Bridge
Queen's Park
Queensbury
Queensway
Ravenscourt Park
Rayners Lane
Redbridge
Regent's Park
Richmond
Rickmansworth
Roding Valley
Royal Oak
Ruislip
Ruislip Gardens
Ruislip Manor
Russell Square
St James's Park
St John's Wood
St Paul's
Seven Sisters
Shepherd's Bush
Shepherd's Bush Market
Sloane Square
Snaresbrook
South Ealing
South Harrow
South Kensington
South Kenton
South Ruislip
South Wimbledon
South Woodford
Southfields
Southgate
Southwark
Stamford Brook
Stanmore
Stepney Green
Stockwell
Stonebridge Park
Stratford
Sudbury Hill
Sudbury Town
Swiss Cottage
Temple
Theydon Bois
Tooting Bec
Tooting Broadway
Tottenham Court Road
Tottenham Hale
Totteridge & Whetstone
Tower Hill
Tufnell Park
Turnham Green
Turnpike Lane
Upminster
Upminster Bridge
Upney
Upton Park
Uxbridge
Vauxhall
Victoria
Walthamstow Central
Wanstead
Warren Street
Warwick Avenue
Waterloo
Watford
Wembley Central
Wembley Park
West Acton
West Brompton
West Finchley
West Ham
West Hampstead
West Harrow
West Kensington
West Ruislip
Westbourne Park
Westminster
White City
Whitechapel
Willesden Green
Willesden Junction
Wimbledon
Wimbledon Park
Wood Green
Wood Lane
Woodford
Woodside Park
Station
A
B
C
D
E
F
G
H
I
J
K
L
M
N
O
P
Q
R
S
T
U
V
W
X
Y
Z