“As we travel the universe…”

Arnauld 12/05/2018. 20 answers, 4.860 views
code-challenge approximation

You'll be given the name of one of the 20 biggest objects in the Solar System. Your task is to return an approximation of its radius, expressed in kilometers.

This is a where your score consists of the length of your code (in bytes) multiplied by a penalty ratio \$\ge 1\$, based on your worst approximation. Therefore, the lowest score wins.

"As we travel the universe" is the last line of the song Planet Caravan by Black Sabbath, also later covered by Pantera.

The Solar System objects

Source: Wikipedia

NB: The rank is given for information only. The input is the name of the object.

  n | Object   | Radius (km)
----+----------+-------------
  1 | Sun      |   696342
  2 | Jupiter  |    69911
  3 | Saturn   |    58232
  4 | Uranus   |    25362
  5 | Neptune  |    24622
  6 | Earth    |     6371
  7 | Venus    |     6052
  8 | Mars     |     3390
  9 | Ganymede |     2634
 10 | Titan    |     2575
 11 | Mercury  |     2440
 12 | Callisto |     2410
 13 | Io       |     1822
 14 | Moon     |     1737
 15 | Europa   |     1561
 16 | Triton   |     1353
 17 | Pluto    |     1186
 18 | Eris     |     1163
 19 | Haumea   |      816
 20 | Titania  |      788

Or as copy-paste friendly lists:

'Sun', 'Jupiter', 'Saturn', 'Uranus', 'Neptune', 'Earth', 'Venus', 'Mars', 'Ganymede', 'Titan', 'Mercury', 'Callisto', 'Io', 'Moon', 'Europa', 'Triton', 'Pluto', 'Eris', 'Haumea', 'Titania'
696342, 69911, 58232, 25362, 24622, 6371, 6052, 3390, 2634, 2575, 2440, 2410, 1822, 1737, 1561, 1353, 1186, 1163, 816, 788

Your score

Let \$R_n\$ be the expected radius of the \$n^{th}\$ object and let \$A_n\$ be the answer of your program for this object.

Then your score is defined as:

$$S=\left\lceil L\times\max_{1\le i \le20}\left({\max\left(\frac{A_i}{R_i},\frac{R_i}{A_i}\right)^2}\right)\right\rceil$$

where \$L\$ is the length of your code in bytes.

Example:

If the size of your code is \$100\$ bytes and your worst approximation is on the Moon with an estimated radius of \$1000\$ km instead of \$1737\$ km, then your score would be:

$$S=\left\lceil 100\times{\left(\frac{1737}{1000}\right)^2}\right\rceil=302$$

The lower, the better.

Recommended header for your answer:

Language, 100 bytes, score = 302

You can use this script to compute your score (first line = code length, next 20 lines = your outputs, from Sun to Titania).

Rules

  • You may take the name of the object in either full lowercase, full uppercase or exactly as described above (title case). Other mixed cases are not allowed.
  • The input is guaranteed to be one of the 20 possible names.
  • You may return either integers or floats. In both cases, the penalty must be computed directly with these values (not rounded values in case of floats).
  • You must return positive values.
  • Empty programs are not allowed.

20 Answers


AdmBorkBork 12/05/2018.

PowerShell, 3 bytes, score 3637

2e4

Try it online!

Very naive, boring, implementation; just returns 20000 no matter the input. Experimentation with things like special-casing the sun or using floating-point values instead of 2 all resulted in worse scores because the length of code increased enough to offset any size-comparison gains.


Dennis 12/06/2018.

Jelly, 34 bytes, score = 37

OḌ“⁸|5/!‘%ƒị“RNFLOJMjs⁽\u[USJ‘1.1*

Input is in uppercase, output is the power of 1.1 with the least error.

Try it online!

How it works

OḌ“⁸|5/!‘%ƒị“RNFLOJMjs⁽\u[USJ‘1.1*  Main link. Argument: s (string)

O                                   Ordinal; map the char in s to their code points.
                                        "ERIS" -> [69,82,73,83]
 Ḍ                                  Undecimal; treat the result as an array of digits
                                    in base 10 and convert it to integer.
                                        [69,82,73,83] -> 69000+8200+730+83 = 78013
  “⁸|5/!‘                           Literal; yield [136, 124, 53, 47, 33].
         %ƒ                         Fold the array by modulus, using the computed
                                    integer as initial value.
                                        78013 -> 78013%136%124%53%47%33 = 32
            “RNFLOJMjs⁽\u[USJ‘      Literal; yield [82, 78, 70, 76, 79, 74, 77, ...
                                    106, 115, 141, 92, 117, 91, 85, 83, 74].
           ị                        Retrieve the element from the array to the right,
                                    at the index to the left.
                                    Indexing is 1-based and modular.
                                        32 = 16 (mod 16) -> 'J' = 74
                              1.1*  Raise 1.1 to the computed power.
                                        74 = 1.1**74 = 1156.268519450066

Olivier Grégoire 12/06/2018.

Java (JDK), 90 bytes, score = 97

s->("ýCĄ (ᬺ!˂Fɍ".charAt(s.substring(2).chars().sum()%96%49%25)-7)*100

Try it online!

  • This entry uses both undisplayable and multi-byte Unicode characters (but Java accepts them nevertheless). Check the TIO for the accurate code.
  • The input must be title-case.
  • This code rounds the values to the best multiple-of-100 (sometimes up, sometimes down) so that the last two digits can be skipped when encoded, and the value can then be approximated by multiplying by 100.
  • This entry uses various hashes to fit a 25 codepoints string (shortest string I could find).

Credits

  • -48 score (-45 bytes) thanks to Kevin Cruijssen by encoding the radiuses (divided by 100) directly in a String instead of hardcoding them in an explicit int array..

DavidC 12/09/2018.

Wolfram Language 114 103 97 88 86 82 bytes. score = 114 103 97 89 87 83 points

(#&@@EntityValue[Interpreter["AstronomicalObject"]@#,"Radius"]/._String->507)1.61&

At least 6 points saved thanks to Dennis, several more thanks to lirtosiast, and 6 more thanks to user202729.

Although Mathematica can fetch solar system data (as well as much additional astronomical data), some minor tweaks are needed, as explained below.

Interpreter[#,"AstronomicalObject"]& will return the entity (i.e. the machine computable object) associated with the term represented by #.

EntityValue[AstronomicalObject[],"Radius"] returns the radius, in miles, of the entity. In the case of "Haumea", the value, 816.27 (i.e. 507*1.61), is returned.

Multiplication of the radius by 1.61 converts from miles to km. Decimal values, rather than integers, account for much less than 1% error, even in the most extreme case.

[[1]] returns the magnitude without the unit, km. This was later changed to #&@@, yielding the same result.


ovs 12/05/2018.

Python 3, score 95, 95 bytes

lambda n:ord("ؙҢਏാᣣ४ঈ挒ឤ?̰ҋ??ۉՉ怮ܞ੊̔"[int(n,35)%87%52%24-1])

Try it online!


Python 3, score 133, 133 bytes

lambda n:int(f'00e0{10**18+10**6}10x1h2411j4?00??811i1207wazxmwuvko?mw??xc1ze1ldyujz6zysi4?ob??k9lym6w'[int(n,35)%87%52%24-1::23],36)

Try it online!


mazzy 12/06/2018.

Powershell, 150 bytes, score 163

($args|% t*y|?{'Su680J68S57U25N24Ea6V6Ma3.3G2.6Ti2.5Me2.4C2.4I1.8M1.7Eu1.5T1.3P1.2E1.1H.8Titani.8'-cmatch"$(($y+=$_))([\d.]+)"}|%{1kb*$Matches.1})[-1]

Test script:

$f = {
($args|% t*y|?{'Su680J68S57U25N24Ea6V6Ma3.3G2.6Ti2.5Me2.4C2.4I1.8M1.7Eu1.5T1.3P1.2E1.1H.8Titani.8'-cmatch"$(($y+=$_))([\d.]+)"}|%{1kb*$Matches.1})[-1]
}

$penalty = @(
    ,("Sun"      , 696342)
    ,("Jupiter"  ,  69911)
    ,("Saturn"   ,  58232)
    ,("Uranus"   ,  25362)
    ,("Neptune"  ,  24622)
    ,("Earth"    ,   6371)
    ,("Venus"    ,   6052)
    ,("Mars"     ,   3390)
    ,("Ganymede" ,   2634)
    ,("Titan"    ,   2575)
    ,("Mercury"  ,   2440)
    ,("Callisto" ,   2410)
    ,("Io"       ,   1822)
    ,("Moon"     ,   1737)
    ,("Europa"   ,   1561)
    ,("Triton"   ,   1353)
    ,("Pluto"    ,   1186)
    ,("Eris"     ,   1163)
    ,("Haumea"   ,    816)
    ,("Titania"  ,    788)
) | % {
    $s,$expected = $_
    $result = &$f $s
    $ratio = [Math]::Max($result/$expected, $expected/$result)
    $ratio*$ratio
}
$scriptLength = $f.ToString().Length - 2  # -4 if CRLF mode
$penaltyMax = ($penalty|Measure-Object -Maximum).Maximum
$score = $scriptLength * $penaltyMax
"$score = $scriptLength * $penaltyMax"

Output:

162.113324228916 = 150 * 1.08075549485944

Explanation:

  • Names contain letters only, radiuses contain digits and dots. So we can write all the data in a data string and perform a regexp search.
  • The script searches for all substrings from left to right and takes the last result found.
  • The input must be title-case to reduce the data string.
  • The end of line mode is LF only.

Example:

Titania         Triton         Titan
--------------  -------------  -------------
T       -> 1.3  T      -> 1.3  T      -> 1.3
Ti      -> 2.5  Tr     ->      Ti     -> 2.5
Tit     ->      Tri    ->      Tit    ->
Tita    ->      Trit   ->      Tita   ->
Titan   ->      Triton ->      Titan  ->
Titani  -> .8
Titania ->

Result is .8    Result is 1.3  Result is 2.5

Powershell, 178 bytes, score 178

($args|% t*y|?{'Su696342J69911S58232U25362N24622Ea6371V6052Ma3390G2634Ti2575Me2440C2410I1822M1737Eu1561T1353P1186E1163H816Titani788'-cmatch"$(($y+=$_))(\d+)"}|%{+$Matches.1})[-1]

Kevin Cruijssen 12/06/2018.

05AB1E, score 100 66 60 (100 61 56 bytes)

•1∞²îc|I‰∍T‡sÇ3¡ò½в…»Ë•§•1ë£ñƒq£û¿’…•S£y¦¦ÇO96%49%25%èт*

Port of @OlivierGrégoire's Java answer, so if you like this first answer, make sure to upvote him as well!
Input in titlecase.

Verify all test cases.


05AB1E, score 100 (100 bytes)

•*Òâ%ÌÜS…Ùb‹Úi{e!]ɸ·vÌBUSηHã£āðxyµŠ•§•3«8¹ØмS7Ç•S£.•WùηƵ@,Sº,ûεβʒóÃX\¹Θäáá’Ý)”Ωož∞-z.A±D•3ôI2£Iθ«kè

Input in full lowercase. Outputs the exact radius, so no penalty is added.

Verify all test cases.

Explanation:

•*Òâ%ÌÜS…Ùb‹Úi{e!]ɸ·vÌBUSηHã£āðxyµŠ•
                   # Compressed integer 696342699115823225362246226371605233902634257524402410182217371561135311861163816788
 §                 # Casted to string (bug, should have been implicitly..)
  •3«8¹ØмS7Ç•      # Compressed integer 65555444444444444433
   S               # Converted to a list of digits: [6,5,5,5,5,4,4,4,4,4,4,4,4,4,4,4,4,4,3,3]
    £              # The first integer is split into parts of that size: ["696342","69911","58232","25362","24622","6371","6052","3390","2634","2575","2440","2410","1822","1737","1561","1353","1186","1163","816","788"]
     .•WùηƵ@,Sº,ûεβʒóÃX\¹Θäáá’Ý)”Ωož∞-z.A±D•
                   # Compressed string "sunjursanursneeeahvesmasgaetinmeycaoioomoneuatrnploershaatia"
      3ô           # Split into parts of size 3: ["sun","jur","san","urs","nee","eah","ves","mas","gae","tin","mey","cao","ioo","mon","eua","trn","plo","ers","haa","tia"]
        I2£        # The first two characters of the input
           Iθ      # The last character of the input
             «     # Merged together
              k    # Get the index of this string in the list of strings
               è   # And use that index to index into the list of integers
                   # (and output the result implicitly)

See this 05AB1E tip of mine (sections How to compress large integers? and How to compress strings not part of the dictionary?) to understand how the compression used works.

I did create a 70-bytes alternative which would map sun to 600,000; [jupiter,saturn] to 60,000; [uranus,neptune] to 30,000; [earth,venus] to 6,000; [mars,ganymede,titan,mercury,callisto] to 3,000; [io,moon,europa,triton,pluto,eris] to 1,500; and [haumea;titania] to 750. Unfortunately that got a score of 117. I will see if I can get below 100 with an alternative approach later.


LegionMammal978 12/06/2018.

Mathematica, 57 bytes, score = 62 58

-4 bytes/score thanks to lirtosiast!

#&@@WolframAlpha[#<>" size km","Result"]]/._Missing->816&

Just does a Wolfram Alpha lookup for the mean radius.


Erik the Outgolfer 12/05/2018.

Python 2, 155 bytes, score = 155

lambda p:int('G11KK54222111111XXNM8MCO37WQ53YXHE93V8BIF2IMH1WU9KPU2MLN    HGR'['uSJJaSrUNNrEnVsMeGtTMMoCoInMuErTuPsEaHTT'.find(p[7%len(p)]+p[0])/2::20],35)

Try it online!

Surprisingly well for this lazy solution... will look into improving as well. ;-)


Kamil Drakari 12/05/2018.

Japt, 86 bytes, score = 94

g5 ¥'i?788:[7*A³7*L6*LG²G²IIÉHÄDÑDÑCÑCÑGÄÄGÄGECC8]g`suj«a¨Ì¼và@ã/eÖô¶e©rp¤r`bU¯2)z)*L

Try it for all inputs, Calculate the score, or Check the highest error

Very similar to Olivier's original answer. Input is all lowercase.

After various improvements to the output values, the current highest error is Venus at just over 4%.

Explanation now that things are a bit more stable:

¤¥`Éa`?                             :If the fifth character of the input is 'i':
       788                          : Output 788.
          :                         :Otherwise:
           [...]                    : From the array representing radii
                g                   : Get the value at the index:
                 `...`              :  In the string representing names
                      b             :  Find the first index where this string appears:
                       U¯2)         :   The first two characters of the input
                           z)       :  And divide it by two
                             *L     : Multiply that value by 100

The string for the names is sujusaurneeavemagatimecaiomoeutrplerha compressed using Japt's built-in compression. The numbers representing the radii are calculated like so:

                          My value | Actual value
                          ---------+-------------
7 * 10 ^ 3 = 7000 * 100 =   700000 | 696342
7 * 100    = 700  * 100 =    70000 |  69911
6 * 100    = 600  * 100 =    60000 |  58232
16 * 16    = 256  * 100 =    25600 |  25362
16 * 16    = 256  * 100 =    25600 |  24622
64         = 64   * 100 =     6400 |   6371
64 - 1     = 63   * 100 =     6300 |   6052
32 + 1     = 33   * 100 =     3300 |   3390
13 * 2     = 26   * 100 =     2600 |   2634
13 * 2     = 26   * 100 =     2600 |   2575
12 * 2     = 24   * 100 =     2400 |   2440
12 * 2     = 24   * 100 =     2400 |   2410
16 + 1 + 1 = 18   * 100 =     1800 |   1822
16 + 1     = 17   * 100 =     1700 |   1737
16         = 16   * 100 =     1600 |   1561
14         = 14   * 100 =     1400 |   1353
12         = 12   * 100 =     1200 |   1186
12         = 12   * 100 =     1200 |   1163
8          = 8    * 100 =      800 |    816
788                     =      788 |    788

Shaggy 12/06/2018.

Japt, 77 76 75 bytes, score = 75

First pass at this; I wanted to try a 0 penalty solution to give myself a baseline to work off. Will come back to it tomorrow to see what improvements can be made, hopefully still for 0 penalty.

Input is case-insensitive.

n35 %87%52 g"..."ò)mc

Try it or test all inputs

The "..." represents a string containing many unprintables. The codepoints are:

32,32,15,61,11,86,696,342,25,75,699,11,33,90,63,71,24,10,24,40,253,62,60,52,32,32,8,16,11,63,32,32,32,32,58,232,17,37,135,3,246,22,18,22,26,34,7,88

To offer a quick explanation: the string gets split into chunks of 2 characters. We then index into that array using part of ovs' formula plus some index-wrapping and then map the 2 characters to their codepoints.

  • Saved a byte/point thanks to ETH

54 bytes, score = 58

A port of Olivier's solution.

"ýCĄ (ᬺ!˂Fɍ"cU¤¬xc %96%49)-7 *L

Test all inputs


AdmBorkBork 12/05/2018.

PowerShell, 203 bytes, score 203

param($a)if($a-eq'Titan'){2575;exit}(696342,69911,58232,25362,24622,6371,6052,3390,2634,2440,2410,1822,1737,1561,1353,1186,1163,816,788)["SuJuSaUrNeEaVeMaGaMeCaIoMoEuTrPlErHaTi".indexOf(-join$a[0..1])/2]

Try it online!

Very similar to Olivier's answer, now that I see it, but developed independently.


BradC 12/05/2018.

T-SQL, 203 bytes, score = 217

SELECT IIF(v='Titan',26,SUBSTRING(value,3,4))*100
FROM i,STRING_SPLIT('Ca24,Ea64,Er12,Eu16,Ga26,Ha8,Io18,Ju699,Ma34,Me24,Mo17,Ne246,Pl12,Sa582,Su6963,Ti8,Tr14,Ur254,Ve61',',')
WHERE LEFT(v,2)=LEFT(value,2)

Line breaks are for readability only.

Input is taken via pre-existing table i with varchar column v, per our IO standards.

Joins the input table to an in-memory table on the first two characters, and returns the remaining digits x100.

Treats "Titan" as a special case using IIF.


Level River St 12/07/2018.

Ruby, 105 bytes, score 109

->n{7E5/('!)"0 r&zZ&1#}3Mfh-~~d@'[0,j=" =1&%)AM<I>2,-B#($D  7@".index((n[1,9].sum%50+34).chr)].sum-j*32)}

Try it online!

If we divide 700000 by the radii, we get a sequence which increases reasonably linearly (though rather erratically). The increments in the table below can be approximated by the ASCII values of characters. The problem with this approach is it requires the input to be decoded to a value which orders the different names by size.

A minor issue is that the difference between Eris and Haumea is quite large. Three characters ~~d are required to encode this increment in ASCII only format. The planet-to-index string has two "ghost planet"spaces in it to pad the index.

700000/r    increment from previous
0.994774    
9.960407    8.965633
11.95806    1.997657
27.45612    15.49805
28.28129    0.825178
109.2987    81.0174
115.0598    5.761118
205.4106    90.3508
264.3667    58.95612
270.4241    6.057335
285.3861    14.96199
288.9386    3.552524
382.1855    93.24692
400.8877    18.70223
446.0871    45.19939
514.6652    68.57806
587.1349    72.46972
598.7463    11.61144
853.3603    254.6139
883.6827    30.32245

Dennis 12/11/2018.

Jelly, 28 bytes, score = 31

“__ʋ7ṗ“RUu⁽NM\sOSJj[FL‘ḥ1.1*

This uses a configurable hashing built-in that I added to Jelly at @lirtosiast's suggestion.

Input is in titlecase, output is the power of 1.1 with the least error.

Try it online!

How it works

This answer consists of merely two parts.

  • First, “__ʋ7ṗ“RUu⁽NM\sOSJj[FL‘ḥ uses the new built-in to map each of the 20 possible inputs to 15 different integers.
  • Then, 1.1* elevates 1.1 to the computed power.

“__ʋ7ṗ“RUu⁽NM\sOSJj[FL‘ is a literal; every non-quote character is replaced by it's 0-based index in Jelly's code page, yielding \$[95, 95, 169, 55, 242], [82, 85, 117, 141, 78, 77, 92, 115, 79, 83, 74, 106, 91, 70, 76]\$.

The hashing built-in first maps \$[95, 95, 169, 55, 242]\$ to an integer by incrementing each number, then treating the result as the bijective base-250 digits integer and adding \$1\$. This yields \$376510639244\$.

By halving and flooring this integer until the result is \$0\$, we get the sequence \$[376510639244, 188255319622, 94127659811, 47063829905, \dots, 5, 2, 1, 0]\$, which has the forward differences \$[188255319622, 94127659811, 47063829906, \dots, 3, 1, 1]\$.

Next, we generate 64 64-bit integers by applying SHAKE256-4096 to the string representation of the internal representation of 's right argument, then chopping the resulting 4096 bits into 64 64-bit chunks.

now computes the dot product of the 39 differences and the first 39 generated 64-bit integers, modulo \$2^{64}\$. This yields an integer in \$[0, 2^{64})\$.

The list \$[82, 85, 117, 141, 78, 77, 92, 115, 79, 83, 74, 106, 91, 70, 76]\$ has length 15, so we multiply the generated integer by 15 and take the 64 higher bits of the result. This yields an integer in \$[0, 15)\$, which we use to index into the list.

To find the appropriate hash configuration, I've used a brute-forcer in C that is part of the Jelly repo.


Neil 12/06/2018.

Charcoal, 101 bytes, score = 101

I⍘§⪪“_″FJ⁼⦄b\l≕)T‹#⊙xO-nη⁻À↓ζ↥ς§%H8H“ρj✳Hρl× S↶…|UD⎇LkfZ”³⌕⪪”@/rjmq_↙§E▶νF↨oº⁷÷K⁻eDH:_Tbk¦�”²⁺§θ⁰§θχγ

Try it online! Link is to verbose version of code. Explanation:

⁺§θ⁰§θχ

Take the 1st and 11th character (cyclically) of the input string and concatenate them.

⌕⪪”@/rjmq_↙§E▶νF↨oº⁷÷K⁻eDH:_Tbk¦�”²

Look them up in the string SuJiSrUuNtEEVVMrGnTTMcClIIMoEpToPPEiHeTa split into pairs of characters.

§⪪“_″FJ⁼⦄b\l≕)T‹#⊙xO-nη⁻À↓ζ↥ς§%H8H“ρj✳Hρl× S↶…|UD⎇LkfZ”³

Split the string m.w'fv&J|\"l|\"e1 c& _c Ca ;e ;* 9a 9C 31 2; 0I .7 ,N ,7 (X (< into groups of three characters and take the corresponding group.

I⍘ ... γ

Decode the result as a base-95 number using the printable ASCII character set as the digits. Example: Io's 11th character is I, so we look up II and find it's the 13th largest object and its size is 31 which maps to 19 * 95 + 17 = 1822.


Simone Chelo 12/07/2018.

Swift 4, 225 bytes, score = 241

Probably golfable a bunch more (maybe in the "Ga-Me-Ca" area?), but Swift is not often used (for a reason, maybe.)

func b(i:String){print(i=="Titan" ?2575:["Su":6963,"Ju":699,"Sa":582,"Ur":253,"Ne":246,"Ea":63,"Ve":60,"Ma":33,"Ga":26,"Me":24,"Ca":24,"Io":18,"Mo":17,"Eu":16,"Tr":14,"Pl":12,"Er":12,"Ha":8,"Ti":8][String(i.prefix(2))]!*100)}

and ungolfed

func size(ofAstralObject object: String) {
  let objectToRadius = // Map size/100 of all objects to the first two chars
   ["Su":6963,
    "Ju":699,
    "Sa":582,
    "Ur":253,
    "Ne":246,
    "Ea":63,
    "Ve":60,
    "Ma":33,
    "Ga":26,
    "Me":24,
    "Ca":24,
    "Io":18,
    "Mo":17,
    "Eu":16,
    "Tr":14,
    "Pl":12,
    "Er":12,
    "Ha":8,
    "Ti":8] // Ti is Titania, while Titan is treated differently

  print(object == "Titan" ? 
    2575 : // If "Titan", print the exact size
    objectToRadius[String(i.prefix(2))]!*100 // get the size from the map and multiply by 100
  )
}

Try It Online!

I tried different "key sizes" for the map, but of course 1 has many clashes and using three chars doesn't give me i=="Titan" ?2575:'s 17 chars, since there's "Io" to manage (and it'll take more than 3 chars, I think).


zruF 12/11/2018.

JavaScript (ES6), 152 bytes, score = 163

Well, it's a pretty standard solution, but I enjoyed the challenge anyway!

s=>s=='Titan'?2575:[6963,699,582,254,246,64,60,34,26,24,24,18,17,16,14,12,12,8,8]["SuJuSaUrNeEaVeMaGaMeCaIoMoEuTrPlErHaTi".match(s[0]+s[1]).index/2]*100

My Score:

Max. penalty ratio = 1.07068 for Triton
Score = ceil(152 x 1.07068) = 163

Try it Online!


Terjerber 12/12/2018.

FALSE, 152 bytes, Score = 563

[911*.]^$0\[~][1+^]#$$2=\$4=\8=||[2 0!]?$3=[764 0!]?$5=[\$$69=\86=|$[6\]?~[2]?0!]?$6=[\$$83=\85=|$[46\]?~[$72=$[1\]?~[2]?]?0!]?$7=[\$84=$[1\]?~[52]?0!]?

Lazy answer using word lengths and first letters but my excuse is that I'm using a weird language

Try it online! (copy paste the code, hit show and then run)

[911*.]          {defines a function that multiplies a number by 911 and then prints it}
^$0\[~][1+^]#    {counts the length of the name as it's input, also records the first char}
$$2=\$4=\8=||[1 0!]?  {if the name is 2, 4, or 8 chars long print 911*2 (0! calls the function)}
$3=[764 0!]?          {if name is 3 long print 911*764}
$5=[\$$69=\86=|$[6\]?~[2]?0!]? {5 long? print 911*6 if it starts with E or V, otherwise *2}
$6=[\$$83=\85=|$[46\]?~[       {6 long? print 911*46 if it starts with S or U, otherwise:}
    $72=$[1\]?~[2]?            {if name starts with H print 911*1 else *2
]?0!]?
$7=[\$84=$[1\]?~[26]?0!]?      {7 long? print 1822*1 if it starts with NT otherwise *26 (for jupiter}

My results:

Sun       : 696004.00 penalty ratio = (696342.00 / 696004.00 )² = 1.00097
Jupiter   : 47372.00  penalty ratio = (69911.00  / 47372.00  )² = 2.17795
Saturn    : 41906.00  penalty ratio = (58232.00  / 41906.00  )² = 1.93095
Uranus    : 41906.00  penalty ratio = (41906.00  / 25362.00  )² = 2.73014
Neptune   : 47372.00  penalty ratio = (47372.00  / 24622.00  )² = 3.70166
Earth     : 5466.00   penalty ratio = (6371.00   / 5466.00   )² = 1.35855
Venus     : 5466.00   penalty ratio = (6052.00   / 5466.00   )² = 1.22591
Mars      : 1822.00   penalty ratio = (3390.00   / 1822.00   )² = 3.46181
Ganymede  : 1822.00   penalty ratio = (2634.00   / 1822.00   )² = 2.08994
Titan     : 1822.00   penalty ratio = (2575.00   / 1822.00   )² = 1.99737
Mercury   : 1822.00   penalty ratio = (2440.00   / 1822.00   )² = 1.79342
Callisto  : 1822.00   penalty ratio = (2410.00   / 1822.00   )² = 1.74959
Io        : 1822.00   penalty ratio = (1822.00   / 1822.00   )² = 1.00000
Moon      : 1822.00   penalty ratio = (1822.00   / 1737.00   )² = 1.10026
Europa    : 1822.00   penalty ratio = (1822.00   / 1561.00   )² = 1.36236
Triton    : 1822.00   penalty ratio = (1822.00   / 1353.00   )² = 1.81343
Pluto     : 1822.00   penalty ratio = (1822.00   / 1186.00   )² = 2.36008
Eris      : 1822.00   penalty ratio = (1822.00   / 1163.00   )² = 2.45435
Haumea    : 911.00    penalty ratio = (911.00    / 816.00    )² = 1.24640
Titania   : 911.00    penalty ratio = (911.00    / 788.00    )² = 1.33655

Max. penalty ratio = 3.70166 for Neptune
Score = ceil(152 x 3.70166) = 563

CCB60 12/12/2018.

Python 2, 89 bytes, Score = 234

lambda(p):39**4/'zzuSJJaSrUNNrEnVsMeGtTMMoCoInMuErTuPsEaHTT'.find(p[7%len(p)]+p[0])**2.18

Try it online!

Most answers posted appear to have used a "encode/decode" strategy. I wondered how well I could do by estimating the diameter of celestial bodies using a simple equation. It's been a fun exercise, but the moderate byte savings are more than made up for by the accuracy penalty.

The core of this solution is the estimating equation:

Radius = 39**4/x**2.18

where x is twice the rank order of the radius of the body.

I generate the value of x based on the input string using a modification of @Erik the Outgolfer's Python 2 solution. I saved a few bytes on his code by recasting my equations to work with [2..40] instead of [1..20].

The code for generating rank orders takes up more than 2/3 of the bytes of the whole solution. If anyone has a more compact way of generating ranks, this solution could be shortened further. Because of the accuracy penalty (around 2.6), the score would improve quite a bit.

Generating the Equation

I used statistical methods to search for simple equations to estimate the size of each body based on its rank. In part following up on the insights in @Level River St's Ruby solution and generalizing, I settled on equations of the form:

Radius = A/(Rank)**B

Working in R, I used linear models on the log of the radii to develop initial estimates, and then used non-linear optimization, seeding the optimization with the results of the linear models, to search for solutions that minimized the penalty function specified in the problem.

The estimated value of A in the above equation is seven digits, so I searched for a simple expression to save a couple of bytes. I looked for expressions of the form

x**y

for two digit x and 1 digit y (for a total of five bytes, saving two bytes, or about five points, given the penalty) that was not too different from the optimum value of A and did not inflate the penalty much, and ended up with the (otherwise inexplicable):

39**4

HighResolutionMusic.com - Download Hi-Res Songs

1 Ariana Grande

7 Rings flac

Ariana Grande. 2019. Writer: Ariana Grande;Richard Rodgers;TBHits;Njomza;Michael "Mikey" Foster;Kaydence;Tayla Parx;Scootie;Oscar Hammerstein II;Victoria Monét.
2 Alan Walker

Lily flac

Alan Walker. 2018. Writer: Alan Walker;Lars Kristian Rosness;Magnus Bertelsen;K-391;Didrik Handlykken;Marcus Arnbekk.
3 Alec Benjamin

Let Me Down Slowly flac

Alec Benjamin. 2019. Writer: Alec Benjamin;Sir Nolan;Michael Pollack.
4 Alan Walker

Lost Control flac

Alan Walker. 2018. Writer: Alan Walker;Thomas Troelsen;Mood Melodies;Sorana;Fredrik Borch Olsen;Magnus "Magnify" Martinsen.
5 Skylar Grey

Everything I Need flac

Skylar Grey. 2018. Writer: Elliott Taylor;Rupert Gregson-Williams;Skylar Grey.
6 Post Malone

Sunflower flac

Post Malone. 2018. Writer: Carl Rosen;Louis Bell;Billy Walsh;Carter Lang;Swae Lee;Post Malone.
7 Westlife

Hello My Love flac

Westlife. 2019. Writer: Steve Mac;Ed Sheeran.
8 Alan Walker

Different World flac

Alan Walker. 2018. Writer: Shy Nodi;Alan Walker;Fredrik Borch Olsen;James Njie;Marcus Arnbekk;Gunnar Greve Pettersen;K-391;Corsak;Shy Martin;Magnus Bertelsen.
9 Sam Smith

Fire On Fire flac

Sam Smith. 2018. Writer: Steve Mac;Sam Smith.
10 Conor Maynard

Way Back Home (Sam Feldt Edit) flac

Conor Maynard. 2018. Writer: Ji Hye Lee;Shaun.
11 Normani

Dancing With A Stranger flac

Normani. 2019. Writer: Mikkel S. Eriksen;Tor Hermansen;Jimmy Napes;Normani;Sam Smith.
12 Slushii

Never Let You Go flac

Slushii. 2019. Writer: Sofía Reyes;Slushii;Aviella Winder.
13 Skrillex

Face My Fears flac

Skrillex. 2019. Writer: Poo Bear;Skrillex;Utada Hikaru.
14 Alora & Senii

Love U So flac

Alora & Senii. 2019. Writer: Alora & Senii.
15 The Chainsmokers

Hope flac

The Chainsmokers. 2018. Writer: Kate Morgan;Chris Lyon;Alex Pall;Andrew Taggart.
16 Imagine Dragons

Believer flac

Imagine Dragons. 2019. Writer: Dan Reynolds;Lil Wayne;Wayne Sermon;Ben McKee;Daniel Platzman;Robin Fredriksson;Mattias Larsson;Justin Tranter.
17 Alan Walker

I Don't Wanna Go flac

Alan Walker. 2018.
18 Mike Perry

Runaway flac

Mike Perry. 2019. Writer: Andreas Wiman;Dimitri Vangelis;Richard Müller;Sasha Rangas;Stefan Van Leijsen;Mike Perry.
19 Gesaffelstein

Lost In The Fire flac

Gesaffelstein. 2019. Writer: Ahmad Balshe;Nate Donmoyer;Gesaffelstein;DaHeala;The Weeknd.
20 Hozier

Almost (Sweet Music) flac

Hozier. 2019. Writer: Hozier.

Related questions

Hot questions

Language

Popular Tags