0
\$\begingroup\$

This is a very simple challenge.

Task

Whenever your code is run, your code should output the next sunset date and time in GMT for all capital cities on Earth. You should get the list of capitals from the below table. The dates and times should be outputted sorted by the name of the capital. You don’t need to output the capital name.

Here is a copy of the list of capitals. Where there is more than one option your code may choose any one of them.

$$\begin{array}{l|l} \text{COUNTRY} & \text{CAPITAL CITY} \\ \hline \text{United Arab Emirates} & \text{Abu Dhabi} \\ \hline \text{Nigeria} & \text{Abuja} \\ \hline \text{Ghana} & \text{Accra} \\ \hline \text{Ethiopia} & \text{Addis Ababa} \\ \hline \text{Algeria} & \text{Algiers} \\ \hline \text{Jordan} & \text{Amman} \\ \hline \text{Netherlands} & \text{Amsterdam} \\ \hline \text{Andorra} & \text{Andorra la Vella} \\ \hline \text{Turkey} & \text{Ankara} \\ \hline \text{Madagascar} & \text{Antananarivo} \\ \hline \text{Samoa} & \text{Apia} \\ \hline \text{Turkmenistan} & \text{Ashgabat} \\ \hline \text{Eritrea} & \text{Asmara} \\ \hline \text{Paraguay} & \text{Asuncion} \\ \hline \text{Greece} & \text{Athens} \\ \hline \text{Iraq} & \text{Baghdad} \\ \hline \text{Azerbaijan} & \text{Baku} \\ \hline \text{Mali} & \text{Bamako} \\ \hline \text{Brunei} & \text{Bandar Seri Begawan} \\ \hline \text{Thailand} & \text{Bangkok} \\ \hline \text{Central African Republic} & \text{Bangui} \\ \hline \text{Gambia} & \text{Banjul} \\ \hline \text{Saint Kitts and Nevis} & \text{Basseterre} \\ \hline \text{China} & \text{Beijing} \\ \hline \text{Lebanon} & \text{Beirut} \\ \hline \text{Northern Ireland} & \text{Belfast} \\ \hline \text{Serbia} & \text{Belgrade} \\ \hline \text{Belize} & \text{Belmopan} \\ \hline \text{Germany} & \text{Berlin} \\ \hline \text{Switzerland} & \text{Bern} \\ \hline \text{Kyrgyzstan} & \text{Bishkek} \\ \hline \text{Guinea-Bissau} & \text{Bissau} \\ \hline \text{Colombia} & \text{Bogota} \\ \hline \text{Brazil} & \text{Brasilia} \\ \hline \text{Slovakia} & \text{Bratislava} \\ \hline \text{Congo, Republic of the} & \text{Brazzaville} \\ \hline \text{Barbados} & \text{Bridgetown} \\ \hline \text{Belgium} & \text{Brussels} \\ \hline \text{Romania} & \text{Bucharest} \\ \hline \text{Hungary} & \text{Budapest} \\ \hline \text{Argentina} & \text{Buenos Aires} \\ \hline \text{Egypt} & \text{Cairo} \\ \hline \text{Australia} & \text{Canberra} \\ \hline \text{Venezuela} & \text{Caracas} \\ \hline \text{Wales} & \text{Cardiff} \\ \hline \text{Saint Lucia} & \text{Castries} \\ \hline \text{Moldova} & \text{Chisinau} \\ \hline \text{Sri Lanka} & \text{Colombo} \\ \hline \text{Guinea} & \text{Conakry} \\ \hline \text{Denmark} & \text{Copenhagen} \\ \hline \text{Senegal} & \text{Dakar} \\ \hline \text{Syria} & \text{Damascus} \\ \hline \text{Bangladesh} & \text{Dhaka} \\ \hline \text{East Timor} & \text{Dili} \\ \hline \text{Djibouti} & \text{Djibouti} \\ \hline \text{Tanzania} & \text{Dodoma} \\ \hline \text{Qatar} & \text{Doha} \\ \hline \text{Ireland} & \text{Dublin} \\ \hline \text{Tajikistan} & \text{Dushanbe} \\ \hline \text{Scotland} & \text{Edinburgh} \\ \hline \text{Sierra Leone} & \text{Freetown} \\ \hline \text{Tuvalu} & \text{Funafuti} \\ \hline \text{Botswana} & \text{Gaborone} \\ \hline \text{Guyana} & \text{Georgetown} \\ \hline \text{Burundi} & \text{Gitega} \\ \hline \text{Guatemala} & \text{Guatemala City} \\ \hline \text{Vietnam} & \text{Hanoi} \\ \hline \text{Zimbabwe} & \text{Harare} \\ \hline \text{Cuba} & \text{Havana} \\ \hline \text{Finland} & \text{Helsinki} \\ \hline \text{Solomon Islands} & \text{Honiara} \\ \hline \text{Pakistan} & \text{Islamabad} \\ \hline \text{Indonesia} & \text{Jakarta} \\ \hline \text{South Sudan} & \text{Juba} \\ \hline \text{Afghanistan} & \text{Kabul} \\ \hline \text{Uganda} & \text{Kampala} \\ \hline \text{Nepal} & \text{Kathmandu} \\ \hline \text{Sudan} & \text{Khartoum} \\ \hline \text{Ukraine} & \text{Kiev} \\ \hline \text{Rwanda} & \text{Kigali} \\ \hline \text{Jamaica} & \text{Kingston} \\ \hline \text{Saint Vincent and the Grenadines} & \text{Kingstown} \\ \hline \text{Congo, Democratic Republic of the} & \text{Kinshasa} \\ \hline \text{Malaysia} & \text{Kuala Lumpur} \\ \hline \text{Kuwait} & \text{Kuwait City} \\ \hline \text{Bolivia} & \text{La Paz (administrative), Sucre (official)} \\ \hline \text{Gabon} & \text{Libreville} \\ \hline \text{Malawi} & \text{Lilongwe} \\ \hline \text{Peru} & \text{Lima} \\ \hline \text{Portugal} & \text{Lisbon} \\ \hline \text{Slovenia} & \text{Ljubljana} \\ \hline \text{Togo} & \text{Lome} \\ \hline \text{England} & \text{London} \\ \hline \text{United Kingdom} & \text{London} \\ \hline \text{Angola} & \text{Luanda} \\ \hline \text{Zambia} & \text{Lusaka} \\ \hline \text{Luxembourg} & \text{Luxembourg} \\ \hline \text{Spain} & \text{Madrid} \\ \hline \text{Marshall Islands} & \text{Majuro} \\ \hline \text{Equatorial Guinea} & \text{Malabo} \\ \hline \text{Maldives} & \text{Male} \\ \hline \text{Nicaragua} & \text{Managua} \\ \hline \text{Bahrain} & \text{Manama} \\ \hline \text{Philippines} & \text{Manila} \\ \hline \text{Mozambique} & \text{Maputo} \\ \hline \text{Lesotho} & \text{Maseru} \\ \hline \text{Eswatini (Swaziland)} & \text{Mbabana} \\ \hline \text{Palau} & \text{Melekeok} \\ \hline \text{Mexico} & \text{Mexico City} \\ \hline \text{Belarus} & \text{Minsk} \\ \hline \text{Somalia} & \text{Mogadishu} \\ \hline \text{Monaco} & \text{Monaco} \\ \hline \text{Liberia} & \text{Monrovia} \\ \hline \text{Uruguay} & \text{Montevideo} \\ \hline \text{Comoros} & \text{Moroni} \\ \hline \text{Russia} & \text{Moscow} \\ \hline \text{Oman} & \text{Muscat} \\ \hline \text{Chad} & \text{N'Djamena} \\ \hline \text{Kenya} & \text{Nairobi} \\ \hline \text{Bahamas} & \text{Nassau} \\ \hline \text{Myanmar (Burma)} & \text{Nay Pyi Taw} \\ \hline \text{India} & \text{New Delhi} \\ \hline \text{Niger} & \text{Niamey} \\ \hline \text{Cyprus} & \text{Nicosia} \\ \hline \text{Nauru} & \text{No official capital} \\ \hline \text{Mauritania} & \text{Nouakchott} \\ \hline \text{Tonga} & \text{Nuku'alofa} \\ \hline \text{Kazakhstan} & \text{Nur-Sultan} \\ \hline \text{Norway} & \text{Oslo} \\ \hline \text{Canada} & \text{Ottawa} \\ \hline \text{Burkina Faso} & \text{Ouagadougou} \\ \hline \text{Federated States of Micronesia} & \text{Palikir} \\ \hline \text{Panama} & \text{Panama City} \\ \hline \text{Suriname} & \text{Paramaribo} \\ \hline \text{France} & \text{Paris} \\ \hline \text{Cambodia} & \text{Phnom Penh} \\ \hline \text{Montenegro} & \text{Podgorica} \\ \hline \text{Haiti} & \text{Port au Prince} \\ \hline \text{Mauritius} & \text{Port Louis} \\ \hline \text{Papua New Guinea} & \text{Port Moresby} \\ \hline \text{Trinidad and Tobago} & \text{Port of Spain} \\ \hline \text{Vanuatu} & \text{Port Vila} \\ \hline \text{Benin} & \text{Porto Novo} \\ \hline \text{Czech Republic (Czechia)} & \text{Prague} \\ \hline \text{Cape Verde} & \text{Praia} \\ \hline \text{South Africa} & \text{Pretoria, Bloemfontein, Cape Town} \\ \hline \text{Kosovo} & \text{Pristina} \\ \hline \text{North Korea} & \text{Pyongyang} \\ \hline \text{Ecuador} & \text{Quito} \\ \hline \text{Morocco} & \text{Rabat} \\ \hline \text{Iceland} & \text{Reykjavik} \\ \hline \text{Latvia} & \text{Riga} \\ \hline \text{Saudi Arabia} & \text{Riyadh} \\ \hline \text{Italy} & \text{Rome} \\ \hline \text{Dominica} & \text{Roseau} \\ \hline \text{Grenada} & \text{Saint George's} \\ \hline \text{Antigua and Barbuda} & \text{Saint John's} \\ \hline \text{Costa Rica} & \text{San Jose} \\ \hline \text{San Marino} & \text{San Marino} \\ \hline \text{El Salvador} & \text{San Salvador} \\ \hline \text{Yemen} & \text{Sana'a} \\ \hline \text{Chile} & \text{Santiago} \\ \hline \text{Dominican Republic} & \text{Santo Domingo} \\ \hline \text{Sao Tome and Principe} & \text{Sao Tome} \\ \hline \text{Bosnia and Herzegovina} & \text{Sarajevo} \\ \hline \text{South Korea} & \text{Seoul} \\ \hline \text{Singapore} & \text{Singapore} \\ \hline \text{North Macedonia (Macedonia)} & \text{Skopje} \\ \hline \text{Bulgaria} & \text{Sofia} \\ \hline \text{Sweden} & \text{Stockholm} \\ \hline \text{Fiji} & \text{Suva} \\ \hline \text{Taiwan} & \text{Taipei} \\ \hline \text{Estonia} & \text{Tallinn} \\ \hline \text{Kiribati} & \text{Tarawa Atoll} \\ \hline \text{Uzbekistan} & \text{Tashkent} \\ \hline \text{Georgia} & \text{Tbilisi} \\ \hline \text{Honduras} & \text{Tegucigalpa} \\ \hline \text{Iran} & \text{Tehran} \\ \hline \text{Israel} & \text{Tel Aviv (Jerusalem has limited recognition)} \\ \hline \text{Bhutan} & \text{Thimphu} \\ \hline \text{Albania} & \text{Tirana (Tirane)} \\ \hline \text{Japan} & \text{Tokyo} \\ \hline \text{Libya} & \text{Tripoli} \\ \hline \text{Tunisia} & \text{Tunis} \\ \hline \text{Mongolia} & \text{Ulaanbaatar} \\ \hline \text{Liechtenstein} & \text{Vaduz} \\ \hline \text{Malta} & \text{Valletta} \\ \hline \text{Vatican City} & \text{Vatican City} \\ \hline \text{Seychelles} & \text{Victoria} \\ \hline \text{Austria} & \text{Vienna} \\ \hline \text{Laos} & \text{Vientiane} \\ \hline \text{Lithuania} & \text{Vilnius} \\ \hline \text{Poland} & \text{Warsaw} \\ \hline \text{United States} & \text{Washington D.C} \\ \hline \text{New Zealand} & \text{Wellington} \\ \hline \text{Namibia} & \text{Windhoek} \\ \hline \text{Côte d'Ivoire (Ivory Coast)} & \text{Yamoussoukro} \\ \hline \text{Cameroon} & \text{Yaounde} \\ \hline \text{Armenia} & \text{Yerevan} \\ \hline \text{Croatia} & \text{Zagreb} \\ \hline \end{array}$$

Your code may use any libraries you like and may even access the Internet to get relevant data. It may also output the dates and times in any easily human readable form you choose. You should assume the code is run in 2020. The time you give for sunset will be deemed correct if there is at least one website or data source (that existed before this question was posed) that agrees with you.

\$\endgroup\$
14
  • \$\begingroup\$ What is unclear about the question? \$\endgroup\$
    – user9207
    May 25 '20 at 4:56
  • 4
    \$\begingroup\$ The question is pretty clear, but the task is under-specified (we don't know what would be a valid sunset time) and not self-contained. Also, allowing access to the Internet means that we can just store the results somewhere and download that file, making it basically a duplicate of this challenge. \$\endgroup\$
    – Arnauld
    May 25 '20 at 9:02
  • 1
    \$\begingroup\$ @Anush All the information needed to write the code should be in the post (eg don't just say for all capital cities on Earth and give a link to them, actually list them in the question.) This is because you can't assume links will always work forever and ever. \$\endgroup\$
    – Noodle9
    May 25 '20 at 10:19
  • 1
    \$\begingroup\$ @KevinCruijssen OK. I am happy with your suggestion. \$\endgroup\$
    – user9207
    May 26 '20 at 9:14
  • 1
    \$\begingroup\$ @mypronounismonicareinstate There is a huge list of cities. Or do you mean what longitude/latitude each city has, or what time zone they are in? \$\endgroup\$ May 26 '20 at 12:05
4
\$\begingroup\$

05AB1E, 106 bytes

’»‚†Ò‚Ÿ.ŒŒ/‚ïŒÇíÇ.htm’.w’¡Õ="17">’¡ε'<¡н„,(S¡н}¦āÈÏ{ε’Š¹.ŒŒ/€±?q=¿Ô+ÿ+ƒÜ’.w©’ƒ£-c·¼:2">’¡θ5£®žg…ÿ (¡θ')¡н‚

Couple of assumptions, which are allowed and/or required for the challenges:

  1. The program is run in 2020.
  2. The url https://geographyfieldwork.com/WorldCapitalCities.htm is accessible and contains the html shown in the second TIO below
  3. Google is accessible and contains the html shown in the fourth TIO below
  4. [Temporarily] Assumes Elixir (in which 05AB1E is built) accessing a website makes adjustments similar to a browser (i.e. implicitly adds https:// and converts spaces to %20). I'll try to verify this locally in a moment. If this isn't true, I'll delete this answer and fix it.

Outputs all times in their respective time zones instead of all in GMT as the challenge description states, which OP allowed in the comments.
This will be output as a list of pairs, where each pair is the time with a timezone (i.e. ["21:46","CEST"]).

No direct TIO, since the .w builtin (to access a website) is disabled on TIO. But:

’»‚†Ò‚Ÿ.ŒŒ/‚ïŒÇíÇ.htm’

Try this part online to see the generation of the URL.

’¡Õ="17">’¡ε'<¡н„,(S¡н}¦āÈÏ{

Try this part online to see it creates the sorted list of cities based on the website's HTML content.

’Š¹.ŒŒ/€±?q=¿Ô+ÿ+ƒÜ’

Try this part online to see the generation of the Google-search URL.

©’ƒ£-c·¼:2">’¡θ5£®žg…ÿ (¡θ')¡н‚

Try the TIO in this pastebin (the link of the TIO itself is too large.. -_-) to see it creates the correct result for a given city based on the Google's search result HTML content.

Explanation:

’»‚†Ò‚Ÿ.ŒŒ/‚ïŒÇíÇ.htm’ # Push dictionary string "geographyfieldwork.com/worldcapitalcities.htm"
 .w                    # Access this website and read its HTML content
   ’¡Õ="17">’          # Push dictionary string 'height="17">'
             ¡         # Split the html on that
              ε        # Map each string-part to:
               '<¡    '#  Split it on "<"
                  н    #  And only leave the first part
               „,(S¡   #  Split that part by "," and "("
                    н  #  And again only leave the first part
              }¦       # After the map: remove the first empty string
                       # (we now have a list of all unordered countries + cities)
                ā      # Push a list in the range [1,length] (without popping)
                 È     # Check for each value whether it's odd
                  Ï    # Only leave the strings at those truthy values
                   {   # And sort those alphabetically

We now have a sorted list of all cities.

ε                      # Map each city to:
 ’Š¹.ŒŒ/€±?q=¿Ô+ÿ+ƒÜ’  #  Push dictionary string "google.com/search?q=sunset+ÿ+today",
                       #  where the `ÿ` is automatically filled with the city
 .w                    #  Access this website and read its HTML content
   ©                   #  Store it in variable `®` (without popping)
    ’ƒ£-c·¼:2">’      "#  Push dictionary string 'line-clamp:2">'
                ¡      #  Split the content on that
                 θ     #  Only leave the last (second) part
                  5£   #  Only leave the first 5 characters (the time)
   ®                   #  Push the HTML content again
    žg                 #  Push the current year (2020)
      …ÿ (             #  Push string "ÿ (", where the `ÿ` is filled with 2020: "2020 ("
          ¡            #  Split the content on that
           θ           #  Only leave the last (second) part
            ')¡       '#  Split it on ")"
               н       #  And leave the first item (the timezone)
   ‚                   #  Pair the time and timezone strings together
                       # (after which the resulting mapped pair of strings is output implicitly)

See this 05AB1E tip of mine (section How to use the dictionary?) to understand why ’»‚†Ò‚Ÿ.ŒŒ/‚ïŒÇíÇ.htm’ is "geographyfieldwork.com/worldcapitalcities.htm"; ’¡Õ="17">’ is 'height="17">'; ’Š¹.ŒŒ/€±?q=¿Ô+ÿ+ƒÜ’ is "google.com/search?q=sunset+ÿ+today"; and ’ƒ£-c·¼:2">’ is 'line-clamp:2">'.

\$\endgroup\$
4
  • \$\begingroup\$ Very nice! (Typo: GTM -> GMT) \$\endgroup\$
    – user9207
    May 26 '20 at 15:57
  • 1
    \$\begingroup\$ @Anush Fixed the typo ;) \$\endgroup\$ May 26 '20 at 15:58
  • 1
    \$\begingroup\$ Does Google return the time of sunset for somtething like sunset La Paz (administrative), Sucre (official) today (or does this somehow handle such cases?)? \$\endgroup\$ May 26 '20 at 17:11
  • \$\begingroup\$ @mypronounismonicareinstate Thanks for noticing! Fixed that one, as well as Tirana (Tirane), Tel Aviv (Jerusalem has limited recognition) and Pretoria, Bloemfontein, Cape Town at the cost of 6 bytes. \$\endgroup\$ May 26 '20 at 17:20