13
\$\begingroup\$

Seven countries lay official claims to parts of Antarctica: Argentina, Australia, Chile, France, New Zealand, Norway, and the United Kingdom. We will focus only on the claims of the main Antarctic landmass south of 60° S, which are:

  • Chile: between 90° W and 53° W
  • United Kingdom: between 80° W and 20° W
  • Argentina: between 74° W and 25° W
  • Norway: between 20° W and 44°38 E
  • Australia: between 44°38 E and 136°11 E; and between 142°2 E and 160° E
  • France: between 136°11 E and 142°2 E
  • New Zealand: between 160° E and 150° W

The region between 150° W and 90° W is unclaimed. Note also that Chile's, the UK's, and Argentina's claims overlap to some degree.

Here is a map:

Map of the world with all but Antarctica blurred, a 0° line of longitude marked, and claims of Antarctica highlighted. (exact description of claims above)

The above image modified from work at https://w.wiki/4e3R; used under CC-BY-SA 3.0.

More information and maps are available on Wikipedia.

All of these claims extend northwards from the South Pole at 90° S. It is unclear where Norway's stops, but it does not matter because we will only ask about the claims just north of the South Pole.

Task

Your task is to encode the information about the claims in the fewest bytes possible: given an input \$ x \$, output the set of countries which claim Antarctica at longitude \$ x \$° and latitude 89.9° S.

You should represent outputs of countries using any seven distinct values, within reason.

For the areas where multiple claims overlap (which are variously those of Argentina, Chile, and the United Kingdom), you should output the multiple values representing those countries. These multiple outputs may be in any order.

For the unclaimed region between 150° W and 90° W, you should output an empty list.

Test cases

     Input     ->  Output(s)
--------------------------------------
  0.0 /  360.0 ->  [Norway]
180.0 / -180.0 ->  [New Zealand]
223.2 / -136.8 ->  []
270.1 /  -89.9 ->  [Chile]
280.5 /  -79.5 ->  [Chile, United Kingdom]
296.6 /  -63.4 ->  [Argentina, Chile, United Kingdom]
337.6 /  -22.4 ->  [United Kingdom]
340.3 /  -19.7 ->  [Norway]
 44.6          ->  [Norway]
 44.7          ->  [Australia]
139.4          ->  [France]
142.0          ->  [France]
142.1          ->  [Australia]
161.8          ->  [New Zealand]
190.5 / -169.5 ->  [New Zealand]

Rules

  • Your code must support non-integer longitudes. Small errors due to floating-point precision errors are acceptable
  • You may choose to require input \$ x \$ between -180° and 180° (with negative values representing west of the Prime Meridian), or between 0° and 360°. You only need to support one of the two edges of whichever range you choose
  • Behaviour exactly on the boundaries of claims (e.g. at exactly 20° W) is undefined
  • You may use any standard I/O method
  • Standard loopholes are forbidden
  • This is , so the shortest code in bytes wins
\$\endgroup\$
0

4 Answers 4

5
\$\begingroup\$

Charcoal, 137 bytes

≔×⁶⁰NθEΦE⪪”}∧¡8↥″⟧MX⬤~m→⊖⊗9⁸'DQζF%f¹ψz‖aνy("⟲?⎚‹3I‹4↥GNOk³▷H!J;⁵´j‹Z*I:↷¡!β↑}1⊞↘≦QêY(¦≔πω/_²≔▶⁶ω≧N4Þ⁰^⊕﹪WÞ|l⎚V2⊖¬|η&f≔”¶⪪ι ››I⊟ιθ›I⊟ιθ⪫ι 

Try it online! Link is to verbose version of code. Assumes input is non-negative but less than 360. Not much shorter than the JS version because I output country names.

≔×⁶⁰Nθ

Multiply the input by 60 to convert it into minutes.

EΦE⪪”...”¶⪪ι ››I⊟ιθ›I⊟ιθ⪫ι 

Split the compressed data string on newlines and again on spaces. Keep only those where the input is between the boundaries or on the lower boundary. Fix up "United Kingdom" back into a single string (using "UK" would save a byte, and double-spacing the output would save a further 3 bytes).

78 bytes using custom output:

≔×⁶⁰NθI﹪⌕AEE⪪”←&!ω\⟧≕G⁵↑³yυ~r,S⦃›F⁷ω(D⧴aM↖G≕%›"‽.⊞⭆↓‽ⅈ0ÀG→$”¶⪪ι ››I⊟ιθ›I⊟ιθ¹¦⁷

Try it online! Link is to verbose version of code. Explanation: Obtains the indices of the matching ranges and reduces modulo 7 to output digits according to the following key:

0 Norway
1 Australia
2 France
3 New Zealand
4 Chile
5 United Kingdom
6 Argentina

(Note that the ranges are ordered slightly differently in this version.)

\$\endgroup\$
5
\$\begingroup\$

JavaScript (ES10), 128 bytes

Expects a signed value.

Returns 0 for New Zealand, 2 for Argentina, 32 for Norway, 34 for Chile, 64 for United Kingdom, 65 for France, 98 for Australia.

v=>[90,100,106,160,a=13478/60,b=19322/60,c=18971/60,0,340].flatMap((x,i)=>v<x|v>[127,160,155,a,c,340,b,30][i]?[]:x*29&99,v+=180)

Try it online!

\$\endgroup\$
2
  • \$\begingroup\$ when you input '337.6', shouldnt you get 3 countries instead of 1? your solution seems flawed \$\endgroup\$
    – Luke_
    Jan 7 at 11:44
  • \$\begingroup\$ @Luke_ As mentioned, this expects a signed value, i.e. in -180 ... 180. \$\endgroup\$
    – Arnauld
    Jan 7 at 13:52
4
\$\begingroup\$

C (gcc), 247 172 bytes

  • -7 thanks to pxeger
  • -3 by changing the output values (and fixed a bug)
  • -6 thanks to gastropner
  • -8 by changing the range format to (offset, starting longitude)
  • -61(!) thanks to Neil

Takes a floating-point longitude from [0, 360) degrees, but performs all the computations using integer minutes. For Norway, I split up the range into two sections to make calculations easier.

Countries are expressed in the following format:

  • 0: Norway
  • 1: Australia
  • 2: Chile
  • 3: United Kingdom
  • 4: Argentina
  • 5: France
  • 6: New Zealand
g[]={1078,8522,2678,0,3e3,9600,351,8171,2940,17160,3600,16800,2220,16200,5493,2678,1201,20400},i,j,*a;f(float l){for(i=l*60,j=9,a=g;j--;)*a+++0u>i-*a++&&printf("%d,",j%7);}

Try it online!

Ungolfed:

g[]={
  1078,8522, // Australia
  2678,0, // Norway
  3000,9600, // New Zealand
  351,8171, // France
  2940,17160, // Argentina
  3600,16800, // United Kingdom
  2220,16200, // Chile
  5493,2678, // Australia
  1201,20400 // Norway
  },
  i,j,*a;

f(float l) {
  for(i=l*60, // Convert input into minutes
      j=9,a=g;j--;)
    *a+++0u>i-*a++&& // (Input-start longitude) within range?
      printf("%d,",j%7);
}
\$\endgroup\$
6
  • \$\begingroup\$ You don't need the (int) cast because i is declared as an int already, saving 7 bytes (...for(i=l*60,...) \$\endgroup\$
    – pxeger
    Jan 7 at 7:48
  • 1
    \$\begingroup\$ Thanks! My original solution involved using modulos, which required casting. I missed the cast when I simplified the code. \$\endgroup\$
    – ErikF
    Jan 7 at 7:52
  • \$\begingroup\$ Flipping high/low values in the list (x(16200,18420) -> x(18420,16200)) and changing the test to i<*a++&&i>=*a allows you to reuse 0 as a sentinel, making the macro (int[]){a,0}, and the loop test *a, saving two more bytes. \$\endgroup\$
    – gastropner
    Jan 7 at 8:53
  • \$\begingroup\$ g[]={20400,21600,2678,8171,16200,18420,16800,20400,17160,20100,8171,8522,9600,12600,0,2678,8522,9600},i,j,*a;f(float l){for(i=l*60,j=0,a=g;j<9;a++,j++)i>=*a++&&i<*a&&printf("%d,",j%7);} is only 185 bytes, and I think it should be possible to eliminate j to save 4 more bytes. \$\endgroup\$
    – Neil
    Jan 7 at 9:08
  • \$\begingroup\$ 172 bytes (Order of output reversed.) \$\endgroup\$
    – gastropner
    Jan 8 at 8:25
2
\$\begingroup\$

05AB1E, 55 54 bytes

60*ò•1ζ_ʒǝ=¶Ò´™p]·ÐΘä¥ËrªÞ÷Â0[₁µÑ…εC`£•Ž≠¶в2ô€ŸQOƶ0K7%

-1 byte thanks to @Neil by also using modulo-7.

Input as a longitude float in the range \$[0,360)\$. Outputs \$0\$ for Argentina, \$1\$ for Australia, \$2\$ for Norway, \$3\$ for France, \$4\$ for New Zealand, \$5\$ for Chile, and \$6\$ for the United Kingdom.

Try it online or verify all test cases.

Explanation:

60*              # Multiply the (implicit) input by 60
   ò             # (Bankers) round it to the nearest integer
•1ζ_ʒǝ=¶Ò´™p]·ÐΘä¥ËrªÞ÷Â0[₁µÑ…εC`£•
                 # Push compressed integer 129995249012016373632115353299026583238712674313934551571472125857818360468822
 Ž≠¶             # Push compressed integer 21601
    в            # Convert the larger integer to base-21601 as list:
                 #  [2678,8171,0,2678,8171,8522,9600,12600,16200,18420,16800,20400,17160,20100,8522,9600,20400,21600]
     2ô          # Split it into parts of size 2:
                 #  [[2678,8171],[0,2678],...]
       €Ÿ        # Map each pair to an inclusive ranged list
                 #  [[2678,2679,2680,...,8170,8171],[0,1,2,...,2677,2678],...]
         Q       # Check for each inner integer if its equal to the round(input*60)
          O      # Sum each inner list, resulting in 1 if it was within that range
           ƶ     # Multiply each by its 1-based index
            0K   # Remove all 0s
              7% # Modulo-7 to transform the 8 to 1 and 9 to 2
                 # (after which the result is output implicitly)

See this 05AB1E tip of mine (sections How to compress large integers? and How to compress integer lists?) to understand why •1ζ_ʒǝ=¶Ò´™p]·ÐΘä¥ËrªÞ÷Â0[₁µÑ…εC`£• is 129995249012016373632115353299026583238712674313934551571472125857818360468822; Ž≠¶ is 21601; and •1ζ_ʒǝ=¶Ò´™p]·ÐΘä¥ËrªÞ÷Â0[₁µÑ…εC`£•Ž≠¶в is [2678,8171,0,2678,8171,8522,9600,12600,16200,18420,16800,20400,17160,20100,8522,9600,20400,21600].


Outputting with the actual title-cased countries from the dictionary would be 85 bytes instead, by removing the no longer necessary 7% and adding some additional trailing bytes:

60*ò•1ζ_ʒǝ=¶Ò´™p]·ÐΘä¥ËrªÞ÷Â0[₁µÑ…εC`£•Ž≠¶в2ô€ŸQOƶ0K”²Ðˆ‚¬ìˆÖ€¢1¸ŽƒŠ0”#sèεT”™ÆŠß”#1ú‡

Try it online or verify all test cases.

Explanation:

”²Ðˆ‚¬ìˆÖ€¢1¸ŽƒŠ0”
             # Push dictionary string "Argentina Australia Norway France New1 Chile United0"
 #           # Split on spaces
  sè         # Modular 0-based index the calculated value into this list
    ε        # Map over each result:
     T       #  Push 10
      ”™ÆŠß” #  Push dictionary string "Zealand Kingdom"
       #     #  Split it on spaces
        1ú   #  Pad each with a leading space
          ‡  #  Transliterate the "1" to " Zealand" and "0" to " Kingdom"
             # (after which the resulting list is output implicitly)

See the same 05AB1E tip I linked earlier (section How to use the dictionary?) to understand why ”²Ðˆ‚¬ìˆÖ€¢1¸ŽƒŠ0” is "Argentina Australia Norway France New1 Chile United0" and ”™ÆŠß” is "Zealand Kingdom".

\$\endgroup\$
4
  • \$\begingroup\$ Can you not arrange for positions 0 and 1 to refer to the same two countries as 7 and 8 thus allowing you to use mod 7 to collapse them to the same result? \$\endgroup\$
    – Neil
    Jan 7 at 9:09
  • \$\begingroup\$ @Neil I can, but I'm afraid it won't save any bytes because the ƶ0K would then also require a -1 (<) before the modulo 7: try it online. \$\endgroup\$ Jan 7 at 9:20
  • 1
    \$\begingroup\$ That's just a numbering issue; if you remove the -1 then the first and last two countries still collapse to the same result, they're just off by 1 from my 0-based indexing attempt. \$\endgroup\$
    – Neil
    Jan 7 at 9:43
  • \$\begingroup\$ @Neil Ah, I'm an idiot. You're complete right! Thanks for -1, I'll update my answer. \$\endgroup\$ Jan 7 at 9:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.