Last active
January 28, 2022 14:48
-
-
Save stuartlangridge/5a1131430b0a85795efdc82991a13767 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
""" | |
Find "tubewhacks"; words or phrases whose letters appear in all but a single tube station's name | |
https://www.reload.me.uk/tubewhack/ | |
Yeah, I'm just here to ruin the fun of thinking them up, by applying code to the problem. Sorry. | |
""" | |
import os | |
import textwrap | |
stations = set([(x.strip(), x.lower().strip()) for x in | |
open(os.path.join(os.path.dirname(__file__), "underground-stations.txt")).readlines()]) | |
words = [x.lower().strip() for x in | |
open("/usr/share/dict/words").readlines() if x.lower() == x and "'" not in x] | |
tubewhacks = {} | |
ll = float(len(words)) | |
pc = 0 | |
for idx, w in enumerate(words): | |
npc = int((idx / ll) * 100) | |
if npc > pc: | |
print(npc) | |
pc = npc | |
nstations = set(stations) | |
for l in w: | |
letters_in = set([s for s in nstations if l in s[1]]) | |
nstations = nstations - letters_in | |
if len(nstations) == 1: | |
nstation = list(nstations)[0][0] | |
if nstation not in tubewhacks: tubewhacks[nstation] = [] | |
tubewhacks[nstation].append(w) | |
with open("tubewhacks.txt", mode="w", encoding="utf-8") as fp: | |
for station, ewords in sorted(tubewhacks.items()): | |
fp.write(station + "\n") | |
fp.write("#" * len(station) + "\n") | |
fp.write("\n") | |
fp.write("\n".join(textwrap.wrap(", ".join(ewords)))) | |
fp.write("\n") | |
fp.write("\n") | |
fp.write("Untubewhackable stations\n") | |
fp.write("########################\n") | |
fp.write("\n") | |
snames = [x[0] for x in stations] | |
unt = sorted([x for x in snames if x not in tubewhacks]) | |
fp.write("\n".join(textwrap.wrap(", ".join(unt)))) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Abbey Road | |
Acton Town | |
Aldgate | |
Aldgate East | |
All Saints | |
Alperton | |
Amersham | |
Angel | |
Archway | |
Arnos Grove | |
Arsenal | |
Baker Street | |
Balham | |
Bank | |
Barbican | |
Barking | |
Barkingside | |
Barons Court | |
Bayswater | |
Beckton | |
Beckton Park | |
Becontree | |
Belsize Park | |
Bermondsey | |
Bethnal Green | |
Blackfriars | |
Blackhorse Road | |
Blackwall | |
Bond Street | |
Borough | |
Boston Manor | |
Bounds Green | |
Bow Church | |
Bow Road | |
Brent Cross | |
Brixton | |
Bromley-by-Bow | |
Buckhurst Hill | |
Burnt Oak | |
Caledonian Road | |
Camden Town | |
Canada Water | |
Canary Wharf | |
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 | |
Crossharbour | |
Croxley | |
Custom House | |
Cutty Sarkfor Maritime Greenwich | |
Cyprus | |
Dagenham East | |
Dagenham Heathway | |
Debden | |
Deptford Bridge | |
Devons Road | |
Dollis Hill | |
Ealing Broadway | |
Ealing Common | |
Earl's Court | |
East Acton | |
East Finchley | |
East Ham | |
East India | |
East Putney | |
Eastcote | |
Edgware | |
Edgware Road | |
Edgware Road | |
Elephant & Castle | |
Elm Park | |
Elverson Road | |
Embankment | |
Epping | |
Euston | |
Euston Square | |
Fairlop | |
Farringdon | |
Finchley Central | |
Finchley Road | |
Finsbury Park | |
Fulham Broadway | |
Gallions Reach | |
Gants Hill | |
Gloucester Road | |
Golders Green | |
Goldhawk Road | |
Goodge Street | |
Grange Hill | |
Great Portland Street | |
Greenford | |
Green Park | |
Greenwich | |
Gunnersbury | |
Hainault | |
Hammersmith | |
Hammersmith | |
Hampstead | |
Hanger Lane | |
Harlesden | |
Harrow & Wealdstone | |
Harrow-on-the-Hill | |
Hatton Cross | |
Heathrow Terminals 1, 2, 3 | |
Heathrow Terminal 4 | |
Heathrow Terminal 5 | |
Hendon Central | |
Heron Quays | |
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 | |
Island Gardens | |
Kennington | |
Kensal Green | |
Kensington (Olympia) | |
Kentish Town | |
Kenton | |
Kew Gardens | |
Kilburn | |
Kilburn Park | |
King George V | |
Kingsbury | |
King's Cross St. Pancras | |
Knightsbridge | |
Ladbroke Grove | |
Lambeth North | |
Langdon Park | |
Latimer Road | |
Leicester Square | |
Lewisham | |
Leyton | |
Leytonstone | |
Limehouse | |
Liverpool Street | |
London Bridge | |
London City Airport | |
Loughton | |
Maida Vale | |
Manor House | |
Mansion House | |
Marble Arch | |
Marylebone | |
Mile End | |
Mill Hill East | |
Monument | |
Moorgate | |
Moor Park | |
Morden | |
Mornington Crescent | |
Mudchute | |
Neasden | |
Newbury Park | |
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 | |
Pontoon Dock | |
Poplar | |
Preston Road | |
Prince Regent | |
Pudding Mill Lane | |
Putney Bridge | |
Queen's Park | |
Queensbury | |
Queensway | |
Ravenscourt Park | |
Rayners Lane | |
Redbridge | |
Regent's Park | |
Richmond | |
Rickmansworth | |
Roding Valley | |
Royal Albert | |
Royal Oak | |
Royal Victoria | |
Ruislip | |
Ruislip Gardens | |
Ruislip Manor | |
Russell Square | |
St. James's Park | |
St. John's Wood | |
St. Paul's | |
Seven Sisters | |
Shadwell | |
Shepherd's Bush | |
Shepherd's Bush Market | |
Sloane Square | |
Snaresbrook | |
South Ealing | |
South Harrow | |
South Kensington | |
South Kenton | |
South Quay | |
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 Gateway | |
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 India Quay | |
West Kensington | |
West Ruislip | |
West Silvertown | |
Westbourne Park | |
Westferry | |
Westminster | |
White City | |
Whitechapel | |
Willesden Green | |
Willesden Junction | |
Wimbledon | |
Wimbledon Park | |
Wood Green | |
Wood Lane | |
Woodford | |
Woodside Park | |
Woolwich Arsenal |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Stations list probably correct as of January 2022, but I got it by just taking the names from https://simple.wikipedia.org/wiki/List_of_London_Underground_stations with little attention which means that there may be some in the list which aren't really stations or which are closed or something, I don't know. If you want accuracy in these things talk to Geoff Marshall. Only about 80 stations have a tubewhack at all; most do not, as a single word, at least not a single word in the Ubuntu dictionary. Many will have as two or more words (for example, "pot when" is a tubewhack for Blackfriars). As far as I can tell you could permanently break this game by creating a station whose name is a perfect anagram of another different station: I recommend making a station called Erect Bone somewhere near Becontree, but you may have other suggestions.