周辺国


27

他の国がどの国を取り囲んでいるのだろうか?私も時々やりますが、それが課題です。

この投稿の下部にあるコードブロックで認識しなければならない国とその国のリストを提供しました。入力国に隣接する国のレイヤーのリストを(あなたの言語で可能な限り最も便利な方法で)出力する完全なプログラムを作成する必要があります。したがって、たとえば:

>>> "United Kingdom" 1
Republic of Ireland

なぜなら"United Kingdom"国名で1あり、あなたが作りたい層の数だからです。実際、Republic of Ireland他の国に行く途中に海があるため、任意の数のレイヤー(0を除く)が返されます。

参照マップ:

地図

例(括弧内のすべてはコメントです)(明らかに、出力の順序は重要ではありません):

>>> Bhutan 2
India (layer 1, touching Bhutan)
China (layer 1, touching Bhutan)
Bangladesh (layer 2, touching India)
Myanmar (layer 2, touching China and India)
Laos (layer 2, touching China)
Vietnam (layer 2, touching China)
North Korea (layer 2, touching China)
Russia (layer 2, touching China)
Mongolia (layer 2, touching China)
Kazakstan (layer 2, touching China)
Uzbekistan (layer 2, touching China)
Afganistan (layer 2, touching China)
Pakistan (layer 2, touching China and India)
Kashmir (layer 2, touching China and India)
Nepal (layer 2, touching China and India)
>>> Russia 0 (no layers used)

>>> Cyprus 1800 (there's a sea in the way)

>>> "The Gambia" 4 (there's a sea in the way)
Senegal (layer 1)
Mauritania (layer 2)
Mali (layer 2)
Guinea (layer 2)
Guinea-Bissau (layer 2)
Sierra Leone (layer 3)
Liberia (layer 3)
Cote D'Ivoire (layer 3)
Burkina Faso (layer 3)
Niger (layer 3)
Algeria (layer 3)
Western Sahara (layer 3)
Morocco (layer 4)
Tunisia (layer 4)
Libya (layer 4)
Chad (layer 4)
Nigeria (layer 4)
Benin (layer 4)
Togo (layer 4)
Ghana (layer 4)

世界は大きいので、コードを小さくすることで補う必要があります。結局のところ、これはです。

リストに触れる(順不同で、できれば解析可能な形式)(ここに間違いがある場合はお知らせください。何度も経験しましたが、間違いを犯したことがあります):

USA touches: Canada, Mexico

Canada touches: USA

Mexico touches: USA, Belize, Guatemala

Guatemala touches: Mexico, Belize, El Salvador, Honduras

Belize touches: Mexico, Guatemala

El Salvador touches: Guatemala, Honduras

Honduras touches: Guatemala, El Salvador, Nicaragua

Nicaragua touches: Honduras, San Jose

San Jose touches: Nicaragua, Panama

Panama touches: San Jose, Columbia

Columbia touches: Venezuela, Brazil, Peru, Ecuador, Panama

Venezuela touches: Columbia, Brazil, Guyana

Guyana touches: Venezuela, Brazil, Suriname

Suriname touches: Guyana, Brazil, French Guiana

French Guiana touches: Suriname, Brazil

Brazil touches: Columbia, Venezuela, Guyana, Suriname, French Guiana, Peru, Bolivia, Paraguay, Argentina, Uruguay

Ecuador touches: Columbia, Peru

Peru touches: Ecuador, Columbia, Brazil, Bolivia, Chile

Bolivia touches: Peru, Brazil, Paraguay, Argentina, Chile

Chile touches: Peru, Bolivia, Argentina

Paraguay touches: Bolivia, Brazil, Argentina

Argentina touches: Chile, Bolivia, Paraguay, Brazil, Uruguay

Uruguay touches: Argentina, Brazil

The Bahamas touches:

Cuba touches:

Jamaica touches:

Haiti touches: Dominican Republic

Dominican Republic touches: Haiti

Puerto Rico touches:

Saint Kitts and Nevis touches:

Montserrat touches:

Guadeloupe touches:

Dominica touches:

Martinique touches:

Saint Vincent touches:

Barbados touches:

Trinidad and Tobago touches:

Greenland touches:

Azores touches:

Falkland Islands touches:

South Georgia touches:

Cape Verde touches:

Madeira Island touches:

Canary Islands touches:

Faroe Islands touches:

Republic of Ireland touches: United Kingdom

United Kingdom touches: Republic of Ireland

Svalbard touches:

Norway touches: Sweden, Finland, Russia

Sweden touches: Norway, Finland

Finland touches: Sweden, Norway, Russia

Russia touches: Norway, Finland, Estonia, Latvia, Belarus, Ukraine, Turkey, Armenia, Azerbaijan, Kazakhstan, China, Mongolia, North Korea

Denmark touches: Germany

Estonia touches: Russia, Latvia

Latvia touches: Estonia, Russia, Belarus, Lithuania

Lithuania touches: Latvia, Belarus, Poland

Belarus touches: Lithuania, Latvia, Russia, Ukraine, Poland

Germany touches: Luxembourg, Belgium, Netherlands, Denmark, Poland, Czech Republic, Austria, Liechtenstein, Switzerland, France

Netherlands touches: Germany, Belgium

Belgium touches: France, Netherlands, Germany, Luxembourg

Luxembourg touches: France, Belgium, Germany

Poland touches: Germany, Lithuania, Belarus, Ukraine, Slovakia, Czech Republic

Ukraine touches: Slovakia, Poland, Belarus, Russia, Romania, Moldova, Hungary

Czech Republic touches: Germany, Poland, Slovakia, Austria

Slovakia touches: Austria, Czech Republic, Poland, Ukraine, Hungary

Moldova touches: Ukraine, Romania

Romania touches: Hungary, Ukraine, Moldova, Bulgaria, Serbia

Hungary touches: Austria, Slovakia, Ukraine, Romania, Serbia, Croatia, Slovenia

Austria touches: Liechtenstein, Germany, Czech Republic, Slovakia, Hungary, Slovenia, Italy, Switzerland

Liechtenstein touches: Switzerland, Germany, Austria

France touches: Belgium, Luxembourg, Germany, Switzerland, Italy, Spain

Switzerland touches: France, Germany, Liechtenstein, Austria, Italy

Slovenia touches: Italy, Austria, Hungary, Croatia

Croatia touches: Slovenia, Hungary, Serbia, Bosnia and Herzegovina

Bosnia and Herzegovina touches: Croatia, Serbia, Montenegro

Serbia touches: Bosnia and Herzegovina, Croatia, Hungary, Romania, Bulgaria, Macedonia, Albania, Montenegro

Bulgaria touches: Serbia, Romania, Turkey, Greece, Macedonia

Montenegro touches: Bosnia and Herzegovina, Serbia, Albania

Albania touches: Montenegro, Serbia, Macedonia, Greece

Macedonia touches: Albania, Serbia, Bulgaria, Greece

Italy touches: France, Switzerland, Austria, Slovenia

Spain touches: Portugal, France

Portugal touches: Spain

Greece touches: Albania, Macedonia, Bulgaria, Turkey

Turkey touches: Greece, Russia, Armenia, Azerbaijan, Iran, Iraq, Syria, Bulgaria

Malta touches:

Cyprus touches:

Armenia touches: Turkey, Russia, Azerbaijan, Iran

Azerbaijan touches: Turkey, Armenia, Russia, Iran

Kazakhstan touches: Russia, China, Uzbekistan, Turkmenistan

Mongolia touches: China, Russia

North Korea touches: China, Russia, South Korea

South Korea touches: North Korea

China touches: Afghanistan, Uzbekistan, Kazakhstan, Russia, Mongolia, North Korea, Vietnam, Laos, Myanmar, India, Bhutan, Nepal, Kashmir

Uzbekistan touches: Kazakhstan, China, Afghanistan, Turkmenistan

Afghanistan touches: Iran, Turkmenistan, Uzbekistan, China, Kashmir, Pakistan

Turkmenistan touches: Kazakhstan, Uzbekistan, Afghanistan, Iran

Iran touches: Iraq, Turkey, Azerbaijan, Armenia, Turkmenistan, Afghanistan, Pakistan

Iraq touches: Jordan, Syria, Turkey, Iran, Kuwait, Saudi Arabia

Syria touches: Lebanon, Turkey, Iraq, Jordan, Israel

Lebanon touches: Israel, Syria

Israel touches: Egypt, Lebanon, Syria, Jordan

Jordan touches: Israel, Syria, Iraq, Saudi Arabia

Saudi Arabia touches: Jordan, Iraq, Kuwait, Qatar, United Arab Emirates, Oman, Yemen

Kuwait touches: Iraq, Saudi Arabia

Qatar touches: Saudi Arabia

United Arab Emirates touches: Saudi Arabia, Oman

Oman touches: Saudi Arabia, United Arab Emirates, Yemen

Yemen touches: Saudi Arabia, Oman

Pakistan touches: Iran, Afghanistan, Kashmir, India

Kashmir touches: Pakistan, Afghanistan, China, India

India touches: Pakistan, Kashmir, Nepal, Bhutan, Myanmar, Bangladesh, China

Nepal touches: India, China

Bhutan touches: India, China

Bangladesh touches: India, Myanmar

Sri Lanka touches:

Adaman and Nicobar Islands touches:

Myanmar touches: Bangladesh, India, China, Laos, Thailand

Thailand touches: Myanmar, Laos, Cambodia, Malaysia

Laos touches: Myanmar, China, Vietnam, Cambodia, Thailand

Vietnam touches: Laos, China, Cambodia

Cambodia touches: Thailand, Laos, Vietnam

Malaysia touches: Thailand, Brunei, Indonesia

Brunei touches: Malaysia

Phillipines touches:

Indonesia touches: Malaysia, Papua New Guinea

Papua New Guinea touches: Indonesia

Australia touches:

Tasmania touches:

Japan touches:

Guam touches:

Solomon Islands touches:

Vanuatu touches:

Fiji touches:

New Caledonia touches:

New Zealand touches:

Kerguelen Island touches:

Heard Island touches:

Mauritius touches:

Reunion touches:

Mayotte touches:

Comoros touches:

Madagascar touches:

Sao Tome touches:

Bioko touches:

Egypt touches: Libya, Israel, Sudan

Libya touches: Algeria, Tunisia, Egypt, Sudan, Chad, Niger

Tunisia touches: Algeria, Libya

Algeria touches: Western Sahara, Morocco, Tunisia, Libya, Niger, Mali, Mauritania

Morocco touches: Western Sahara, Algeria

Western Sahara touches: Morocco, Algeria, Mauritania

Mauritania touches: Western Sahara, Algeria, Mali, Senegal

Senegal touches: The Gambia, Mauritania, Mali, Guinea, Guinea-Bissau

The Gambia touches: Senegal

Guinea-Bissau touches: Senegal, Guinea

Guinea touches: Guinea-Bissau, Senegal, Mali, Cote D'Ivoire, Liberia, Sierra Leone

Sierra Leone touches: Guinea, Liberia

Liberia touches: Sierra Leone, Guinea, Cote D'Ivoire

Cote D'Ivoire touches: Liberia, Guinea, Mali, Burkina Faso, Ghana

Mali touches: Senegal, Mauritania, Algeria, Niger, Burkina Faso, Cote D'Ivoire, Guinea

Burkina Faso touches: Mali, Niger, Benin, Togo, Ghana, Cote D'Ivoire

Ghana touches: Cote D'Ivoire, Burkina Faso, Togo

Togo touches: Ghana, Burkina Faso, Benin

Benin touches: Togo, Burkina Faso, Niger, Nigeria

Niger touches: Burkina Faso, Mali, Algeria, Libya, Chad, Nigeria, Benin

Nigeria touches: Benin, Niger, Chad, Cameroon

Chad touches: Niger, Libya, Sudan, Central African Republic, Cameroon, Nigeria

Sudan touches: Chad, Libya, Egypt, Eritrea, Ethiopia, Kenya, Uganda, Democratic Republic of the Congo, Central African Republic

Eritrea touches: Sudan, Djibouti, Ethiopia

Djibouti touches: Ethiopia, Eritrea, Somalia

Ethiopia touches: Sudan, Eritrea, Djibouti, Somalia, Kenya

Somalia touches: Kenya, Ethiopia, Djibouti

Kenya touches: Uganda, Sudan, Ethiopia, Somalia, Tanzania

Uganda touches: Democratic Republic of the Congo, Sudan, Kenya, Tanzania, Rwanda

Democratic Republic of the Congo touches: Cabinda, Congo, Central African Republic, Sudan, Uganda, Rwanda, Burundi, Zambia, Angola

Central African Republic touches: Cameroon, Chad, Sudan, Democratic Republic of the Congo, Congo

Cameroon touches: Nigeria, Chad, Central African Republic, Congo, Gabon, Equatorial Guinea

Equatorial Guinea touches: Cameroon, Gabon

Gabon touches: Equatorial Guinea, Cameroon, Congo

Congo touches: Gabon, Cameroon, Central African Republic, Democratic Republic of the Congo, Cabinda

Rwanda touches: Democratic Republic of the Congo, Uganda, Tanzania, Burundi

Burundi touches: Democratic Republic of the Congo, Rwanda, Tanzania

Tanzania touches: Burundi, Rwanda, Uganda, Kenya, Mozambique, Malawi, Zambia

Cabinda touches: Congo, Democratic Republic of the Congo

Angola touches: Democratic Republic of the Congo, Zambia, Namibia

Zambia touches: Angola, Democratic Republic of the Congo, Tanzania, Malawi, Mozambique, Zimbabwe, Botswana, Namibia

Malawi touches: Zambia, Tanzania, Mozambique

Mozambique touches: Zimbabwe, Zambia, Malawi, Tanzania, South Africa, Swaziland

Zimbabwe touches: Namibia, Zambia, Mozambique, South Africa, Botswana

Botswana touches: Namibia, Zambia, Zimbabwe, South Africa

Namibia touches: Angola, Zambia, Zimbabwe, Botswana, South Africa

South Africa touches: Namibia, Botswana, Zimbabwe, Mozambique, Swaziland, Lesotho

Swaziland touches: South Africa, Mozambique

Lesotho touches: South Africa

入力に引用符が含まれていますか?
Loovjo

無効な入力に対して何をすべきですか?(最適化のための場所を開くものであれば何でもいいのですが)
yo

2
たとえば、技術的には、フランスはカリブ海のセントマーチン島でオランダに触れ、メリリャとセウタはアフリカ本土のスペインの飛び地であり、スペインはナミビア、ボツワナ、ザンビア、ジンバブエの4点であるモロッコに触れますサンマリノ、モナコ、バチカンが完全に欠落しているなど、実際には100メートル離れた2つのトライポイントがあります。しかし、これは課題に関連するとは思いません。地理的に正しい出力を生成しますが、アルゴリズムが機能することを示します。
-Christallkeks

1
Mathematica
ビルトインと

1
@NBZ通常は同意しますが、実際にはカントリーグラフの構造が非常に大きいため、エンコードと実際のコードの間の非常に興味深い相互作用になります。これからグラフ理論と最適化について多くのことを学びました。それが単なる国のインプットを備えたプログラムであったなら、私はずっと前に退屈していたでしょう。Perlでは、展開はただ%r=map%$_,%rです。
トンホスペル16年

回答:


15

Perl、1509 1496 1392 1389 1386 1251 1248 1246 1241バイト

+2を含む -na

国とSTDINのカウントで実行します。例えば perl -na countries0.pl <<< "The Gambia 4"

ファイルcountries.pl

$_=unpack"B*","\xf4\xb5\xd4\x9b\xd1\x72\xec\x72\xb1\xdd\x51\x9d\xe6\xa5\x92\xd2\xd3\xc9\x0d\xdd\xcd\x23\x47\x5c\xb4\x56\x93\x92\x36\x51\x8d\x05\x68\xf2\x2c\x33\x75\x98\x8a\xbc\xb7\xaf\x56\x73\x55\x15\x64\xbb\x2f\x4d\x8a\x30\xe2\xda\x26\xb1\xdb\xe4\xbb\xf9\x34\x74\xb9\xce\xce\xf4\x78\x2f\x37\x8e\x8d\x8f\xdc\xcb\x5e\x7f\x8a\xc1\x29\xcd\xe3\x9e\xbd\x2e\x28\x90\xd3\xce\xd8\xb4\x29\x4d\xb8\x93\xd5\x77\x9a\x29\x3f\x65\xa2\xcc\x9c\x66\x9a\x8c\x46\xb3\x39\xb3\x8f\x92\xec\xb8\xff\xda\x58\x56\x24\x92\x52\x5c\x9e\x0b\x49\x30\xe4\xa9\xa8\xc9\xf7\xef\x12\x65\x85\xb4\x51\x1c\x5b\x24\xa2\x65\xa3\x59\x71\x94\x45\xd4\xff\xf9\xf4\x70\xce\x35\x26\x8a\x30\xe5\xda\x34\x34\x49\x25\x45\x04\x94\x53\x51\x57\x5f\xfe\x69\x1c\x51\x95\x60\x93\xe4\xde\x29\xc2\x78\x68\xaa\xb2\x69\x41\xc3\x58\x32\x01\x72\xd1\xcf\x54\x08\x03\x33\xca\x2c\xcc\xdb\xa0\x26\x43\x34\x9a\x1a\x24\x5d\x03\x24\x1d\x5a\x71\x00\xa4\x98\xd1\xbe\x07\x66\xdb\x26\x91\x90\x3b\xbb\x0d\xf2\x68\x68\x91\x03\xa5\xa5\x92\x06\x64\x36\x5d\xa8\x05\x36\x49\xe1\xa1\xa9\xda\x89\xa0\x28\xdd\x49\x23\xb2\x68\x0d\x4e\xf4\x4d\x01\x36\xcf\x53\xa5\xc0\xa6\xd1\x3c\x90\x0b\x26\xcc\x12\xe4\xe8\x2c\xb4\x1a\x93\x63\x44\xdc\x05\xa3\x69\xa9\xd2\xe0\xb0\xe8\x1b\x81\x8d\xa3\xec\x10\x06\xd2\xe1\x87\x24\xf4\x72\xb2\x41\x49\xf4\x6d\xb5\x01\xd0\xe5\x72\x4d\xa8\x0e\x37\x34\x1d\xa8\x06\x67\xa9\xb5\x31\x44\x8a\x06\x93\x5f\x2d\x65\x76\x4d\x00\xb9\x26\x4f\x9c\x83\x40\x71\xf2\xe1\xa0\x70\x17\x21\xa2\x44\x0e\x64\x33\x8b\x2d\x40\x1a\x69\xd5\x1b\x70\x47\x29\x1c\x93\x2d\x37\x20\x8e\x42\x2c\xae\x80\x0d\x86\x69\xd1\x36\xa0\x3b\xb9\x0a\x49\x07\x43\x95\xd3\xd6\xa0\x3b\x26\xb2\xd4\x03\x73\x1a\x26\xd4\x04\x69\xc9\x0b\x29\xb5\x01\x40\xb2\x89\xb5\x01\x2e\x8f\x29\xb5\x01\x3f\x36\x96\x4c\x80\x5a\x26\x91\xa0\x19\x20\xd1\xb3\xe8\x13\x96\xee\x97\x02\xac\x90\xd1\x22\x00\x68\x35\xda\x80\x1c\xdb\xe8\xc9\x36\xe8\xe8\x90\x51\xb1\x92\x6d\x40\x51\xf2\x6b\x29\x67\x51\x20\x64\xc3\xaa\x36\xd4\x06\x9b\x29\x72\x40\xee\x66\x33\x43\xd9\x6c\xa8\x02\xd3\xd6\xe8\xe8\x90\x26\x45\xa0\x40\xd9\xf7\xb6\xa0\x2c\xda\x24\x1d\xa2\x60\xec\xf6\x40\x61\xa6\x3a\x24\x09\xcb\x46\x68\x7b\x2d\x95\x01\x37\xb2\x5e\xb7\x47\x44\x83\xd4\x7d\x3c\x6e\x8e\x89\x05\x15\xa3\x51\x36\xe8\xe8\x90\x0e\x6d\xf4\xae\x0f\x53\xa6\x8d\x9a\x08\xe5\x3a\xc8\x6d\x40\x7a\x7b\xa5\x86\x0a\xd0\x74\x68\x2c\x91\x5a\x80\xe1\xac\x9a\x02\xcd\xa5\x40\x9b\x72\x8d\xa6\xa7\x40\x32\x89\xd0\x68\x29\x74\xc0\x9a\x6c\x39\x0a\x14\x6d\x19\x09\x46\xcd\xa0\xe5\xd0\x2e\xd2\x1a\x69\x10\x5e\x51\x92\x41\xdb\xb6\xd4\x06\x63\x44\x83\xb4\x98\xad\x0a\x36\x8c\xb5\x00\xec\xb4\x54\x48\x04\xeb\x33\x33\x1d\x80\x19\x32\x89\xca\x40\x19\x77\x23\x36\x41\x1b\xd1\x31\xa3\x40\x1a\x67\xa0\x36\x52\x29\xb6\x9d\x07\x29\x16\x64\x56\xa0\x2d\xd6\xd2\x41\x04\x83\x0e\xd0\x2b\xa0\xb2\xd0\x77\x74\x7d\x83\x44\x88\x1d\xcc\x68\x1b\x50\x1d\xcc\xc6\x68\x51\x4d\xb7\x28\x09\x36\xc3\x6c\xa8\x07\xda\x2c\xa3\x37\x20\x48\x66\xb6\x4b\x6a\x02\x39\x7d\x22\xcb\x56\x72\x07\xa4\x9b\xd0\x0c\x90\x6c\xf9\x00\x66\xa5\x83\x44\x88\x1a\x9d\x07\x28\xd0\x34\x03\x32\x3e\xee\x89\xa0\x13\x48\xd9\x96\xa0\x25\xab\x94\x60\x8d\x03\x4d\xd8\x0f\xa4\x59\x6a\x00\x74\x4b\xe8\x9b\x50\x1d\x98\xa8\x90\x51\x3a\xc8\x68\x09\xea\x89\x15\x00\xdd\xd1\x22\xa0\x19\x36\xcd\x22\xb0\x18\xd9\xa6\x56\x04\x64\x7b\x73\x20\x8d\x03\x4b\xf6\xd4\x07\x28\xcb\x24\x54\x00\x6c\xcb\xd0\x03\x9a\x6d\xdb\x50\x02\x94\x73\xc6\xd0\x76\xe4\x0f\x8c\xab\x03\x34\xa1\xcc\xa7\x59\x07\x0d\x41\x03\x92\x48\xdb\x40\xc2\x8a\x6d\xb9\x44\xc0\xe0\x4d\xb5\x26\xda\x80\x4d\xb5\x26\x82\x81\xd4\x9b\x6a\x02\x39\x6e\x79\xcc\x83\x72\xe8\xe4\xd4\xc3\xb4\x35\x1b\x40\x32\x49\xb2\x41\x1a\x4d\xb6\x1d\x13\x6a\x02\x64\xe9\x28\x0b\x24\x59\x4c\xbb\x6a\x03\x99\x4e\xb2\x06\x4d\xbe\xb2\x69\x05\x53\xb9\x04\x68\x1b\x03\x94\x8c\x9b\x9c\xa4\x03\xce\xb2\x0d\x51\x99\x48\x34\x6a\x26\x80\xe6\x47\x28\x09\x16\x5e\x6c\xd9\x03\xb2\x4c\xb5\x40\x80\x36\x64\x9b\x6a\x03\x53\xb2\x65\x40\x1a\x96\x1d\x81\x34\xd8\x72\x14\x3d\x64\xe8\x59\x88\x39\x44\xd0\x54\x01\x68\x59\xd2\x09\x96\xe1\xa9\xd9\x32\xa0\x35\x3b\x26\x54\xfb\x2d\xde\xd2\x60\x3e\x32\xa8\x59\xb2\x0d\x12\x20\x0b\x31\xb2\x6d\xca\x26\x07\x04\xab\x3a\x0f\x2d\xb5\x03\x0d\x4e\xc9\x95\x01\xdb\x49\xad\xa4\x03\x2c\xa6\x40\x19\xa5\x0d\x52\x2c\xb5\x00";s/.{5}/pack b5,$&/ge;s#\G[^\x00]??#${$.+=$&gt$_}{$t=$.+ord(O&$&)}&=\$$t{$.}#eg;y//\n '_-z-/c;s/\b./\u$&/g;s/X/republic/g;y/_`/ /d;print+(/$|.+\n/mg)[eval'%r=map%$_,$l+=s/^@F$//m*$`=~y/\n//,'x pop@F]

これはそのまま機能しますが、指定された長さを取得するには、エスケープされたすべてのバイトを対応するリテラルバイトに置き換える必要があります。たとえば、次の方法で実行できます。

perl -p0e 's/\\n/\n/g;s/"\\x.*?"/"\x27".eval($&)."\x27"/ges;s/\s+$//' < countries.pl > countries0.pl

説明

最初に、いくつかの変換が削除されたプログラムを表示しましょう。

$_ = unpack"B*", "touches\0names";
s{.{5}}{pack b5,$&}ge;
s{\G[^\x00]??}{
    # The next 3 lines were: ${$.+=$&gt$_}{$t=$.+ord(O&$&)}&=\$$t{$.}
    $. += $& gt $_;
    $t = $. + ord(O&$&);
    ${$t}{$.} = ${$.}{$t} = "";
}eg;
tr//\n '_-z-/c;
s/\b./\u$&/g;
s/X/Republic/g;
y/_`/ /d;
print +(/$|.+\n/mg)[eval'%r=map%$_,%r,s/^@F$//m*$`=~y/\n//;'x pop@F]

基本的な考え方は、3つの主要なデータ構造を持つことです。

  • @countriesすべての国を含む配列
  • 2つのレベルハッシュ%touchesにおけるインデックスの@countries配列は、それが$touches{$i}{$j}存在する場合にのみ$countries[$i]触れます$countries[$j]
  • %reachable現在検討中のレイヤーで到達可能なすべての国のインデックスのキーを持つワーキングセットハッシュ。

アルゴリズムは次のとおりです。

  • で対象国のインデックスを検索し、@countriesそれを使用して初期化します%reachable
  • 多くのレイヤーが要求されるため:
    • 各キー$r%reachable検索して$touches{$r}、そこにあるすべてのキーを収集します
    • 収集したすべてのキーをに追加します%reachable。これはハッシュなので、重複は削除されます
  • 最後に、で蓄積されたすべてのインデックスを使用し%reachableて、対応する国を@countries印刷しますが、元の対象国は印刷しません

ここで、シンプルさが終わり、ゴルフが始まります。

  • @countriesそれはメモリで簡単に作成されているが、配列は、名前で存在することはありません
  • %reachableハッシュは名前が付けられます。%r
  • %touchesハッシュは、明示的に存在しません。代わりに、perlグローバル名前空間を使用します。たとえば、国6が国3に接触し、国12がハッシュ%6で表されます。(3 => undef, 12 => undef)
  • 結果の最終的なルックアップは原則的@countries[keys %reachable]には行われますがkeys、代わりにを書きたくありません@countries[%reachable]。しかし、インデックス0になる値%reachableが含まundefれるため、インデックス1で実際の国リストを開始し、インデックス0に空の文字列を入れます。その空の文字列を印刷することはできません。また、対象国が空の文字列に置き換えられることを確認します。そして最後に、各国には最後にまだ改行があります。最終出力が単純になることをすべて知っているprint @countries[%reachable]。この時点で国が存在することを除いて、$_実際のコードはprint+(/$|.+\n/mg)[%r]です。正規表現は、空行が改行を取得しないようにし、完全な国名は取得するようにします。
  • 触れる国%reachableは原則としてを使用して取得できますmap keys %{$touches{$_}},keys %reachable。しかし、これkeysは、.defなしで取得するundef値を適切に処理するように注意する場合は必要ありませんkeys。メイングロブを使用して値を保存する前に言ったように、実際のコードフラグメントはmap%$_,%rです。返される値のそれぞれを、として実行できる新しいキーとして追加%r%r=map%$_,%rます。ただし、これには、起点レイヤーがセットに残るように、各国が自分自身を触れていると呼ぶ必要があります。このコードは、ユーザーがレイヤーを要求した回数だけ繰り返す必要があります。これはプログラムの実際のコアであり、他のすべてはこれをサポートするためのノイズであることに注意してください。
  • コア操作は、ユーザーがレイヤーを要求した回数だけ繰り返す必要があります。これを行う便利な方法は、コアコードを含む文字列を数回作成して評価することです。-aオプションが層の数を集めたので、@Fこれの最後の要素がを使用して達成できるのでeval '%r=map%$_,%r;' x pop @F。これは一般にperlでループする最短の方法ではありませんが$_、ループ中に変化しないという利点があります。これは後で使用します。STDINでの独自の行に層数を置くことは私が代わってしまうx pop@Fことにより、x<>4つのバイトを保存するが、私は可能な限り仕様の近くに残るしたいと思います。
  • pop @F削除後、レイヤー@Fには開始国名が含まれます。名前にスペースが含まれる国は、コンポーネント部分に分割されることに注意してください。を実行することで、大きな国の文字列でターゲットを検索し$_、すぐにターゲットの国をemty文字列に置き換えることができます(したがって、印刷されません)s/^@F$//m。名前にスペースが含まれる国は、@F補間によって再構築されることに注意してください。また、一部の国が他の部分文字列であるため、これは慎重に固定しなければならないことを通告、例えばGuineaおよびGuinea-BissauまたはNigerおよびNigeria
  • 対象国のインデックスは、との一致の前に改行を数えることで見つけることができます$'=~y/\n//。対象国が見つからない場合、$`以前の正規表現の値が含まれている可能性があり、これは非常に間違っている可能性があります。代わりに、0(空の文字列があるインデックス)が必要です。これは、前の一致と組み合わせることで達成できますs/^@F$//m*$`=~y/\n//
  • 実際、この式をマップへの追加引数としてevalに移動して、初​​期化する必要なくターゲット国のインデックスをループに追加できます%reachable。evalはになりeval '%r=map%$_,%r,%r,s/^@F$//m*$`=~y/\n//;' x pop@F;ます。置換によってターゲット国が破棄される$_ため、最初に追加されるだけです(ターゲット国インデックスは%reachableとにかくすでに存在しているため、そうでない場合は問題になりません)
  • evalはハッシュ%rを返すので、これを組み合わせprint+(/$|.+\n/mg)[%r]て実際のコードに到達できますprint+(/$|.+\n/mg)[eval'%r=map%$_,%r,s/^@F$//m*$`=~y/\n//;'x pop@F]

次の質問は、カントリーリストをエンコードする方法です。上で説明したように、改行で終了し、単一の改行で始まる国の巨大な文字列としてそれが欲しいです。このために、26文字、スペース、改行、-Guinea-Bissau)および'Cote D'Ivoire)が必要です。問題は、文字が大文字である場合があることです。これは、単語の境界の後の最初の文字を大文字にして簡単に解決できます。ただし、例外があります:Republic of IrelandBosnia and HerzegovinaおよびDemocratic Republic of the Congo。これらには大文字で始まらない単語があります。その前のスペースをアンダースコア_に置き換えて単語の境界として認識されないようにし、後で_スペースで置き換えることで対応できます。残っている例外はUSA単語の境界上にない大文字があります。そのために、このように書くことで単語の境界を導入u`s`aし、後で逆引用符を削除します。一緒に与えること:

s/\b./\u$&/g;            Uppercase the first letter of each word
tr/_`/ /d;               Replace "_" by " ", remove "`"

このコードで、私は使用して全体の国の文字列をエンコードすることができa-z'-\n_および`32種類の文字です。したがって、各文字は5ビットでエンコードできます。実際、巨大なビット文字列がある場合は11110100111...、次を使用して必要な文字に変換できます。

s{.{5}}{pack b5,$&}ge;     Convert each 5 bits to a character in the range
                           \x00 to \x1f.
tr//\n '_-z-/c;            Convert characters in the range \x00 to \x1f to our
                           target characters. _-z is conveniently equivalent to
                           _`a-z. Put \n first so that "00000" converts to
                           newline (will be used later). The c modifier
                           complements the empty source range thereby giving
                           all characters (of which only 32 are used)

バイト文字列がある$_場合、必要な巨大なビット文字列はを使用して作成できます$_ = unpack"B*"。したがって、基本的にこれは小さなベース256からベース32へのコンバーターであり、各国の文字は着信バイナリ国文字列の5ビットを使用してエンコードされます。これは比較的コンパクトでありRepublic、5つの国名に表示される1つの例外を除いて、国リストで繰り返される文字列の特別なコードを開発することはできません。常に完全な単語として表示され、国名がX(そのような文字のみ)で始まることはないため、国名の最初の文字が大文字になった後、エスケープコードとして使用できます。

s/X/Republic/g;        Save 7 bytes by explicitely encoding Republic

ここで、「タッチ」関係をエンコードする方法が必要です。最初に気づくのは、それが対称であるため、国$nが国$tに触れると、国$tも国に触れることです$n。したがって、%touches両方の方法でハッシュを入力する場合にのみ、関係の半分をエンコードする必要があります。簡略化されたコードでは、次のことが行われていることがわかります。

${$n}{$t} = "";           Update the main glob to say $n touches $t
${$t}{$n} = "";           Update the main glob to say $t touches $n

カウンターを0ではなく1から開始するため、実際のコードでは$.なくを使用し$nます(国0はダミーの空の文字列です)。アイデアは、国のインデックスのシーケンス書くことである| A, B, C | D, E | .. インデックスを持つ国1タッチの国を言いABそしてC、国2つのタッチインデックスDE実際、現在の国からのオフセット(後で値を小さくするために使用します)と正のオフセットのみをエンコードします(これにより、「タッチ」関係が一方向にのみエンコードされ、使用する方法はとにかく負の数を処理しないでください)。タッチ関係は他の国から既に与えられているため、一部の国では隣人の空のリストがあります。国リスト(順序が関係ない)をリストの最後に来るように再配置できます。その後、これらの国をシーケンスから除外できます。「タッチ」リレーションと同じ数のオフセットが必要なので、これは何も得られませんが、ダミーオフセットをエンコードすることでバイトの損失を防ぎます。上で説明したように、国0はダミーの空の文字列なので、スキップされることを確認する必要があります。この数値のシーケンスを、バイト値がインデックスオフセットに対応するバイトのシーケンスとして書き込むことができます。ただし、シーケンス内の次の国がどこから始まるかを知る必要があります(|上記の例のs)。これを行うには、特定の国のtouchesリストの最初のインデックスに上位ビットを1に設定します。これにより、インデックスAおよびD上記の例になります。

しかし、厄介な問題が1つあります。127か国以上です。そのため、文字記号ビットだけを使用することはできません。代わりに、私は、すべての国がそれが触れるすべての国から15の位置から遠くなることは決してないような国の配置を見つけました:

Chile                           : [9 11 15] []
Portugal                        : [7] []
Luxembourg                      : [2 12 15] []
Netherlands                     : [1 14] []
Belgium                         : [10 13] [-2 -1]
Denmark                         : [12] []
Suriname                        : [4 6 14] []
Switzerland                     : [7 10 12 14 15] []
Spain                           : [6] [-7]
Bolivia                         : [2 6 9 11] [-9]
French Guiana                   : [10] [-4]
Argentina                       : [2 7 9] [-11 -2]
Guyana                          : [8 14] [-6]
Uruguay                         : [7] [-2]
France                          : [3 5] [-12 -10 -7 -6]
Peru                            : [1 5 14] [-15 -6]
Ecuador                         : [13] [-1]
Germany                         : [4 5 10 11] [-15 -14 -13 -12 -10 -3]
Paraguay                        : [2] [-9 -7]
Italy                           : [3 4] [-12 -5]
Brazil                          : [6 9] [-14 -11 -10 -9 -8 -7 -5 -2]
Liechtenstein                   : [1] [-14 -4]
Austria                         : [1 5 8 13] [-15 -5 -3 -1]
Slovenia                        : [1 7] [-4 -1]
Croatia                         : [1 6 12] [-1]
Bosnia and Herzegovina          : [6 11] [-1]
Venezuela                       : [3] [-14 -6]
Czech Republic                  : [1 8] [-10 -5]
Poland                          : [5 7 13 15] [-11 -1]
Columbia                        : [13] [-14 -13 -9 -3]
Hungary                         : [5 6 7 11] [-8 -7 -6]
Montenegro                      : [5 8] [-6]
Moldova                         : [5 9] []
Lithuania                       : [10 13] [-5]
Sweden                          : [10 11] []
Slovakia                        : [6] [-13 -8 -7 -5]
Serbia                          : [1 2 3 14] [-12 -11 -6 -5]
Romania                         : [4 13] [-7 -5 -1]
Macedonia                       : [1 12 13] [-2]
Albania                         : [12] [-8 -3 -1]
Estonia                         : [6 15] []
Ukraine                         : [2 14] [-13 -11 -9 -6 -4]
Panama                          : [15] [-13]
Belarus                         : [3 12] [-15 -10 -2]
Norway                          : [1 11] [-10]
Finland                         : [10] [-11 -1]
Latvia                          : [9] [-13 -6 -3]
Turkmenistan                    : [9 13 14 15] []
Armenia                         : [1 7 8 15] []
Azerbaijan                      : [6 7 14] [-1]
Bulgaria                        : [1 13] [-14 -13 -12]
Greece                          : [12] [-13 -12 -1]
South Korea                     : [7] []
Pakistan                        : [3 9 11 15] []
Nepal                           : [14 15] []
Russia                          : [4 6 8 10 14] [-15 -14 -12 -11 -10 -9 -7 -6]
Iran                            : [6 7 14] [-9 -8 -7 -3]
San Jose                        : [14] [-15]
Bhutan                          : [10 11] []
North Korea                     : [10] [-7 -4]
Uzbekistan                      : [1 2 9] [-13]
Kazakhstan                      : [8] [-14 -6 -1]
Afghanistan                     : [2 7] [-15 -9 -6 -2]
Turkey                          : [7 13] [-15 -14 -13 -12 -8 -7]
Kashmir                         : [4 5] [-11 -2]
Mongolia                        : [4] [-10]
Kuwait                          : [4 12] []
Qatar                           : [11] []
India                           : [1 4 15] [-15 -14 -10 -4]
China                           : [5 14 15] [-15 -14 -11 -10 -9 -8 -7 -5 -4 -1]
Iraq                            : [6 8 9] [-14 -7 -4]
Nicaragua                       : [14] [-14]
Bangladesh                      : [11] [-4]
United Arab Emirates            : [4 5] []
Vietnam                         : [10 12] [-5]
Yemen                           : [2 3] []
Syria                           : [3 5 11] [-13 -6]
Oman                            : [1] [-4 -2]
Saudi Arabia                    : [1] [-12 -11 -8 -5 -3 -1]
Jordan                          : [8] [-9 -3 -1]
Djibouti                        : [10 12 14] []
Lebanon                         : [6] [-5]
Lesotho                         : [9] []
Myanmar                         : [1 15] [-15 -14 -11]
Laos                            : [2 14] [-15 -10 -1]
Honduras                        : [3 14] [-14]
Cambodia                        : [12] [-12 -2]
Israel                          : [15] [-11 -8 -6]
El Salvador                     : [11] [-3]
Swaziland                       : [2 6] []
Somalia                         : [4 6] [-10]
South Africa                    : [2 4 9 10] [-9 -2]
Eritrea                         : [2 14] [-12]
Zimbabwe                        : [2 7 8 11] [-2]
Ethiopia                        : [2 12] [-14 -4 -2]
Mozambique                      : [8 9 10] [-6 -4 -2]
Kenya                           : [9 10 12] [-6 -2]
Belize                          : [2 15] []
Thailand                        : [15] [-15 -14 -12]
Guatemala                       : [13] [-14 -11 -2]
Botswana                        : [1 4] [-9 -7]
Namibia                         : [3 6] [-10 -8 -1]
Egypt                           : [4 13] [-15]
Malawi                          : [1 2] [-8]
Zambia                          : [1 3 13] [-11 -9 -4 -3 -1]
Tanzania                        : [3 4 5] [-10 -9 -2 -1]
Sudan                           : [2 9 11 12 13] [-14 -12 -10 -4]
Angola                          : [10] [-6 -3]
Uganda                          : [1 9] [-12 -3 -2]
Rwanda                          : [1 8] [-4 -1]
Burundi                         : [7] [-5 -1]
Brunei                          : [2] []
Mexico                          : [15] [-15 -13]
Malaysia                        : [15] [-15 -2]
Cabinda                         : [3 15] []
Libya                           : [1 3 6 7] [-13 -9]
Tunisia                         : [6] [-1]
Democratic Republic of the Congo: [2 12] [-13 -11 -10 -9 -8 -7 -3]
Chad                            : [1 2 3 14] [-12 -3]
Central African Republic        : [10 13] [-13 -2 -1]
Nigeria                         : [1 5 12] [-2]
Niger                           : [1 4 9 10] [-6 -3 -1]
Algeria                         : [1 2 4 9] [-7 -6 -1]
Morocco                         : [1] [-1]
Western Sahara                  : [2] [-2 -1]
Benin                           : [5 8] [-5 -4]
Mauritania                      : [5 11] [-4 -2]
USA                             : [15] [-15]
Indonesia                       : [15] [-15]
Congo                           : [3 5] [-15 -12 -10]
Burkina Faso                    : [1 3 5 6] [-9 -5]
Mali                            : [5 6 8] [-10 -9 -5 -1]
Cameroon                        : [2 15] [-14 -13 -12 -3]
Togo                            : [2] [-8 -3]
Gabon                           : [13] [-5 -2]
Ghana                           : [1] [-5 -2]
Cote D'Ivoire                   : [2 3] [-6 -5 -1]
Senegal                         : [2 7 12] [-11 -6]
Liberia                         : [1 10] [-2]
Guinea                          : [5 9] [-8 -3 -2 -1]
Haiti                           : [6] []
United Kingdom                  : [4] []
Canada                          : [] [-15]
Papua New Guinea                : [] [-15]
Guinea-Bissau                   : [] [-7 -5]
Republic of Ireland             : [] [-4]
Dominican Republic              : [] [-6]
Equatorial Guinea               : [] [-15 -13]
Sierra Leone                    : [] [-10 -9]
The Gambia                      : [] [-12]

(この説明を書いている時点で、私の検索プログラムは実際に最大距離が最大12である順序を見つけました)。これは0x10、新しい国の開始を示すフラグとして使用でき、32個の異なる値をエンコードするだけでよいことを意味します。これは、国リストに必要なのと同じベース256からベース32へのコンバーターを使用して拡張するために圧縮できます。実際0x00、タッチデコーダーを記述してこれで停止する場合、タッチストリングを国間文字列の前(エンコード前)に配置でき\x00ます。国のデコーダーは0x00、最初に残されたこれが最初に必要な改行になるように作成されているため、インデックス0の国は空の文字列です。

古いバージョンのコードでは、国のグラフに接続されているコンポーネントが4つしかないという事実を使用して、国のインデックスを128未満に減らしましたが、それは非常に複雑で、コードとエンコード文字列がかなり長くなりました。

バイトシーケンスを%touchesハッシュに変換するコードは次のようになります。

s{\G[^\x00]??}{                I want to walk over the characters in $_ in
                               sequence but stop at the first \x00. \G says to
                               only match where the previous match left of and
                               is initialized to the start of the string. The
                               ?? is for non greedy matching which means it
                               prefers to match the empty string. Like this it
                               will start to match the empty string, then one
                               char, then the empty string, then the next char
                               etc. In the code below you can see that the
                               empty string becomes an offset of 0 without
                               advancing the country, which means each country
                               gets a realtionship to itself (except for the
                               omitted final countries. This will take over
                               the role of "Add all collected keys to
                               `%reachable" in the basic algortith mentioned
                               above so we can do "%reachable = all countries
                               touch %reachable" as basic step. The exception
                               countries at the end are no problem. Their
                               neighbours are guaranteed to get a self loop
                               reference. So if the starting country is an
                               exception country it will not be in the first
                               layer, but that is no problem since we don't
                               print the starting country anyways. And layer 1
                               DOES refer to itself AND the starting country
                               so all countries will be there on all later
                               layers. If it is not the starting country but a
                               layer passes through it the preceding country
                               will keep pushing the exception country again
                               on each round, so again nothing is lost
    $. += $& gt $_             $. is used to indicate the index of the current
                               country. Add 1 to $. if the byte has bit 5 set.
                               This works because $_ will be carefully
                               constructed so it will start with "\x0f" by
                               making sure the first country has a touching
                               country at distance 15. This also imples that
                               for the first country I cannot trigger an 
                               increase. That is why $. is used as as index so
                               its value will start with 1
    $t=$.+ord(O&$&);           The touching country offset is in byte `$&`
                               which gets converted to a number and has its
                               high bit removed (O has byte code \x4f)
    ${$t}{$.} = ${$.}{$t}="";  Next the %touching hash is updated as explained
                               above. Sets the value to "" (which will behave
                               as 0 during the country lookups). This also
                               makes sure the replacement expression is ""
                               which means that the substitution as a whole
                               removes the sequence of encoded bytes
}eg

すべてのシングルトン国はまったくエンコードされていないことに注意してください。入力として使用されるため、一致しないため%reachable、最初の空の国への参照が含まれているだけで、何も印刷されません。

それでプログラム全体が説明されます。その後必要なのは、国の順序を慎重に選択することにより、巨大なエンコードされた文字列を生成するメタプログラムを書くことだけでした。

  • 空の隣人リスト(隣人に含まれる)を持つすべての国は、国リストの最後に表示されます
  • 接触しているすべての国は、お互いに15以下である
  • 最初の国にはオフセット15で隣国があります
  • エンコードされた文字列に含めることはできません'(最後の単一引用符で囲まれた文字列を無効にします)

1
非常に素晴らしい梱包、特に国名。ちょうど32文字で十分な驚くべき偶然です。
Christallkeks

5

JavaScript(ES6)、2862 2324

F=(C,N)=>`USA,,Canada,,Mexico,,Guatemala,,Belize,,El Salvador,,Honduras,,Nicaragua,,San Jose,   ,Panama,
,Columbia,,Venezuela,
,Guyana,
,Suriname,,French Guiana,
,Brazil,

,Ecuador,
,Peru,
,Bolivia,,Chile,,Paraguay,,Argentina,,Uruguay,,Haiti,,Dominican Republic,,Republic of Ireland,,United Kingdom,,Norway,,Sweden,,Finland,,Russia, !#)@ABCGDE,Denmark,$,Estonia,!,Latvia, #",Lithuania,!#(,Belarus,"!)(,Germany,'&%(*0132,Netherlands,$&,Belgium,2%$',Luxembourg,2&$,Poland,$"#)+*,Ukraine,+(#.-/,Czech Republic,$(+0,Slovakia,0*()/,,,Moldova,).,Romania,/)-87,Hungary,0+).754,Austria,1$*+/4<3,Liechtenstein,3$0,France,&'$3<=,Switzerland,2$10<,Slovenia,<0/5,Croatia,4/76,Bosnia and Herzegovina,579,Serbia,65/.8;:9,Bulgaria,7.@?;,Montenegro,67:,Albania,97;?,Macedonia,:78?,Italy,2304,Spain,>2,Portugal,=,Greece,:;8@,Turkey,?ABKLM,Armenia,@BK,Azerbaijan,@AK,Kazakhstan,GHJ,Mongolia,G,North Korea,GF,South Korea,E,China,IHCDE`_]Y[ZX,Uzbekistan,CGIJ,Afghanistan,KJHGXW,Turkmenistan,CHIK,Iran,L@BAJIW,Iraq,PM@KRQ,Syria,N@LPO,Lebanon,OM,Israel,fNMP,Jordan,OMLQ,Saudi Arabia,PLRSTUV,Kuwait,LQ,Qatar,Q,United Arab Emirates,QU,Oman,QTV,Yemen,QU,Pakistan,KIXY,Kashmir,WIGY,India,WXZ[]\,Nepal,YG,Bhutan,YG,Bangladesh,Y],Myanmar,\YG_^,Thailand,]_ab,Laos,]G`a^,Vietnam,_Ga,Cambodia,^_`,Malaysia,^cd,Brunei,b,Indonesia,be,Papua New Guinea,d,Egypt,gO|,Libya,ihf|{y,Tunisia,ig,Algeria,kjhgytl,Morocco,ki,Western Sahara,jil,Mauritania,kitm,Senegal,nltpo,The Gambia,m,Guinea-Bissau,mp,Guinea,omtsrq,Sierra Leone,pr,Liberia,qps,Cote D'Ivoire,rptuv,Mali,mliyusp,Burkina Faso,tyxwvs,Ghana,suw,Togo,vu,Benin,wuyz,Niger,utig{zx,Nigeria,xy{,Chad,yg|z,Sudan,{gf},Eritrea,|~,Djibouti,},Ethiopia,|}~,Somalia,~,Kenya,|,Uganda,|,Democratic Republic of the Congo,|,Central African Republic,{|,Cameroon,z{,Equatorial Guinea,,Gabon,,Congo,,Rwanda,,Burundi,,Tanzania,,Cabinda,,Angola,,Zambia,,Malawi,,Mozambique,,Zimbabwe,,Botswana,,Namibia,,South Africa,,Swaziland,,Lesotho,,`.replace(/([^,]*),/g,(_,x)=>++i%2?a.push(x):b.push([...x].map(c=>c.charCodeAt())),i=0,a=[],b=[])&&N?new Set([for(q of b[a.indexOf(C)]||[])for(p of F(a[q],N-1))p]).add(C):new Set([C])

適切な国を含むSetオブジェクトを返します。これには大量の印刷できないものが含まれていることに注意してください。

テストスニペット(ES6準拠のブラウザーが必要)

使い方

何よりも先に、私はリストから隣人のいないすべての国を削除しました。次に、リストを次の形式に縮小しました。

  • 国の名前
  • コンマ
  • バイトとしての各ネイバーのインデックス
  • コンマ

これにより、リストは2130バイトに圧縮されます。正規表現のエラーを回避するために、コンマで表される国に空白のエントリが慎重に挿入されました。興味深い部分について:

F=(C,N)=>``.replace(/([^,]*),/g,(_,x)=>++i%2?a.push(x):b.push([...x].map(c=>c.charCodeAt())),i=0,a=[],b=[])&&N?new Set([for(q of b[a.indexOf(C)]||[])for(p of F(a[q],N-1))p]).add(C):new Set([C])

// Define a function F that takes in a country C and a number N, and returns:
F=(C,N)=>(

i=0,   // index
a=[],  // list of countries
b=[],  // list of their neighbors

// Take this big string and replace each string of non-comma chars x, followed by a comma, with this function:
``.replace(/([^,]*),/g,(_,x)=>

// If we're on an even index, push the country name to a.
++i%2?a.push(x)
// Otherwise, push the list of its char codes to b.
:b.push([...x].map(c=>c.charCodeAt()))),

// If N, the number of levels, is more than 1, return a set made out of:
N?new Set(
// For each item q in the country's neighbors, or [] if the country doesn't have any (or doesn't exist):
 [for(q of b[a.indexOf(C)]||[])
// For each item p in F(the q'th country, N - 1), take p.
  for(p of F(a[q],N-1))p]
// Add C to this set.
).add(C)

// Otherwise (if N is 0), return a set containing C.
:new Set([C]))

障害が見つかった後、リストが更新されました。変更の詳細については、改訂履歴をご覧ください。
アディソンクランプ

@VoteToCloseありがとう、修正。(1バイトかかりました!)
ETHproductions

5

JavaScript(ES6)2622 3815

セットを返す関数。反復を避けるためのセットを使用した再帰スキャン。

(読みやすくするために2つの改行が追加されました-1行にする必要があります)

なしで国を保存しないの@ETHproductionsのアイデア借り隣人を。(彼の正書法も借りて、私はいつもその言葉のつづりを間違えています)

(p,l)=>("China124b41017862692829186d7a40Russia635472421f1110343541007862Brazil23685767732b20651e87Germany5d367b8b1c3a065b2f16Democratic Republic of the Congo6e24220531474e084cSudan151a52532627310422Austria5b033a2e0a483e2fSerbia4d390a2c21433361Zambia4c040f5e1b32382aAlgeria6a79841a0d0c44Hungary062e112c073948Iran191035344a1246Mali2d44090d132517Niger130c091a154537Saudi Arabia3f197591866488Tanzania4e4731271b5e08Turkey3b0134350b1930Ukraine2e1c1f012c770aAfghanistan0b4a4b004046Burkina Faso0c0d37835625Cameroon451522245571Chad0d1a05221445France365d032f3e80Guinea742d0c255a7fIndia46407a6d296bIraq3f30100b750eLibya09845205150dMozambique32085e0f1d81Poland035c1f112e3aSouth Africa2a38321b818eArgentina5020650287Belarus5c4201111cBolivia2b02651e50Bulgaria072c103b43Central African Republic1415050424Columbia68022b6f7dCongo551422046eCote D'Ivoire5a170c1356Ethiopia0553516627Kenya310526660fLaos2900694f49Myanmar6b18002849Namibia4c0832381dPeru6f23022050Romania0a11772107Senegal94440c1774Slovakia063a1c110aSwitzerland16035b063eSyria7610193f3dUganda0405270f47Zimbabwe2a081b1d38Albania6107433bArmenia1001350bAzerbaijan1034010bBelgium167b035dBenin83130d45Botswana2a08321dCroatia480a074dCzech Republic031c2e06Greece33432110Guatemala606c7058Israel5276303fItaly162f0648Jordan3d30190eKashmir46120018Kazakhstan01004b4aLatvia72011f5cMacedonia3307213bMauritania6a090c2dNigeria370d1514Pakistan0b124018Rwanda04310f4eSlovenia3e060a39Thailand29284f5fTurkmenistan414b120bUzbekistan4100124aAngola04082aBosnia and Herzegovina390761Burundi04470fCambodia492869Chile2b201eDjibouti265366Egypt1a3d05Eritrea055126Finland826301Gabon711424Ghana251383Guyana680267Honduras3c707cIndonesia5f8f97Liberia7f1725Liechtenstein2f0306Lithuania421f1cLuxembourg163603Malawi080f1bMalaysia498959Mexico856c3cMontenegro4d0733North Korea000193Norway825401Oman0e8688Paraguay20021eSomalia272651Suriname570273Venezuela230257Vietnam28004fWestern Sahara790944Bangladesh1829Belize603cBhutan1800Cabinda2404Ecuador232bEl Salvador3c58Equatorial Guinea1455Estonia0142French Guiana6702Guinea-Bissau2d17Kuwait190eLebanon3d30Moldova112cMongolia0001Morocco6a09Nepal1800Netherlands0336Nicaragua587ePanama7e23San Jose7c7dSierra Leone175aSpain9016Swaziland1d1bSweden6354Togo5613Tunisia091aUSA8a60United Arab Emirates0e64Uruguay1e02Yemen0e64Brunei5fCanada85Denmark03Dominican Republic8dHaiti8cLesotho1dPapua New Guinea59Portugal80Qatar0eRepublic of Ireland95South Korea62The Gambia2dUnited Kingdom92"
.replace(/(\D+)([^A-Z]+)/g,(_,n,b)=>c.push([n,...b.match(/../g).map(x=>+('0x'+x))]),c=[]),
r=new Set,(f=(p,l)=>(c.find(x=>p==x[0],r.add(p))||[]).map((x,i)=>l&&i&&f(c[x][0],l-1)))(p,l),r.delete(p),r)

説明

// c has to be an array of arrays filled this way
// c[0] = ['USA', 1, 2]
// c[1] = ['Canada', 0]
// and so on

// make c array from a compact string
Z="China124b41017862692829186d7a40Russia635472421f1110343541007862Br ..."
// Country name followed by neighbors indexes as hex number, 2 digits each
// as the country are less than 160, the indexes starts with a digit
c=[]
Z.replace(/(\D+)([^A-Z]+)/g, // separate non-digits, then non uppercase
  (_,n,b)=> // n is the country name, b is the hex string
  c.push([n,
     ...b.match(/../g).map(x=>+('0x'+x))] // hex digits to int array
  )
),
r=new Set
// f: recursive scan
f=(p,l)=>
  // this check would make the function longer but SOOOO faster
  // r.has(p) ||
  (
    c.find(x=>p==x[0], r.add(p)) // add p to the set, then find it in the c array
    || [] // if not found use an empty array as result
  ).map( // recursive call for each neighbor index 
         // excluding position 0 (it's the name not an index)
         // and excluding all if l reached 0
     (x,i)=>l && i && f(c[x][0], l-1)
  )
f(p,l)
r.delete(p) // the starting country could be in the set if l>0
return r

テスト

P=(p,l)=>(
"China124b41017862692829186d7a40Russia635472421f1110343541007862Brazil23685767732b20651e87Germany5d367b8b1c3a065b2f16Democratic Republic of the Congo6e24220531474e084cSudan151a52532627310422Austria5b033a2e0a483e2fSerbia4d390a2c21433361Zambia4c040f5e1b32382aAlgeria6a79841a0d0c44Hungary062e112c073948Iran191035344a1246Mali2d44090d132517Niger130c091a154537Saudi Arabia3f197591866488Tanzania4e4731271b5e08Turkey3b0134350b1930Ukraine2e1c1f012c770aAfghanistan0b4a4b004046Burkina Faso0c0d37835625Cameroon451522245571Chad0d1a05221445France365d032f3e80Guinea742d0c255a7fIndia46407a6d296bIraq3f30100b750eLibya09845205150dMozambique32085e0f1d81Poland035c1f112e3aSouth Africa2a38321b818eArgentina5020650287Belarus5c4201111cBolivia2b02651e50Bulgaria072c103b43Central African Republic1415050424Columbia68022b6f7dCongo551422046eCote D'Ivoire5a170c1356Ethiopia0553516627Kenya310526660fLaos2900694f49Myanmar6b18002849Namibia4c0832381dPeru6f23022050Romania0a11772107Senegal94440c1774Slovakia063a1c110aSwitzerland16035b063eSyria7610193f3dUganda0405270f47Zimbabwe2a081b1d38Albania6107433bArmenia1001350bAzerbaijan1034010bBelgium167b035dBenin83130d45Botswana2a08321dCroatia480a074dCzech Republic031c2e06Greece33432110Guatemala606c7058Israel5276303fItaly162f0648Jordan3d30190eKashmir46120018Kazakhstan01004b4aLatvia72011f5cMacedonia3307213bMauritania6a090c2dNigeria370d1514Pakistan0b124018Rwanda04310f4eSlovenia3e060a39Thailand29284f5fTurkmenistan414b120bUzbekistan4100124aAngola04082aBosnia and Herzegovina390761Burundi04470fCambodia492869Chile2b201eDjibouti265366Egypt1a3d05Eritrea055126Finland826301Gabon711424Ghana251383Guyana680267Honduras3c707cIndonesia5f8f97Liberia7f1725Liechtenstein2f0306Lithuania421f1cLuxembourg163603Malawi080f1bMalaysia498959Mexico856c3cMontenegro4d0733North Korea000193Norway825401Oman0e8688Paraguay20021eSomalia272651Suriname570273Venezuela230257Vietnam28004fWestern Sahara790944Bangladesh1829Belize603cBhutan1800Cabinda2404Ecuador232bEl Salvador3c58Equatorial Guinea1455Estonia0142French Guiana6702Guinea-Bissau2d17Kuwait190eLebanon3d30Moldova112cMongolia0001Morocco6a09Nepal1800Netherlands0336Nicaragua587ePanama7e23San Jose7c7dSierra Leone175aSpain9016Swaziland1d1bSweden6354Togo5613Tunisia091aUSA8a60United Arab Emirates0e64Uruguay1e02Yemen0e64Brunei5fCanada85Denmark03Dominican Republic8dHaiti8cLesotho1dPapua New Guinea59Portugal80Qatar0eRepublic of Ireland95South Korea62The Gambia2dUnited Kingdom92"
.replace(/(\D+)([^A-Z]+)/g,(_,n,b)=>c.push([n,...b.match(/../g).map(x=>+('0x'+x))]),c=[]),
r=new Set,(f=(p,l)=>(c.find(x=>p==x[0],r.add(p))||[]).map((x,i)=>l&&i&&f(c[x][0],l-1)))(p,l),r.delete(p),r)

// TEST

console.log=x=>O.textContent+=x+'\n'

function test()
{
  var n,l,r;
  [,n,l]=I.value.match(/(.+) (\d+)/)
  console.log(n+' '+l)
  r=P(n,l)
  console.log(r.size+'\n'+[...r])
}

test()
<input id=I value='Bhutan 2'><button onclick='test()'>go</button><pre id=O></pre>


最初は、「なぜでは1/xなく」と考えていました+x。それから私はそれがcaseを回避する賢い方法だと気づきました0。+1
ETHproductions

@VoteToClose更新
-edc65

隣国のない国をすべて削除し、リストにない入力のフォールバックを追加する方が短いでしょうか?500バイト以上節約できました。
ETHproductions

@ETHproductionsはい。私は誰か他の人のアイデア借りて、このような大きなゲインについての疑問だった
edc65

4

Python 2、6967 6965 6950 6906バイト

Q=[["USA",1,2],["Canada",0],["Mexico",0,4,3],["Guatemala",2,4,5,6],["Belize",2,3],["El Salvador",3,6],["Honduras",3,5,7],["Nicaragua",6,8],["San Jose",7,9],["Panama",8,10],["Columbia",11,15,17,16],["Venezuela",10,15,12],["Guyana",11,15,13],["Suriname",12,15,14],["French Guiana",13,15],["Brazil",10,11,12,13,14,17,18,20,21,22],["Ecuador",10,17],["Peru",16,10,15,18,19],["Bolivia",17,15,20,21,19],["Chile",17,18,21],["Paraguay",18,15,21],["Argentina",19,18,20,15,22],["Uruguay",21,15],["The Bahamas"],["Cuba"],["Jamaica"],["Haiti",27],["Dominican Republic",26],["Puerto Rico"],["Saint Kitts and Nevis"],["Montserrat"],["Guadeloupe"],["Dominica"],["Martinique"],["Saint Vincent"],["Barbados"],["Trinidad and Tobago"],["Greenland"],["Azores"],["Falkland Islands"],["South Georgia"],["Cape Verde"],["Madeira Island"],["Canary Islands"],["Faroe Islands"],["Republic of Ireland",46],["United Kingdom",45],["Svalbard"],["Norway",49,50,51],["Sweden",48,50],["Finland",49,48,51],["Russia",48,50,53,54,56,62,84,87,88,89,93,90,91],["Denmark",57],["Estonia",51,54],["Latvia",53,51,56,55],["Lithuania",54,56,61],["Belarus",55,54,51,62,61],["Germany",60,59,58,52,61,63,68,69,71,70],["Netherlands",57,59],["Belgium",70,58,57,60],["Luxembourg",70,59,57],["Poland",57,55,56,62,64,63],["Ukraine",64,61,56,51,66,65,67],["Czech Republic",57,61,64,68],["Slovakia",68,63,61,62,67],["Moldova",62,66],["Romania",67,62,65,76,75],["Hungary",68,64,62,66,75,73,72],["Austria",69,57,63,64,67,72,80,71],["Liechtenstein",71,57,68],["France",59,60,57,71,80,81],["Switzerland",70,57,69,68,80],["Slovenia",80,68,67,73],["Croatia",72,67,75,74],["Bosnia and Herzegovina",73,75,77],["Serbia",74,73,67,66,76,79,78,77],["Bulgaria",75,66,84,83,79],["Montenegro",74,75,78],["Albania",77,75,79,83],["Macedonia",78,75,76,83],["Italy",70,71,68,72],["Spain",82,70],["Portugal",81],["Greece",78,79,76,84],["Turkey",83,51,87,88,97,98,99],["Malta"],["Cyprus"],["Armenia",84,51,88,97],["Azerbaijan",84,87,51,97],["Kazakhstan",51,93,94,96],["Mongolia",93,51],["North Korea",93,51,92],["South Korea",91],["China",95,94,89,51,90,91,120,119,117,111,113,112,110],["Uzbekistan",89,93,95,96],["Afghanistan",97,96,94,93,110,109],["Turkmenistan",89,94,95,97],["Iran",98,84,88,87,96,95,109],["Iraq",102,99,84,97,104,103],["Syria",100,84,98,102,101],["Lebanon",101,99],["Israel",145,100,99,102],["Jordan",101,99,98,103],["Saudi Arabia",102,98,104,105,106,107,108],["Kuwait",98,103],["Qatar",103],["United Arab Emirates",103,107],["Oman",103,106,108],["Yemen",103,107],["Pakistan",97,95,110,111],["Kashmir",109,95,93,111],["India",109,110,112,113,117,114],["Nepal",111,93],["Bhutan",111,93],["Bangladesh",111,117],["Sri Lanka"],["Adaman and Nicobar Islands"],["Myanmar",114,111,93,119,118],["Thailand",117,119,121,122],["Laos",117,93,120,121,118],["Vietnam",119,93,121],["Cambodia",118,119,120],["Malaysia",118,123,125],["Brunei",122],["Phillipines"],["Indonesia",122,126,127],["Papua New Guinea",125],["Australia"],["Tasmania"],["Japan"],["Guam"],["Solomon Islands"],["Vanuatu"],["Fiji"],["New Caledonia"],["New Zealand"],["Kerguelen Island"],["Heard Island"],["Mauritius"],["Reunion"],["Mayotte"],["Comoros"],["Madagascar"],["Sao Tome"],["Bioko"],["Egypt",146,101,167],["Libya",148,147,145,167,166,164],["Tunisia",148,146],["Algeria",150,149,147,146,164,159,151],["Morocco",150,148],["Western Sahara",149,148,151],["Mauritania",150,148,159,152],["Senegal",153,151,159,155,154],["The Gambia",152],["Guinea-Bissau",152,155],["Guinea",154,152,159,158,157,156],["Sierra Leone",155,157],["Liberia",156,155,158],["Cote D'Ivoire",157,155,159,160,161],["Mali",152,151,148,164,160,158,155],["Burkina Faso",159,164,163,162,161,158],["Ghana",158,160,162],["Togo",161,160],["Benin",162,160,164,165],["Niger",160,159,148,146,166,165,163],["Nigeria",163,164,166,176],["Chad",164,146,167,175,176,165],["Sudan",166,146,145,168,170,172,173,174,175],["Eritrea",167,169,170],["Djibouti",170,168,171],["Ethiopia",167,168,169,171,172],["Somalia",172,170,169],["Kenya",173,167,170,171,182],["Uganda",174,167,172,182,180],["Democratic Republic of the Congo",183,179,175,167,173,180,181,185,184],["Central African Republic",176,166,167,174,179],["Cameroon",165,166,175,179,178,177],["Equatorial Guinea",176,178],["Gabon",177,176,179],["Congo",178,176,175,174,183],["Rwanda",174,173,182,181],["Burundi",174,180,182],["Tanzania",181,180,173,172,187,186,185],["Cabinda",179,174],["Angola",174,185,190],["Zambia",184,174,182,186,187,188,189,190],["Malawi",185,182,187],["Mozambique",188,185,186,182,191,192],["Zimbabwe",190,185,187,191,189],["Botswana",190,185,188,191],["Namibia",184,185,188,189,191],["South Africa",190,189,188,187,192,193],["Swaziland",191,187],["Lesotho",191]]
i=raw_input().split()
l,c=int(i[-1])," ".join(i[:-1])
for _,v in enumerate(Q):
    if v[0]==c:C=m={_}
for _ in[0]*l:
    n=set()
    for A in C:n|=({d for d in Q[A][1:]if d not in C}|{A})
    C=n
for v in C-m:print Q[v][0]

私は本当に、本当にすべてがうまくいったことを願っています。例:

入力:

Sweden 3

出力:

Kazakhstan
Norway
Finland
Russia
Turkey
Estonia
Latvia
Armenia
Belarus
Azerbaijan
Mongolia
North Korea
China
Ukraine

空の行が許可されることを願っています。これ以上空行はありません!わーい!

説明:

一番上の長い行は、各国の名前と周辺国に関するデータです。リスト内の各要素は別のリストであり、その最初の要素は国の名前であり、他の要素はそれを囲む各国のインデックスです。USAは最初の要素であり、インデックスが含まれています1, 2。リストの要素1はカナダで、リストの要素2はメキシコです。このリストは、このプログラムを使用して生成されました。

s="""USA touches: Canada, Mexico

Canada touches: USA

...... [上記の大きなリスト]

Lesotho touches: South Africa"""

names = []

for row in s.split("\n\n"):
    names.append(row.split(" touches:")[0])


countries = []

for row in s.split("\n\n"):
    name = row.split(" touches:")[0]
    touching = row.split(" touches:")[1][1:].split(", ")

    lst = [name]
    for t in touching:
        if t in names:
            lst.append(names.index(t))

    countries.append(lst)

o = "[" 
for country in countries:
    o += "[\"" + country[0] + "\"," + ",".join(map(str, country[1: ])) + "],"

print o[:-1] + "]" 

出力は見つけることができる非常に単純な正規表現によって除去することができカンマ、含まれてここに。プログラム全体はこちらから入手できます。出力は4,736バイトで、プログラムの約88%です。

適切な変数名、コメント、空白(以前のバージョン)を使用したプログラムの残りの部分は次のとおりです。

COUNTRY_LIST=...
user_input = raw_input().split()
level = int(user_input[-1]) # last element of user_input
user_country = " ".join(user_input[:-1])

# Convert user_country to index
for index, country in enumerate(COUNTRY_LIST):
    if country[0] == user_country:
        user_country = index

surrounding = {user_country} # each country surrounding's index
for _ in [0] * level: # Loop level times, I'm using [0] * l instead of range(l) to save some bytes.
    new = set() # newer version of surrounding to avoid accidentally looping through some new countries.
    for country in surrounding:
        new |= {country} # Add country to new, using union.
        for surrounding_index in COUNTRY_LIST[country][1:]: # Get all the surrounding countries.
            if surrounding_index not in surrounding:
                 new |= {surrounding_index} # Add to new
    surrounding = new 
for surrounding_country in surrounding - {user_country}:
    print COUNTRY_LIST[surrounding_country][0] # print all the surrounding countries names except for the input country.

str:tuple dictを使用するためにバイトを節約できます。また、{}は空のセットになります。
CalculatorFeline

2
{}残念ながら@CatsAreFluffy は口述を作ります。
-Loovjo

ループの代わりに{x for d in Q[A][1:] if d not in C}and を使用してみてください。C|=nfor A in C:
CalculatorFeline

1
いい答えだ!私のリストが簡単に解析できることを望んでいましたが、そうだったようです。\ o / +1
アディソンクランプ

1
隣国のない国をすべて削除し、リストにない入力のフォールバックを追加する方が短いでしょうか?
ETHproductions

4

Mathematica、128Bプログラム+ 2856Bデータ= 2984バイト

e@a_:=a[[1]]<->#&/@Rest@a;l=ToExpression[ImportString[s]~StringSplit~"\n"];n=AdjacencyList[Graph[Union@@l,Flatten[e/@l]],#1,#2]&

FOO2856バイトの文字列はどこにありますか(印刷できない文字とMMAのみの文字が含まれているため、ここには貼り付けません)。文字列はリストのBZIP2圧縮リストで、各内部リストの形式は{Country, Neighbor, Neighbor, ...}です。リストはすでに冗長なエッジを削除するために最適化されています。

n["Mexico", 2]
(*{"USA", "Canada", "Belize", "Guatemala", "El Salvador", "Honduras"}*)

n["Cyprus", 17]
(*{}*)

Mathematicaのグラフ形式でそれを使用すると、次のような簡単で素晴らしいことができます:

map = Graph[Union @@ l, Flatten[e /@ l]];
touchGraph[country_, n_] :=
   NeighborhoodGraph[map, country, n, VertexLabels -> "Name",
     GraphLayout -> {"RadialEmbedding", "RootVertex" -> country}
  ];

次のようなものを取得するには: フランスの2地区のグラフ


それはクールだ。:DIリストをテストするためにこのプログラムがあればいいのに!
アディソンクランプ

1バイトを保存するために#1を#に変更することができます...編集する時間の価値がないようです:p
hYPotenuser

3

PHP、5169 2716 2698 2321バイト

更新

これは私の2番目の非常に短いバージョンです。元の投稿は以下を参照してください。

これはかなり詳細な編集になることが判明しました...

隣国のない国を削除します。

私の元の配列定義はなんと4901バイトの長さでした-隣人のいない国をすべて削除すると(@ETHproductionsが示唆したように)、これを725バイトから4176バイトに削減しました。もちろん、これにはフォールバックに対応するためにいくつかの追加のロジックコードを追加する必要がありますが、この大きなゲインと比較すると無視できるはずです。

数字の代わりに文字を使用する

次のステップは、近隣参照のデコードに必要なバイト数を減らすことでした。私の最初のアイデアは、10進法を捨てて数字を表すために高い基数を使用することでした(たとえば、0-9とazを使用する基数36)が、これらをデコードするために必要な追加のロジックはたくさん見えました。それで、私は何か他のものに行きました:キャラクター。

各ASCII文字の長さは1バイトのみであり、0〜255の範囲の明確に定義された番号にマップされます。これはまさに必要なものです。最初の39個のASCII文字は印刷不能/インクルード'"あり、エスケープする必要があるため、スキップしました。結果の配列定義の長さは2878バイトのみで、前と比較すると1298バイトまたは31%節約されました。もちろん、これも追加のロジックを必要としますが、ありがたいことにchrord短い関数名です:-)

国名の圧縮

しかし、それらの国の名前はまだ多くのスペースを占めていたので、それらを圧縮する方法を検討することにしました。5か国には「共和国」という用語が含まれているため、$r='Republic'一度宣言してから書き込み"$r of Ireland"などを行うことで16バイトを節約できました。4回表示される「ギニア」についても同様です。

比較的頻繁に発生する文字の組み合わせもかなりありますが、入力$xはまだ2文字であるため、これらを置き換えるのは3文字以上の組み合わせと、実際に置き換えることができるLOTがある場合にのみ意味があります。たとえば、すべての10件の交換-niaに秒Tanzaniaなどは1バイトのみを得ました。-istan(4x、-1)と同じ、(-land7x、-4)でさらに運がいい。

PHPの「機能」

コードゴルファーにとってありがたいことに、PHPは構文規則に違反しても気にしません。ここでは、これを使用していくつかの引用符を取り除き、'Lesotho'=>'E'(14バイト)をLesotho=>E(10バイト)に変換できます。驚いたことに(または衝撃的?)、これはAZ、0-9、またはASCIIテーブルの後半で構成され、数字始まっていない文字列でも機能し、これが可能になります:India=>nh¢•Q“

ただし、ASCIIテーブルの設計者が文字ブロックの間に句読点を入れているのは残念です。つまり、リスト内の150か国すべてに対応するPHPの意味のない文字の連続したブロックはありません。これにより、多くの文字列が引用符のままになります。時折、文字列が数字で始まらないように、数字を後ろに移動しました。

最終的な配列定義

これにより、配列定義は2534バイトになり、初期値のほぼ半分になります。もちろん、国の順序を最適化して、できるだけ多くのエントリが引用などを失うようにすることもできますが、これにそれほど労力をかけたくありませんでした。;-)

コード

したがって、ここに、2番目のバージョンに、追加のロジックが少し追加されています。

function f($s)
{
    // define often used parts of country names
    $r=Republic;$g=Guinea;$n=nia;$i=istan;$l=land;
    // array definition mainly as explained above, refer to edit notes below
    $x=explode('#',"China#:si) Š‘PQ@•¢h#Russia#‹|šjG98\]i( Š#Brazil#K›SHF®#Germany#…^£³Db.ƒW>#Democratic $r of the Congo#–LJ-Yov0t#Sudan#=Bz{NOY,J#Austria#ƒ+bV2pfW#Serbia#ua2TIk[‰#Zambia#t,7†CZ`R#Algeria#’¡¬B54l#Hungary#.V9T/ap#Iran#A8]\r:n#Mali#Ul15;M?#Niger#;41B=m_#Saudi Arabia#gA¹­Œ°#Tanza$n#voYOC†0#Turkey#c)\]3AX#Ukraine#VDG)TŸ2#Afghan$i#3rs(hn#Burkina Faso#45_«~M#Cameroon#m=JL}™#Chad#5B-J<m#France#^…+Wf¨#$g#œU4M‚§#India#nh¢•Q“#Iraq#gX836#Libya#1¬z-=5#Mozambique#Z0†7E©#Po$l#+„G9Vb#South Africa#R`ZC©¶#Argentina#xH*®#Belarus#„j)9D#Bolivia#S*Fx#Bulgaria#/T8ck#Central African $r#<=-,L#Columbia#*S—¥#Congo#}<J,–#Cote D'Ivoire#‚?4;~#Ethiopia#-{yŽO#Kenya#Y-NŽ7#Laos#Q(‘wq#Myanmar#“@(Pq#Namibia#t0Z`E#Peru#—K*Hx#Roma$n#29ŸI/#Senegal#¼l4?œ#Slovakia#.bD92#Switzer$l#>+ƒ.f#Syria#ž8Age#Uganda#,-O7o#Zimbabwe#R0CE`#Alba$n#‰/kc#Arme$n#8)]3#Azerbaijan#8\)3#Belgium#>£+…#Benin#«;5m#Botswana#R0ZE#Croatia#p2/u#Czech $r#+DV.#Greece#[kI8#Guatemala#ˆ”˜€#Israel#zžXg#Italy#>W.p#Jordan#eXA6#Kashmir#n:(@#Kazakhstan#)(sr#Latvia#š)G„#Macedo$n#[/Ic#Maurita$n#’14U#Nigeria#_5=<#Pak$i#3:h@#Rwanda#,Y7v#Slove$n#f.2a#Thai$l#QPw‡#Turkmen$i#is:3#Uzbek$i#i(:r#Angola#,0R#Bos$n and Herzegovina#a/‰#Burundi#,o7#Cambodia#qP‘#Chile#SHF#Djibouti#N{Ž#Egypt#Be-#Eritrea#-yN#Fin$l#ª‹)#Gabon#™<L#Ghana#M;«#Guyana#*#Honduras#d˜¤#Indonesia#‡·#Liberia#§?M#Liechtenstein#W+.#Lithua$n#jGD#Luxembourg#>^+#Malawi#07C#Malaysia#q±#Mexico#¯”d#Montenegro#u/[#North Korea#()»#Norway#ª|)#Oman#6­°#Paraguay#H*F#Somalia#ONy#Suriname#*›#Venezuela#K*#Vietnam#P(w#Western Sahara#¡1l#Bangladesh#@Q#Belize#ˆd#Bhutan#@(#Cabinda#L,#Ecuador#KS#El Salvador#d€#Equatorial $g#<}#Esto$n#)j#French Guiana#*#$g-Bissau#U?#Kuwait#A6#Lebanon#eX#Moldova#9T#Mongolia#()#Morocco#’1#Nepal#@(#Nether$ls#+^#Nicaragua#€¦#Panama#¦K#San Jose#¤¥#Sierra Leone#?‚#Spain#¸>#Swazi$l#EC#Sweden#‹|#Togo#~;#Tunisia#1B#United Arab Emirates#6Œ#Uruguay#F*#USA#²ˆ#Yemen#6Œ#Brunei#‡#Canada#¯#Denmark#+#Dominican $r#µ#Haiti#´#Lesotho#E#Papua New $g##Portugal#¨#Qatar#6#$r of Ire$l#½#South Korea#Š#The Gambia#U#United Kingdom#º");
    // turn the indexed into the wanted associative array
    $k=0;while($k<299)$t[$x[$k++]]=$x[$k++];

    // used 3 times -> saves 20 bytes when cached rather than call each time
    $y=array_keys($t);

    // Extract country and layer parameters from input (damn countries with spaces)
    list($c, $l) = str_getcsv($s, ' ', '"');

    // input not in array -> no neighbours -> output nothing
    if(in_array($c, $y))
    {
      // convert country into its ASCII code via index number, accomodating for the 39 chars offset
      $r = [chr(40+array_search($c, $y))];

      // for each layer needed
      while($l>$j++)
        // go through ALL countries found so far
        foreach($r as$d)
          // and add their neighbours to the result
          // (str_split returns the string as an array of chars)
          $r = array_merge($r, str_split( array_values($t)[ord($d)-40] ));

      // remove all the duplicates that were created doing that...
      $r = array_unique($r);
      // remove the initial country itself from the result
      unset($r[0]);
      // convert the index chars back into country names
      foreach($r as$k=>$v)
        $r[$k] = $y[ord($v)-40];

      // output as list
      echo implode($r, "\n");
    }
}

ゴルフ

function f($s){$r=Republic;$g=Guinea;$n=nia;$i=istan;$l=land;$x=explode('#',"China#:si) Š‘PQ@•¢h#Russia#‹|šjG98\]i( Š#Brazil#K›SHF®#Germany#…^£³Db.ƒW>#Democratic $r of the Congo#–LJ-Yov0t#Sudan#=Bz{NOY,J#Austria#ƒ+bV2pfW#Serbia#ua2TIk[‰#Zambia#t,7†CZ`R#Algeria#’¡¬B54l#Hungary#.V9T/ap#Iran#A8]\r:n#Mali#Ul15;M?#Niger#;41B=m_#Saudi Arabia#gA¹­Œ°#Tanza$n#voYOC†0#Turkey#c)\]3AX#Ukraine#VDG)TŸ2#Afghan$i#3rs(hn#Burkina Faso#45_«~M#Cameroon#m=JL}™#Chad#5B-J<m#France#^…+Wf¨#$g#œU4M‚§#India#nh¢•Q“#Iraq#gX836#Libya#1¬z-=5#Mozambique#Z0†7E©#Po$l#+„G9Vb#South Africa#R`ZC©¶#Argentina#xH*®#Belarus#„j)9D#Bolivia#S*Fx#Bulgaria#/T8ck#Central African $r#<=-,L#Columbia#*S—¥#Congo#}<J,–#Cote D'Ivoire#‚?4;~#Ethiopia#-{yŽO#Kenya#Y-NŽ7#Laos#Q(‘wq#Myanmar#“@(Pq#Namibia#t0Z`E#Peru#—K*Hx#Roma$n#29ŸI/#Senegal#¼l4?œ#Slovakia#.bD92#Switzer$l#>+ƒ.f#Syria#ž8Age#Uganda#,-O7o#Zimbabwe#R0CE`#Alba$n#‰/kc#Arme$n#8)]3#Azerbaijan#8\)3#Belgium#>£+…#Benin#«;5m#Botswana#R0ZE#Croatia#p2/u#Czech $r#+DV.#Greece#[kI8#Guatemala#ˆ”˜€#Israel#zžXg#Italy#>W.p#Jordan#eXA6#Kashmir#n:(@#Kazakhstan#)(sr#Latvia#š)G„#Macedo$n#[/Ic#Maurita$n#’14U#Nigeria#_5=<#Pak$i#3:h@#Rwanda#,Y7v#Slove$n#f.2a#Thai$l#QPw‡#Turkmen$i#is:3#Uzbek$i#i(:r#Angola#,0R#Bos$n and Herzegovina#a/‰#Burundi#,o7#Cambodia#qP‘#Chile#SHF#Djibouti#N{Ž#Egypt#Be-#Eritrea#-yN#Fin$l#ª‹)#Gabon#™<L#Ghana#M;«#Guyana#*#Honduras#d˜¤#Indonesia#‡·#Liberia#§?M#Liechtenstein#W+.#Lithua$n#jGD#Luxembourg#>^+#Malawi#07C#Malaysia#q±#Mexico#¯”d#Montenegro#u/[#North Korea#()»#Norway#ª|)#Oman#6­°#Paraguay#H*F#Somalia#ONy#Suriname#*›#Venezuela#K*#Vietnam#P(w#Western Sahara#¡1l#Bangladesh#@Q#Belize#ˆd#Bhutan#@(#Cabinda#L,#Ecuador#KS#El Salvador#d€#Equatorial $g#<}#Esto$n#)j#French Guiana#*#$g-Bissau#U?#Kuwait#A6#Lebanon#eX#Moldova#9T#Mongolia#()#Morocco#’1#Nepal#@(#Nether$ls#+^#Nicaragua#€¦#Panama#¦K#San Jose#¤¥#Sierra Leone#?‚#Spain#¸>#Swazi$l#EC#Sweden#‹|#Togo#~;#Tunisia#1B#United Arab Emirates#6Œ#Uruguay#F*#USA#²ˆ#Yemen#6Œ#Brunei#‡#Canada#¯#Denmark#+#Dominican $r#µ#Haiti#´#Lesotho#E#Papua New $g##Portugal#¨#Qatar#6#$r of Ire$l#½#South Korea#Š#The Gambia#U#United Kingdom#º");$k=0;while($k<299)$t[$x[$k++]]=$x[$k++];$y=array_keys($t);list($c,$l)=str_getcsv($s,' ','"');if(in_array($c,$y)){$r=[chr(40+array_search($c,$y))];while($l>$j++)foreach($r as$d)$r=array_merge($r,str_split(array_values($t)[ord($d)-40]));$r=array_unique($r);unset($r[0]);foreach($r as$k=>$v)$r[$k]=$y[ord($v)-40];echo implode($r,"\n");}}

更新の編集

次の方法でさらに18バイトを保存しました:

  • 引用符の除去$r='Republic'など(-10)
  • 交換forwhileループ(-6)
  • asキーワードの後の空白を削除する(-2)

上記のコードを変更して更新しました。

別の編集

内包された文字列からインデックス付き配列を最初に作成し(すべて=>- "廃止された-417バイトのオーバーヘッド)、その後それを必要な連想配列(+40バイトのコード)に変えることで、さらに377バイトを削ぎ落としました。上記のコードを再度更新しました。


最初の投稿

function f($s){$t=["Adaman and Nicobar Islands"=>[],"Afghanistan"=>[80,179,186,36,87,131],"Albania"=>[115,152,101,66],"Algeria"=>[190,117,177,97,126,106,109],"Angola"=>[45,192,120],"Argentina"=>[35,19,134,22,185],"Armenia"=>[178,144,9,80],"Australia"=>[],"Austria"=>[98,64,44,154,77,155,83,168],"Azerbaijan"=>[178,6,144,80],"Azores"=>[],"Bangladesh"=>[78,119],"Barbados"=>[],"Belarus"=>[99,93,144,182,137],"Belgium"=>[61,122,64,100],"Belize"=>[112,70],"Benin"=>[175,25,126,127],"Bhutan"=>[78,36],"Bioko"=>[],"Bolivia"=>[135,22,134,5,35],"Bosnia and Herzegovina"=>[41,152,115],"Botswana"=>[120,192,193,158],"Brazil"=>[37,188,73,164,62,135,19,134,5,185],"Brunei"=>[105],"Bulgaria"=>[152,143,178,66,101],"Burkina Faso"=>[106,126,16,175,65,40],"Burundi"=>[45,145,170],"Cabinda"=>[39,45],"Cambodia"=>[172,92,189],"Cameroon"=>[127,34,33,39,63,53],"Canada"=>[185],"Canary Islands"=>[],"Cape Verde"=>[],"Central African Republic"=>[29,34,163,45,39],"Chad"=>[126,97,163,33,29,127],"Chile"=>[135,19,5],"China"=>[1,186,88,144,114,128,189,92,119,78,17,121,87],"Columbia"=>[188,22,135,50,132],"Comoros"=>[],"Congo"=>[63,29,33,45,27],"Cote D'Ivoire"=>[96,71,106,25,65],"Croatia"=>[155,77,152,20],"Cuba"=>[],"Cyprus"=>[],"Czech Republic"=>[64,137,154,8],"Democratic Republic of the Congo"=>[27,39,33,163,181,145,26,192,4],"Denmark"=>[64],"Djibouti"=>[56,54,157],"Dominica"=>[],"Dominican Republic"=>[74],"Ecuador"=>[37,135],"Egypt"=>[97,82,163],"El Salvador"=>[70,76],"Equatorial Guinea"=>[29,63],"Eritrea"=>[163,47,56],"Estonia"=>[144,93],"Ethiopia"=>[163,54,47,157,89],"Falkland Islands"=>[],"Faroe Islands"=>[],"Fiji"=>[],"Finland"=>[167,129,144],"France"=>[14,100,64,168,83,161],"French Guiana"=>[164,22],"Gabon"=>[53,29,39],"Germany"=>[100,14,122,46,137,44,8,98,168,61],"Ghana"=>[40,25,175],"Greece"=>[2,101,24,178],"Greenland"=>[],"Guadeloupe"=>[],"Guam"=>[],"Guatemala"=>[112,15,52,76],"Guinea"=>[72,151,106,40,96,153],"Guinea-Bissau"=>[151,71],"Guyana"=>[188,22,164],"Haiti"=>[49],"Heard Island"=>[],"Honduras"=>[70,52,125],"Hungary"=>[8,154,182,143,152,41,155],"India"=>[131,87,121,17,119,11],"Indonesia"=>[105,133,7],"Iran"=>[81,178,9,6,179,1,131],"Iraq"=>[86,169,178,80,91,150],"Israel"=>[51,94,169,86],"Italy"=>[61,168,8,155],"Jamaica"=>[],"Japan"=>[],"Jordan"=>[82,169,81,150],"Kashmir"=>[131,1,36,78],"Kazakhstan"=>[144,36,186,179],"Kenya"=>[181,163,56,157,170],"Kerguelen Island"=>[],"Kuwait"=>[81,150],"Laos"=>[119,36,189,28,172],"Latvia"=>[55,144,13,99],"Lebanon"=>[82,169],"Lesotho"=>[158],"Liberia"=>[153,71,40],"Libya"=>[3,177,51,163,34,126],"Liechtenstein"=>[168,64,8],"Lithuania"=>[93,13,137],"Luxembourg"=>[61,14,64],"Macedonia"=>[2,152,24,66],"Madagascar"=>[],"Madeira Island"=>[],"Malawi"=>[192,170,118],"Malaysia"=>[172,23,79],"Mali"=>[151,109,3,126,25,40,71],"Malta"=>[],"Martinique"=>[],"Mauritania"=>[190,3,106,151],"Mauritius"=>[],"Mayotte"=>[],"Mexico"=>[185,15,70],"Moldova"=>[182,143],"Mongolia"=>[36,144],"Montenegro"=>[20,152,2],"Montserrat"=>[],"Morocco"=>[190,3],"Mozambique"=>[193,192,104,170,158,166],"Myanmar"=>[11,78,36,92,172],"Namibia"=>[4,192,193,21,158],"Nepal"=>[78,36],"Netherlands"=>[64,14],"New Caledonia"=>[],"New Zealand"=>[],"Nicaragua"=>[76,148],"Niger"=>[25,106,3,97,34,127,16],"Nigeria"=>[16,126,34,29],"North Korea"=>[36,144,160],"Norway"=>[167,60,144],"Oman"=>[150,183,191],"Pakistan"=>[80,1,87,78],"Panama"=>[148,37],"Papua New Guinea"=>[79],"Paraguay"=>[19,22,5],"Peru"=>[50,37,22,19,35],"Phillipines"=>[],"Poland"=>[64,99,13,182,154,44],"Portugal"=>[161],"Puerto Rico"=>[],"Qatar"=>[150],"Republic of Ireland"=>[184],"Reunion"=>[],"Romania"=>[77,182,113,24,152],"Russia"=>[129,60,55,93,13,182,178,6,9,88,36,114,128],"Rwanda"=>[45,181,170,26],"Saint Kitts and Nevis"=>[],"Saint Vincent"=>[],"San Jose"=>[125,132],"Sao Tome"=>[],"Saudi Arabia"=>[86,81,91,140,183,130,191],"Senegal"=>[174,109,106,71,72],"Serbia"=>[20,41,77,143,24,101,2,115],"Sierra Leone"=>[71,96],"Slovakia"=>[8,44,137,182,77],"Slovenia"=>[83,8,77,41],"Solomon Islands"=>[],"Somalia"=>[89,56,47],"South Africa"=>[120,21,193,118,166,95],"South Georgia"=>[],"South Korea"=>[128],"Spain"=>[138,61],"Sri Lanka"=>[],"Sudan"=>[34,97,51,54,56,89,181,45,33],"Suriname"=>[73,22,62],"Svalbard"=>[],"Swaziland"=>[158,118],"Sweden"=>[129,60],"Switzerland"=>[61,64,98,8,83],"Syria"=>[94,178,81,86,82],"Tanzania"=>[26,145,181,89,118,104,192],"Tasmania"=>[],"Thailand"=>[119,92,28,105],"The Bahamas"=>[],"The Gambia"=>[151],"Togo"=>[65,25],"Trinidad and Tobago"=>[],"Tunisia"=>[3,97],"Turkey"=>[66,144,6,9,80,81,169],"Turkmenistan"=>[88,186,1,80],"USA"=>[30,112],"Uganda"=>[45,163,89,170,145],"Ukraine"=>[154,137,13,144,143,113,77],"United Arab Emirates"=>[150,130],"United Kingdom"=>[141],"Uruguay"=>[5,22],"Uzbekistan"=>[88,36,1,179],"Vanuatu"=>[],"Venezuela"=>[37,22,73],"Vietnam"=>[92,36,28],"Western Sahara"=>[117,3,109],"Yemen"=>[150,130],"Zambia"=>[4,45,170,104,118,193,21,120],"Zimbabwe"=>[120,192,118,158,21]];list($c,$l)=str_getcsv($s,' ','"');$r=[array_search($c,array_keys($t))];for($i=0;$i<$l;$i++)foreach($r as $d)$r=array_merge($r,array_values($t)[$d]);$r=array_unique($r);unset($r[0]);foreach($r as $k=>$v)$r[$k]=array_keys($t)[$v];return implode($r,"\n");}

これはかなり早い最初のバージョンです。名前の明らかな数字以外のリスト圧縮はまだしていませんでした。明日はそれに取り組み、投稿を編集するかもしれません。

私のリストは、各国のエントリを持つ単純な連想配列です。配列キーは国の名前であり、その配列のインデックスによって参照される近隣の配列の値です。PHPでは、インデックスを使用して連想配列にアクセスできないためarray_keysarray_values関数と関数を使用する回避策が必要でした。

コメントされた実際のコード:

function f($s)
{
  $t = ["Adaman and Nicobar Islands"=>[],"Afghanistan"=>[80,179,186,36,87,131],"Albania"=>[115,152,101,66],...,"Zimbabwe"=>[120,192,118,158,21]];
  // Extract country and layer parameters from input (damn countries with spaces)
  list($c, $l) = str_getcsv($s, ' ', '"');

  // convert country into its index number
  $r = [array_search($c, array_keys($t))];

  // for each layer needed
  for($i=0; $i<$l; $i++)
    // go through ALL countries found so far
    foreach($r as $d)
      // and add their neighbours to the result
      $r = array_merge($r, array_values($t)[$d]);

  // remove all the duplicates that were created doing that...
  $r = array_unique($r);
  // remove the initial country itself from the result
  unset($r[0]);

  // convert the index numbers back into country names
  foreach($r as $k=>$v)
    $r[$k] = array_keys($t)[$v];

  // output as list
  return implode($r,"\n");
}

前といつものように、どんなコメントでも大歓迎です。


隣国のない国をすべて削除し、リストにない入力のフォールバックを追加する方が短いでしょうか?
ETHproductions

うん、それは私が念頭に置いていたものの1つです-そのための私の編集したばかりの投稿を見てください:)
Christallkeks

3

Dyalog APL、82バイトのプログラム+ 1924バイトのデータ= 2006バイト

{N S←{{1↓¨⍵⊂⍨⍵=⊃⍵}0(220⌶)¯2(219⌶)¯128+⎕UCS⍵}¨829(↑{⍺ ⍵}↓)'………'
S[∪{∊N[⍵]}⍣⍵⊢S⍳⊂⍺]~⊂⍺}

Dyalog APLの組み込み(de)serialize(220⌶)および(un-)zip(219⌶)を使用する以外に、データをパックするために特別なことはしませんでした。

楕円がこれらのバイト値を持つzlibされた文字列を表す場合:

248 90 45 21 235 211 76 225 152 70 175 10 138 165 197 222 176 99 5 119 140 150 217 105 192 171 234 83 193 187 99 88 233 211 162 34 230 18 178 252 135 17 83 82 82 233 83 209 169 157 54 4 79 96 53 47 98 119 92 59 232 60 180 26 249 110 107 247 221 119 125 188 79 63 127 255 26 254 140 252 215 108 231 79 94 24 30 204 8 135 218 175 7 107 236 237 208 162 26 0 238 212 18 17 115 9 70 9 228 73 232 18 210 40 73 90 196 205 81 230 106 150 37 171 195 91 172 89 140 39 70 51 180 180 149 93 10 38 33 46 59 5 164 13 164 195 25 90 33 172 109 52 180 3 58 77 118 230 234 187 28 129 57 238 12 179 161 209 83 205 55 91 78 244 91 25 229 39 254 219 51 246 51 246 125 21 125 107 90 79 90 151 103 3 186 164 143 250 128 245 110 64 239 247 196 199 245 204 249 138 104 2 174 106 18 42 245 217 215 104 249 217 158 250 226 66 67 196 182 100 166 243 81 236 72 67 158 71 167 20 35 99 186 140 103 75 39 83 186 35 162 91 29 195 173 34 99 229 66 209 14 29 104 229 47 59 45 0 233 209 243 241 158 29 82 201 149 218 183 23 76 135 121 104 103 178 103 82 188 122 2 114 24 170 21 95 58 133 22 122 213 44 51 120 83 108 76 167 171 68 213 112 132 226 249 109 28 156 238 119 98 170 212 233 207 97 229 86 7 147 75 71 252 177 244 150 117 43 132 170 198 79 33 165 208 161 103 23 42 220 229 22 120 241 129 213 97 221 87 207 170 242 191 62 138 170 3 202 13 10 56 75 231 79 244 94 94 195 37 245 75 105 134 32 170 254 215 119 22 107 149 212 131 89 31 239 149 32 99 242 89 247 112 152 249 120 150 181 42 3 42 109 235 57 250 149 245 223 39 22 78 165 60 123 214 119 85 41 142 93 209 27 110 42 21 30 123 6 53 54 47 30 218 3 235 85 237 75 235 72 93 73 193 238 57 72 189 245 248 87 233 98 233 130 244 26 245 157 247 141 142 18 181 66 13 244 36 71 228 141 164 177 159 52 41 166 52 217 183 244 211 173 58 229 231 58 180 54 218 44 94 52 188 102 106 57 41 21 231 148 119 85 114 196 177 234 101 9 91 248 118 246 146 17 45 45 157 235 94 206 59 37 29 58 135 247 32 221 106 182 42 102 247 111 50 52 147 110 194 111 193 119 205 159 104 161 90 157 191 33 219 15 40 143 127 83 223 22 219 189 60 11 136 122 212 207 248 191 145 141 235 80 220 143 117 25 250 201 251 200 66 250 238 126 169 53 23 122 75 5 117 130 250 9 143 171 36 215 112 139 219 161 106 171 180 44 190 61 81 235 220 136 149 148 162 145 156 34 119 214 111 236 122 185 167 141 98 122 236 223 152 158 208 191 189 183 89 199 94 15 62 195 135 80 254 244 208 195 80 219 166 93 243 142 99 220 231 0 252 216 159 32 193 82 8 38 224 183 183 12 251 44 145 13 234 220 147 26 164 151 93 119 248 49 198 180 230 254 4 228 12 137 49 198 225 177 155 1 70 116 137 30 4 71 33 217 248 222 159 185 163 194 255 214 243 218 84 130 89 135 238 9 176 117 145 158 2 39 32 153 205 219 231 6 186 13 58 94 140 186 69 92 60 29 185 65 9 243 198 51 246 75 156 186 65 189 209 173 241 46 88 177 233 93 197 253 198 151 32 207 244 34 218 86 10 165 11 120 168 58 140 173 65 43 122 2 123 12 11 66 171 241 222 6 93 110 197 91 55 234 105 138 156 229 122 171 238 85 78 216 53 127 194 191 129 153 5 154 24 248 90 213 213 193 246 107 182 140 124 59 158 35 90 125 141 250 136 91 241 146 71 241 26 198 206 122 26 157 228 161 146 227 10 244 192 82 126 118 249 250 47 94 32 231 104 16 50 125 254 51 48 196 210 132 134 3 65 100 31 63 127 125 182 126 125 122 253 252 190 125 178 190 105 53 30 80 12 157 55 204 171 121 225 182 30 110 146 199 153 88 178 205 69 26 19 80 92 214 181 91 189 55 222 105 94 59 182 169 135 250 178 155 214 110 146 211 77 46 250 112 193 104 153 225 134 38 25 55 233 232 140 83 27 184 185 165 193 32 59 244 68 153 85 201 141 190 145 58 213 241 27 62 58 203 166 239 207 21 207 70 82 252 19 202 10 231 81 196 211 239 77 158 177 230 61 49 185 242 201 245 36 9 246 98 162 2 80 43 38 50 51 110 37 26 242 15 68 1 230 41 225 250 64 171 48 81 189 27 232 104 70 143 70 225 105 42 151 89 37 70 26 141 189 167 81 104 43 23 220 235 77 70 69 234 233 226 140 149 59 54 250 18 61 137 52 114 174 134 209 101 24 73 232 69 122 52 19 235 168 218 49 130 2 121 202 242 62 127 230 92 134 48 232 74 90 32 4 192 235 84 233 218 238 203 76 53 239 56 131 45 170 98 172 182 232 242 114 170 1 238 89 238 115 58 218 4 124 136 212 123 148 193 10 248 109 242 101 60 19 106 205 52 149 164 236 69 168 31 191 172 109 82 99 117 90 173 43 23 107 106 210 230 101 191 42 5 202 57 112 106 204 20 150 229 58 46 117 131 85 251 54 141 235 203 207 222 143 32 48 190 200 171 14 238 77 136 111 165 5 0 124 183 98 134 86 173 77 195 116 142 107 199 14 57 161 15 166 118 9 115 134 84 65 26 130 93 9 142 108 14 116 164 49 151 157 209 96 44 179 233 32 71 116 195 6 70 167 109 104 89 15 216 54 138 78 4 230 167 1 130 46 205 41 45 95 115 150 209 215 94 54 248 37 151 191 20 172 119 73 245 40 22 166 169 196 173 121 241 175 10 139 209 140 176 171 3 250 212 224 98 233 76 221 162 201 62 185 211 79 177 99 116 129 75 82 10 251 81 19 244 254 31 133 212 11 230 17 206 19 197 124 18 88 161 44 244 106 233 130 250 242 4 149 239 36 173 69 175 162 219 144 53 131 244 148 34 177 245 236 203 199 17 252 29 244 171 199 252 236 163 18 158 247 25 19 9 142 133 67 132 40 154 182 31 108 232 73 167 94 118 161 98 149 41 186 104 27 243 131 80 113 165 100 64 103 110 15 111 208 253 22 120 41 17 45 169 183 166 159 221 143 200 101 189 103 75 81 75 226 33 99 79 151 85 71 194 15 128 58 71 214 208 150 203 143 222 219 252 208 243 234 205 181 209 78 149 175 83 129 35 193 255 240 228 61 200 163 159 213 115 129 162 11 208 102 111 32 30 126 146 164 65 100 29 145 172 185 116 184 39 5 235 179 240 89 1 0 233 31 114 81 20 221 231 161 81 80 211 45 38 250 228 55 197 101 173 102 80 13 195 5 201 3 94 46 146 221 65 140 160 173 12 174 27 82 50 199 70 76 60 153 9 176 135 40 155 2 233 139 123 22 15 217 9 211 205 206 140 189 67 138 44 89 193 188 161 35 112 248 98 112 25 247 9 177 55 7 108 166 142 92 149 33 240 230 247 77 225 84 80 131 111 128 147 35 140 109 251 107 135 111 46 216 94 88 65 110 146 68 127 233 168 199 25 49 189 119 188 47 94 5 139 66 37 232 135 167 19 75 197 58 151 140 80 229 49 226 152 219 180 169 207 223 242 134 116 47 120 104 227 4 74 17 204 209 156 166 24 187 142 48 204 116 66 67 146 224 2 211 99 55 30 102 93 241 151 33 106 102 136 64 56 28 235 26 88 206 198 201 42 95 64 37 126 148 40 221 157 220 56 7 145 30 83 21 74 106 44 216 244 162 59 96 157 151 87 157 233 120 237 234 194 96 244 222 209 237 50 29 213 15 130 86 242 50 146 254 102 35 212 183 95 151 251 239 180 27 12 181 24 134 93 194 250 85 173 135 184 214 31 93 249 109 225 222 211 104 77 65 115 1 235 124 173 86 76 24 54 20 117 181 135 30 44 91 27 207 3 225 7 109 78 227 239 124 174 131 68 152 103 222 172 69 33 64 87 142 244 229 235 153 124 134 210 3 203 125 236 215 48 15 234 22 199 3 230 240 211 116 48 26 252 104 127 61 155 98 144 117 160 248 126 5 54 249 64 48 23 62 95 241 3 125 113 126 75 33 100 193 181 137 242 5 144 92 41 80 181 67 128 100 3 201 30 191 38 119 17 49 172 52 3 129 91 39 60 78 54 126 238 6 6 27 131 250 100 227 184 228 150 30 248 176 13 57 204 105 8 139 54 19 127 241 149

エンコードされた文字列と残りのプログラムの両方が、APLの256文字のコードページ、つまりバイトごとに1つのシンボルに収まることに注意してください。

以下に、すべてをまとめたときの様子を示します(U + 0000の代わり):

{N S←{{1↓¨⍵⊂⍨⍵=⊃⍵}0(220⌶)¯2(219⌶)¯128+⎕UCS⍵}¨829(↑{⍺ ⍵}↓)'øZ-ëÓLáF¯
¥ÅÞ°cwÙiÀ«êSÁ»cXéÓ¢"æ²üSRRéSÑ©6O`5/bw\;è<´ùnk÷Ýw}¼O?ÿþü×lçO^ÌÚ¯kìíТ␀îÔs    F   äIèÒ(IZÄÍQæj%«Ã[¬Y'F3´´]
&!.;¤
¤ÃZ!¬m4´:Mvæê»9ÑSÍ7[Nô[å'þÛ3ö3ö}}kZOZgº¤úõn@ï÷ÄÇõÌùh®j*õÙ×hùÙúâBCĶd¦óQìHCG§#cºgK'Sº#¢[í"cåBÑhå/;-␀éÑóñRÉÚ·Lyhg²gR¼zrª_:zÕ,3xSlL§«DÕpâùmîwbªÔéÏaåVKGü±ôu+ªÆO!¥Ð¡g*ÜåxñÕaÝWϪò¿>ªÊ

8KçOô^^Ã%õKi ªþ×wkÔYï còY÷pùxµ**më9úõß'N¥<{ÖwU)]Ñn*{56/ÚëUíKëH]IÁî9H½õøWébéôõ÷µB
ô$G䤱4)¦4Ù·ôÓ­:åç:´6Ú,^4¼fj9)çwUrıêe  [øvö--ë^Î;%:÷ Ýj¶*f÷o24nÂoÁwÍh¡Z¿!Û(SßÛ½<zÔÏø¿ëPÜuúÉûÈBúî~©5zKuú    «$×pÛ¡j«´,¾=QëÜ¢"wÖoìz¹§bzìßп½·YÇ^>ÃPþôÐÃPÛ¦]ócÜç␀üØ ÁR&à··û,
êܤ]wø1Æ´æþä1Æá±FtG!ÙøÞ¹£ÂÿÖóÚTYî   °u' ÍÛçº
:^ºE\<¹A    óÆ3öKºA½Ñ­ñ.X±é]ÅýÆ Ïô"ÚV
¥x¨:­A+z{B«ñÞ]nÅ[7êiåz«îUNØ5¿øZÕÕÁök¶|;#Z}ú[ñGñÆÎzä¡ã
ôÀR~vùú/^ çh2}þ30ÄÒAd?}¶~}zýü¾}²¾i5P7Ì«yá¶nÇX²ÍEP\Öµ[½7Þi^;¶©ú²ÖnÓM.úpÁhá&7éèS¸¹¥Á ;ôDUɾ:Õñ>:˦ïÏÏFRüÊ
çQÄÓïM±æ=1¹òÉõ$ öb¢P+&23n%òDæ)áú@«0Q½èhFFái*Y%F½§Qh+ÜëMFEêéâ;6ú=4r®ÑeIèEz4ë¨Ú1yÊò>æ\0èJZ ÀëTéÚîËL5ï8-ªb¬¶èòrªîYîs:Ú|Ô{Á
ømòe<jÍ4¤ìE¨¿¬mRcuZ­+kjÒæe¿*Ê9pjÌå:.uUû6ëËÏÞ 0¾È«îMo¥␀|·bV­MÃtkÇ9¡¦v    sTA]    lt¤1Ñ`,³é GtÃF§mhYØ6Næ§.Í)-_sÑ×^6ø%¿¬wIõ(¦©Ä­yñ¯
Ñ°«úÔàbéLÝ¢É>¹ÓO±ctKR
ûQôþÔæÎÅ|X¡,ôjéúòï$­E¯¢Û5ô"±õìËÇüô«Çüì£÷    C(¶lèI§^v¡b)ºhóPq¥d@gnoÐýx)-©·¦ÝÈe½gKQKâ!cOUGÂ:GÖÐËÞÛüÐóê͵ÑN¯S#Áÿðä=È£Õs¢Ðfo ~¤Ad¬¹t¸'ë³ðY␀érQÝç¡QPÓ-&úä7Åe­fP
ÃÉ^.ÝA ­®R2ÇFL< °(é{Ù   ÓÍνC,YÁ¼¡#pøbp÷    ±7l¦\!ðæ÷MáTPo#mûko.Ø^XAnDé¨Ç1½w¼/^B%è§KÅ:På1âÛ´©Ïßòt/xhãJÌѦ»0ÌtBCàÓc7f]ñ!jf@8ëXÎÆÉ*_@%~(ÝÜ8SJj,Øô¢;`WéxíêÂ`ôÞÑí2ÕVò2þf#Ô·_ûï´µ]ÂúU­¸Ö]ùmáÞÓhMAsë|­VL6uµ,[ÏámNãï|®DgÞ¬E!@Wôåë|ÒË}ì×0êÇæðÓt0üh=bu ø~6ù@0>_ñ}q~K!dÁµò\)PµCdÉ¿&w1¬4['<N6~îúdã¸äø°
9Ìi6ñËp1w_>}Ö!/'
S[∪{∊N[⍵]}⍣⍵⊢S⍳⊂⍺]~⊂⍺}
弊社のサイトを使用することにより、あなたは弊社のクッキーポリシーおよびプライバシーポリシーを読み、理解したものとみなされます。
Licensed under cc by-sa 3.0 with attribution required.