チューブのどこか…しかし、どのライン?

ロンドン地下鉄A.K.A.地下鉄は世界で最も古い地下鉄で、現在267の名前の駅(「Edgware
Road」と「Hammersmith」はそれぞれ2つの場所を占めているため厳密に269 **駅に対応)

チャレンジ

nameで指定されたステーションにサービスを提供している行の名前を入力として出力します。

Input:
A string or list of characters

  • This may be assumed to be a valid station name (as
    listed in the code-block below).

  • You may assume any & in the input will
    consistently be the word and (or
    And) instead if you wish, just state it clearly in
    your answer.

Output:
Separated output listing those of the eleven lines
servicing that station:

  • A list of strings, a list of lists of characters, printed text,
    a string, a list of characters; if in doubt ask.

  • You may consistently output the word and
    (or And) in place of any & if you wish,
    just state this clearly in your answer.

  • With the caveat that if printing or returning a string or list
    of characters that the separator-substring used is not present in
    any of the line names (including the & or
    and or And used) – this therefore
    excludes the use of a single space character as the separator.

The Tube Network:
– Note: This is the final state, even if it happens to contain
a spelling mistake (unless addressed prior to any
answers)

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

… 11行の名前は次のとおりです。

Bakerloo
Central
Circle
District
Hammersmith & City
Jubilee
Metropolitan
Northern
Piccadilly
Victoria
Waterloo & City

*トランスポートロンドンでは他の列車も運行していますが、一部は「The
Tube」(「ドックランズライトレールウェイ」または「DLR」)の一部と呼ばれることもありますが、ここに記載されている11列に固執します。

**リンクされたウィキペディアのページには現在270と記載されていますが、私は彼らが誤って
“DLR”をサービスしているにもかかわらず、カナリーワーフの2番目の場所を間違って数えていると思います)


Mornington Crescent
(互換性があります)を使用した、ゴルフによる提出のための想像上のブラウニーポイントのヒープIDEはここで入手可能です!


This is ,
so the shortest code in bytes wins per language and the shortest
solution wins (don’t let golfing languages put you off golfing in
other languages). Have fun!

ベストアンサー

ES9、Node.js/Chrome、989 977 931 892 889 887バイト

s=>"Bakerloo,Central,Circle,District,Hammersmith & City,Jubilee,Metropolitan,Northern,Piccadilly,Victoria,Waterloo & City".split`,`.filter((_,i)=>parseInt('7c1w0o741s3k39w22c020c080we80y3l0a8w0t3xhs2olc7g0km87w0176r8ao2e4g0q5w0eeb753mekwx1k18'.substr(" 5Kd5_9 5c4^5];`3]3 4]4^<`Y`0^5h3 9 ;<`3 Wf9 9`E 0< ; 9`;]2o4b99a33d5`; 3`3jB]Kj9b55e8m5]= KmS ;]K5`9^9]<_3^0 ;]3_3]3 99;b=]K 3 Xe95`9_Qd5_0o3b;];bKf=e=b3jH_<]4d; 3g:d45eT]J_5Kk4{2q9_Kc4c<]5a3d8`5hF 4jKhLUm3|5]: ;a5{<> :^3d5t9]5l6_A~f9h5]5b5b9hK]9]: 5l4:a5m9}4^@oHkH^3e3c1c4nBf<^9~3n=l<]9]5]5a9kK 5 5`: =g:aHcAb2q?_2b0tAsNc;]9]9_3e5e3qAkR^Ac5bK Mc?a;9t=y2_;]5b3_2e<3 9`5_Ga4h9t8_9^>e3]H^Eg5zAe4cZ_;ePGm2 3a3".replace(/./g,c=>c.repeat((n=c[C='charCodeAt']())<92||n-91))[C](parseInt(s.replace(/W|d/g,''),36)*79%2777%2328)*2-96,2),36)>>i&1) 

完全なテストスイート(Node.js)

Try it online!

デモ(Chrome)

NB: Due to inconsistencies in the
implementation of parseInt() across
browsers(1), this is only guaranteed to work for all
stations on Chrome.

<div class=”snippet” data-lang=”js” data-hide=”true”
data-console=”true” data-babel=”false”> <div
class=”snippet-code snippet-currently-hidden”>

let f =

s=>"Bakerloo,Central,Circle,District,Hammersmith & City,Jubilee,Metropolitan,Northern,Piccadilly,Victoria,Waterloo & City".split`,`.filter((_,i)=>parseInt('7c1w0o741s3k39w22c020c080we80y3l0a8w0t3xhs2olc7g0km87w0176r8ao2e4g0q5w0eeb753mekwx1k18'.substr(" 5Kd5_9 5c4^5];`3]3 4]4^<`Y`0^5h3 9 ;<`3 Wf9 9`E 0< ; 9`;]2o4b99a33d5`; 3`3jB]Kj9b55e8m5]= KmS ;]K5`9^9]<_3^0 ;]3_3]3 99;b=]K 3 Xe95`9_Qd5_0o3b;];bKf=e=b3jH_<]4d; 3g:d45eT]J_5Kk4{2q9_Kc4c<]5a3d8`5hF 4jKhLUm3|5]: ;a5{<> :^3d5t9]5l6_A~f9h5]5b5b9hK]9]: 5l4:a5m9}4^@oHkH^3e3c1c4nBf<^9~3n=l<]9]5]5a9kK 5 5`: =g:aHcAb2q?_2b0tAsNc;]9]9_3e5e3qAkR^Ac5bK Mc?a;9t=y2_;]5b3_2e<3 9`5_Ga4h9t8_9^>e3]H^Eg5zAe4cZ_;ePGm2 3a3".replace(/./g,c=>c.repeat((n=c[C='charCodeAt']())<92||n-91))[C](parseInt(s.replace(/W|d/g,''),36)*79%2777%2328)*2-96,2),36)>>i&1)


</div> </div>

(1)仕様:mathIntを基数-R記法[...]でZで表される数学的な整数値とする。
Rが2,4,8,10,16、または32でない場合、mathIntは、基数-R表記でZで表される数学的整数値に対する実装依存の近似/em>


どうやって?

以下は入力 s = "St. James's Park"
のステップバイステップデコード例です。

ステップ1:

すべてのパディング文字を展開することにより、最初に一次ルックアップテーブル(503〜2,328バイト)を展開します。これらの文字は、92より大きいASCIIコードでエンコードされますが、ペイロードデータは48〜90の範囲を使用します。

tbl = " 5Kd5_9 5c4[...]"
  .replace(
    /./g, c =>
      c.repeat((n = c.charCodeAt()) < 92 || n - 91)
  )

ステップ2:

入力文字列からアルファベット以外の文字をすべて削除します。

str = s.replace(/W|d/g, '')

これは "StJamessPark" を与えます。

ステップ3:

結果の文字列を基数36として解析します。

id = parseInt(str, 36)

これは 3793395908848905700 です(これは Chrome V8 によって返された近似結果です)。 )。

ステップ4:

ハッシュ値を計算します。

hash = id * 79 % 2777 % 2328

これは 533 を与えます。

NB: Due to loss of precision, this result is
not mathematically correct (it should be 184). But the
lookup table was — of course — built the same way, so that’s the
one we’re expecting.

ステップ5:

主ルックアップテーブルのこの位置にある文字のASCIIコードを取得します。

code = tbl.charCodeAt(hash)

これは 58 (これは ':' の文字です)を与えます。

ステップ#6

この値を使用して、セカンダリルックアップテーブルから2文字の文字列を抽出します。

msk36 = '7c1w0o74[...]'.substr(code * 2 - 96, 2)

これは 0c を与えます。

ステップ7

この文字列を基数36として解析します。

msk = parseInt(msk36, 36)

12 となります。

ステップ#8

最後に、 msk
で設定されたビットに従って、最下位のものから開始して、ステーションリストをフィルタリングします。

"Bakerloo,Central,Circle,District,[...]".split`,`.filter((_, i) => msk >> i & 1)

この例では、 msk12 を保持しています。これはバイナリで
00000001100 です。最終的な結果につながる3番目と4番目のステーションを維持します:
['Circle'、 'District']

返信を残す

メールアドレスが公開されることはありません。 * が付いている欄は必須項目です