25
\$\begingroup\$

Task

Given a positive integer return the geologic era and period it was that many million years ago.

Input/output

The input is a string or integer; the output is a string. Eras and periods are separated by slashes (/). Input will always be between 0 and 542 inclusive

Data

The possible outputs for eras and periods and their corresponding time periods (in millions of years) are:

  • Cenozoic 0 - 66
    • Quaternary 0 - 3
    • Neogene 4 - 23
    • Paleogene 24 - 66
  • Mesozoic 67 - 252
    • Cretaceous 67 - 145
    • Jurassic 146 - 201
    • Triassic 202 - 252
  • Paleozoic 253 - 542
    • Permian 253 - 299
    • Carboniferous 300 - 359
    • Devonian 360 - 419
    • Silurian 420 - 444
    • Ordovician 445 - 485
    • Cambrian 486 - 542

Submissions will be scored by byte count. Lowest byte count wins.

Test cases

314 -> Paleozoic/Carboniferous
0 -> Cenozoic/Quaternary
542 -> Paleozoic/Cambrian
100 -> Mesozoic/Cretaceous
\$\endgroup\$
  • 1
    \$\begingroup\$ I suppose that by "The inpt [sic] is a string or integer" you mean that we can choose, not that we have to handle both. If so, then specifying "integer" is enough, e.g. taking number via stdin is indistinguishable from taking the string representation of that same number. \$\endgroup\$ – Adám Jul 8 at 18:17
  • 5
    \$\begingroup\$ (cont.) Finally, for your next challenge, I'd highly recommend using the Sandbox so that you can refine the specifics and get preliminary feedback before posting. Hope you enjoy CGCC! \$\endgroup\$ – caird coinheringaahing Jul 8 at 18:40
  • 6
    \$\begingroup\$ @cairdcoinheringaahing Removing rules listed in "things to avoid when writing challenges" is explicitly not allowed \$\endgroup\$ – pppery Jul 8 at 18:52
  • 7
    \$\begingroup\$ @Abigial I didn't change them back. Someone else did. \$\endgroup\$ – matt Jul 8 at 21:01
  • 3
    \$\begingroup\$ @Abigail, nor did Matt change them in the first place. \$\endgroup\$ – Shaggy Jul 8 at 22:42

17 Answers 17

14
\$\begingroup\$

Befunge-93, 537 bytes

&:"C"`#v_"neC">,,,"/ciozo",,,,,,:4`#v_"auQ",,,"yranret">,,,,,,,@
*54+65:<   >  ^"Mes"_v#!`*+3          >#>#             ^#
 "leogene"<^"ale","P"<     v_v#`*64:<>        "enegoeN"^
,,,"Cre"< ^ ,,"Pa"_v#!`"C":< >       ^^"taceous"
`*2"e":_^#`*+*5545:<v_v#
 ,"T"_v#!`*+*543+65:< >"J","cissaru"  ^"riassic"
*"d"3:<v_v#!`
"rmian"< >:"x"3*`!#v_:"F"6*`#v_"D",v  ^"Pe"
"ous",,,,,,"Carbon"<         :        ^"ifer"
"enovian"                          <  ^
"brian","C"_v#`*"Q"6_v#`*"Y"5<        ^"am"
"an",,,"Ord"<        >"S","nairuli"   ^"ovici"

Try it online!

This is basically a giant if/elsif/if chain (or rather, two of them), one for the era, and one for the period.

| improve this answer | |
\$\endgroup\$
10
\$\begingroup\$

Jelly,  74  73 bytes

“¥Þ+O83/<<ı)‘Ä>⁸Sµ:3»1;ị"“¥nq9r&t\“¥Ḅr¶4ḍẏżæœġẓÆ$Ụ>¬ḞḂṂĊƁÄ`zṚƥṀȯ4N»Ḳ€¤j”/

A monadic Link accepting number in \$[0,542]\$ which yields a list of characters (or a full program which prints the result).

Try it online!

How?

“...‘Ä>⁸Sµ:3»1;ị"“...“...»Ḳ€¤j”/ - Link: integer, N        e.g. 100
“...‘                            - list of code page indices    [4,20,43,79,56,51,47,60,60,25,41]
     Ä                           - cumulative sums              [4,24,67,146,202,253,300,360,420,445,486]
      >⁸                         - greater than N?              [0,0,0,1,1,1,1,1,1,1,1]
        S                        - sum                          8
         µ                       - start a new monadic chain, call that X
          :3                     - integer divide (X) by 3      2
            »1                   - maximum of that and 1        2
              ;                  - concatenate with X           [2,8]
                            ¤    - nilad followed by link(s) as a nilad:
                 “...“...»       -   list of compressed strings ["Paleozoic Mesozoic Cenozoic","Ordovician Silurian Devonian Carboniferous Permian Triassic Jurassic Cretaceous Paleogene Neogene Quaternary Cambrian"]
                          Ḳ€     -   split each at spaces       [["Paleozoic","Mesozoic","Cenozoic"],["Ordovician","Silurian","Devonian","Carboniferous","Permian","Triassic","Jurassic","Cretaceous","Paleogene","Neogene","Quaternary","Cambrian"]
                "                - zip with:
               ị                 -   index into (modular)       ["Mesozoic","Cretaceous"]
                             j”/ - join with a '/'              "Mesozoic/Cretaceous"
| improve this answer | |
\$\endgroup\$
7
\$\begingroup\$

Java (JDK), 260 bytes

n->(n<67?"Cen":n<253?"Mes":"Pale")+"ozoic/"+"QuaternaryNeogenePaleogeneCretaceousJurassicTriassicPermianCarboniferousDevonianSilurianOrdovicianCambrian".split("(?=[A-Z])")[(n=java.util.Arrays.binarySearch("B‘ÉüīŧƣƼǥȞ".toCharArray(),(char)n))<0?~n:n]

Try it online!

  • Contains invisible characters. The binary search String is actually: "\u0003\u0017\u0042\u0091\u00c9\u00fc\u012b\u0167\u01a3\u01bc\u01e5\u021e".
| improve this answer | |
\$\endgroup\$
6
\$\begingroup\$

J, 195 bytes

Assumes that input is 0-542, otherwise ~+7 bytes.

(Cen`Mes`Pale{~66 252&I.);@,'ozoic/';Quaternary`Neogene`Paleogene`Cretaceous`Jurassic`Triassic`Permian`Carboniferous`Devonian`Silurian`Ordovician`Cambrian{~(+/\3 20 43 79 56 51 47 60 60 25 41)I.]

Try it online!

| improve this answer | |
\$\endgroup\$
5
\$\begingroup\$

Python 3, 273 264 bytes

lambda y:(['Cen']*67+['Mes']*186+['Pale']*290)[y]+'ozoic/'+(['Quaternary']*4+['Neogene']*20+['Paleogene']*43+['Cretaceous']*79+['Jurassic']*56+['Triassic']*51+['Permian']*47+['Carboniferous']*60+['Devonian']*60+['Silurian']*25+['Ordovician']*41+['Cambrian']*57)[y]

Try it online!

| improve this answer | |
\$\endgroup\$
4
\$\begingroup\$

JavaScript (Node.js),  226  221 bytes

n=>(Buffer('!%5LpYTP]]:JZ').some(c=>(n-=c-34)<j++,j=1),a='CenMesPaleQuaternaryNeogenePaleogeneCretaceousJurassicTriassicPermianCarboniferousDevonianSilurianOrdovicianCambrian'.match(/.[a-z]+/g))[j>8?2:j/6|0]+'ozoic/'+a[j]

Try it online!

| improve this answer | |
\$\endgroup\$
4
\$\begingroup\$

Charcoal, 148 bytes

Nθ§⪪Cen Mes Pale¦ ⁺‹θ⁶⁷‹θ²⁵³ozoic§⪪”↶0s⟧↶'⪪Q⟧⪪⪫(cI‹qκyQυ⌕↖↙″⁼R¤´⁵σι↙¡Z⟧+]IΦc№M⁰$✂%¹νν⬤~[Z⊕←⊘↖τF¤H>¹Sk◨ⅈγδ;§⟦⬤▶%↨Φ;{θi∕Nβ” LΦI⪪”)¶5″⁶vρ⁶S⊘l²Kκ~y”³‹ιθ

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

Nθ

Input the year.

§⪪Cen Mes Pale¦ ⁺‹θ⁶⁷‹θ²⁵³

Print one of the three era prefixes depending on the year.

ozoic

Print the era suffix.

§⪪”...” LΦI⪪”...”³‹ιθ

Extract the years that the periods end from a compressed list of padded years and count how many periods have ended before the input year and index into a compressed list of names of periods to print the current period. (Padding the years to three digits saves 4 bytes overall due to not needing any separators.)

| improve this answer | |
\$\endgroup\$
4
\$\begingroup\$

05AB1E, 127 125 124 bytes

.•TćFh/>ytTOb•#櫕͇,®ǝ₁êË2•80в.¥I›©₆12ªèOè.•Hα^B·´‘›∞ÕΣHı[šyZÙΣpK5|´Ø·ëu"dw$мïjéåpºöÒ@’»©\I›¼ä^и9Σ߃ôƶI<Ægª6XyrмÏ•#®Oè'/ý™

Try it online or verify all test cases.

Explanation:

.•TćFh/>ytTOb• # Push compressed string "ozoic cen pale mes"
 #             # Split it on spaces: ["ozoic","cen","pale","mes"]
  ć            # Extract head; pop and push remainder-list and first item separated
   «           # Append this head to each item in the list:
               #  ["cenozoic","paleozoic","mesozoic"]
•Í‡,®ǝ₁êË2•    # Push compressed integer 3656627291841362083337
 80в           # Convert it to base-80 as list: [4,20,43,79,56,51,47,60,60,25,41,57]
    .¥         # Undelta this list: [0,4,24,67,146,202,253,300,360,420,445,486,543]
      I›       # Check for each whether it's larger than the input-integer
               # (1 if truthy; 0 if falsey)
        ©      # Store this list of checks in variable `®` (without popping)
₆              # Push builtin 36
 12ª           # Convert it to a list of digits, and append 12: [3,6,12]
    è          # Index those into the checks (to get those for [67,253,543])
     O         # Sum those checks to get the amount of truthy values
      è        # Index it into the string-list (modulair 0-based,
               # so 3 indexes into "cenozoic")
.•Hα^B·´‘›∞ÕΣHı[šyZÙΣpK5|´Ø·ëu"dw$мïjéåpºöÒ@’»©\I›¼ä^и9Σ߃ôƶI<Ægª6XyrмÏ•
              "# Push compressed string "quaternary cambrian ordevician silurian devonian carboniferous permian triassic jurassic cretaceous paleogene neogene"
 #             # Split it on spaces: ["quaternary","cambrian","ordevician","silurian","devonian","carboniferous","permian","triassic","jurassic","cretaceous","paleogene","neogene"]
  ®            # Push the list of checks from variable `®`
   Oè          # Do the same as we did earlier
'/ý           '# Join the two words on the stack with "/" delimiter
   ™           # And titlecase both words in this string
               # (after which the result is output implicitly)

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

| improve this answer | |
\$\endgroup\$
3
\$\begingroup\$

APL (Dyalog Unicode) 18.0, 213 bytes

(0 4 24 67 146 202 253 300 360 420 445 486 543⍸⎕)⊃⊃,/1(⌷,¨↓)¨(9⍴4↑1)⊂(∊∘⎕A⊂⊢)'Cenozoic/QuaternaryNeogenePaleogeneMesozoic/CretaceousJurassicTriassicPaleozoic/PermianCarboniferousDevonianSilurianOrdovicianCambrian'

Try it online! (uses c as a polyfill for since TIO has not upgraded to 18.0 yet)

| improve this answer | |
\$\endgroup\$
  • \$\begingroup\$ Hello again! :) \$\endgroup\$ – matt Jul 8 at 20:13
3
\$\begingroup\$

perl -pl, 270 251 bytes

@a=((Cenozoic)x67,(Mesozoic)x186,(Paleozoic)x290);@b=((Quaternary)x4,(Neogene)x20,(Paleogene)x43,(Cretaceous)x79,(Jurassic)x56,(Triassic)x51,(Permian)x47,(Carboniferous)x60,(Devonian)x60,(Silurian)x25,(Ordovician)x41,(Cambrian)x57);$_=$a[$_].$".$b[$_]

Try it online!

This creates two arrays with 543 elements each. Finding the era and period is then just a matter of indexing in the arrays.

Edit: The challenge was changed; we can now assume the input is between 0 and 542 inclusive. So we don't need to test the input anymore. And we don't require a slash between era and period either.

| improve this answer | |
\$\endgroup\$
  • 1
    \$\begingroup\$ You don't need the temporary arrays @a & @b, just index directly into the lists. Also, removing the string "ozoic" from each of the entries in the first list saves some bytes: 230 bytes \$\endgroup\$ – Xcali Jul 8 at 20:20
  • 2
    \$\begingroup\$ Actually removing the list that @a represents altogether saves a few more bytes: 222 \$\endgroup\$ – Xcali Jul 8 at 20:28
  • \$\begingroup\$ Down to 202 using @Xcali's solution and compressing the list a bit: Try it online! \$\endgroup\$ – Dom Hastings Jul 15 at 11:50
3
\$\begingroup\$

JavaScript (Node.js), 339 bytes

f=(a)=>{g=(b,q,w)=>{for(i=0;;i++){if(a<q[i])return w[i]}}
x=[67,253,543]
y=['Cenozoic/','Mesozoic/','Paleozoic/']
n=[4,24,67,146,202,253,300,360,420,445,486,543]
m=['Quaternary','Neogene','Paleogene','Cretaceous','Jurassic','Triassic','Permian','Carboniferous','Devonian','Silurian','Ordovician','Cambrian']
console.log(g(a,x,y)+g(a,n,m))}

Try it online!

simplest solution to start golfing

| improve this answer | |
\$\endgroup\$
3
\$\begingroup\$

Whitespace, 1841 1830 1819 bytes

        
   
 
    
                     
                    
        
             
                            
        
                
    
        
            
             
                      
        
               
                   
        
                
   
                     
                
                
   
             
                      
        
                 
 
                                
        
                    
                         
        
                  
   
                 
             
                    
                
                

    

     
    
 
                  
        
                
   
                
                     
                
                    
                        
   
                       
        
              
   
                
                  
                
            

    

        
   
                    
                 
                
                     
                 
                
                  
                
                    
            

    

      
   
                
                 

    

        
    
   
            
                         
        
                 
   
                
                
                    
                    
                
   
                             
        
                    
   
                
                 
              

    

         
   
                    
                    
                        
                
                
                
                  
                
                 
                

    

            
   
                 
                    
             

    

       
 

 

   
                     
                
                
                    
                 
                
            

    

        
 

   
                    
                    
                        
                 
                
                 
                
                     
                        
             
                 
                
                

    

         
 

   
                     
                        
                     
                
          

    

            
 

   
                 
                    
                  
                
                

    

          
   
                
                
                     
                        
              
                 
                    

  
   
                    
                
                
                        
                     
                        
    
                
         
 
                

                     

 
                

            
   
                     
                
                

 
    

             
   
                    
                
                

 
    

                
   
                
                  
                
            

    
 
 
                
    
  
 
    

        

Try it online!
For some reason it doesn't work quite right on TIO, try it using the IDE I wrote it in, Whitelips

Explanation

Since the only conditionals in whitespace are jump-if-negative and jump-if-zero, I figure out if the inputed number minus the number for the era plus one is negative, then jump to the respective label and push the era onto the stack. I then jump into a loop that prints the entire stack. (loops until it reaches a -1, which I push at the very start of the program.) I save repetive bytes by pushing "ogene" and then "Ne" or "Pale", "ozoic/" and then "Mes" or "Cen", etc.

| improve this answer | |
\$\endgroup\$
  • 1
    \$\begingroup\$ Typo? and then Ner ... but Nerogene isn’t a period. \$\endgroup\$ – matt Jul 20 at 21:20
  • \$\begingroup\$ @matt good catch! misread my handwriting, changing to ne. . . \$\endgroup\$ – nope Jul 20 at 21:38
2
\$\begingroup\$

FEU, 268 bytes

u/x
m/x{486}x*/"Cambr#/x{445}x*/"Ordov%#/x{420}x*/"Silur#/x{360}x*/"Devon#/x{300}x*/"Carbonifer&/x{253}x*/"Perm#/x{202}x*/'Tri,/x{146}x*/'Jur,/x{67}x*/'Cretace&/x{24}x*/- 0/x{4}x*/-N0/x*/-Quaternary/0/eogene/-/Cen!/,/ass%/'/Mes!/&/ous/#/ian/"/ e!/!/ozo%\//%/ic/ /Pal/g

Try it online!

Basically just compression.

| improve this answer | |
\$\endgroup\$
2
\$\begingroup\$

Io, 417 bytes

Port of Noodle9's Python answer.

method(y,("Pale "repeated(67).."Mes "repeated(186).."Pale "repeated(290))split at(y).."ozoic/"..("Quaternary "repeated(4).."Neogene "repeated(20).."Paleogene "repeated(43).."Cretaceous "repeated(79).."Jurassic "repeated(56).."Triassic "repeated(51).."Permian "repeated(47).."Carboniferous "repeated(60).."Devonian "repeated(60).."Silurian "repeated(25).."Ordovician "repeated(41).."Cambrian "repeated(57))split at(y))

Try it online!

| improve this answer | |
\$\endgroup\$
2
\$\begingroup\$

PHP with -r, 261 bytes

Lots of ternary operators is the shortest solution I've found. Then golfed for some redundant suffixes. Only twice the amount of bytes needed to spell out each era uncompressed.

$a=$argv[1];echo($a<67?Cen:($a<253?Mes:Pale)).'ozoic/'.($a<4?Quarternary:($a<24?Neogene:($a<67?Paleogene:($a<146?Cretaceous:($a<202?Jurassic:($a<253?Triassic:($a<300?Permian:($a<360?Carboniferous:($a<420?Devon:($a<445?Silur:($a<486?Ordovic:Cambr))).ian))))))));

Try it online!

| improve this answer | |
\$\endgroup\$
2
\$\begingroup\$

Ruby, 317 bytes

->a{a<31?"Cenozoic/"+(a<4?"Quaternary":(a<24?"Neogene":(a<67?"Paleogene":""))):a<253?"Mesozoic/"+(a<146?"Cretaceous":(a<202?"Jurassic":(a<253?"Triassic":""))):a<543?"Paleozoic/"+(a<300===a ?"Permian":(a<360 ?"Carboniferous":(a<420?"Devonian":(a<445===a ?"Silurian":(a<486 ?"Ordovician": (a<543?"Cambrian":"")))))):""}

Try it online!

| improve this answer | |
\$\endgroup\$
2
\$\begingroup\$

05AB1E, 235 bytes

67‹i’¦ì€¸zo¾ã/’™?¹4‹i’QuâìÒÇry’?ë¹₂Í‹i’ÖÌž¹’™?ë’æ§ož¹’™?}}ë¹253‹i’€á€Êzo¾ã/’™?¹145‹i’±ƒˆÆÁàÔºs’™?ë¹т·Ì‹i’JҢ턾ã’?ë’Æ×턾㒙?}}ë’槢äo¾ã/’™?¹3т*‹i’„œéên’™?ë¹₆T*‹i’®´€¬²¡Ôºs’™?ë¹420‹i’Ùç·‹’™?ë¹445‹i’¯ë„¹´€¤’™?ë¹486‹i’€—€·É²·‹’™?뒧袰’™?

Try it online!

   i                                                         # if
                                                             # implicit input
67‹                                                          # is less than 67
                ?                                            # then output without trailing newline
    ’¦ì€¸zo¾ã/’™                                             # "Cenozoic/"
                    i                                        # if
                 ¹                                           # first item from input history
                  4‹                                         # is less than 4
                               ?                             # then output without trailing newline
                     ’QuâìÒÇry’                              # "Quaternary"
                                ë    i                       # elif
                                 ¹                           # first item from input history
                                    ‹                        # is less than
                                  ₂                          # 26
                                   Í                         # - 2 = 24
                                             ?               # then output without trailing newline
                                      ’ÖÌž¹’™                # "Neogene"
                                              ë              # else
                                                       ?     # output without trailing newline
                                               ’æ§ož¹’™      # "Paleogene"
                                                        }}   # end if statement (2x)
ë     i                                                      # elif
 ¹                                                           # first item from input history
  253‹                                                       # is less than 253
                   ?                                         # then output without trailing newline
       ’€á€Êzo¾ã/’™                                          # "Mesozoic/"
                         i                                   # if
                    ¹                                        # first item from input history
                     145‹                                    # is less than 145
                                      ?                      # then output without trailing newline
                          ’±ƒˆÆÁàÔºs’™                       # "Cretaceous"
                                       ë     i               # elif
                                        ¹                    # first item from input history
                                            ‹                # is less than
                                         т                   # 100
                                          ·                  # * 2 = 200
                                           Ì                 # + 2 = 202
                                                       ?     # then output without trailing newline
                                              ’JҢ턾㒠     # "Jurassic"
ë                                                            # else
          ?                                                  # output without trailing newline
 ’Æ×턾㒙                                                   # "Triassic"
           }}                                                # end if statement (2x)
             ë                                               # else
                         ?                                   # output without trailing newline
              ’槢äo¾ã/’™                                    # "Paleozoic"
                               i                             # if
                          ¹                                  # first item from input history
                              ‹                              # is less than
                           3т*                               # 3 * 100 = 300
                                        ?                    # then output without trailing newline
                                ’„œéên’™                     # "Permian"
                                         ë     i             # elif
                                          ¹                  # first item from input history
                                              ‹              # is less than
                                           ₆                 # 36
                                            T*               # * 10 = 360
                                                            ?# then output without trailing newline
                                                ’®´€¬²¡Ôºs’™ # "Carboniferous"
ë     i                                                      # elif
 ¹                                                           # first item from input history
  420‹                                                       # is less than 420
              ?                                              # then output without trailing newline
       ’Ùç·‹’™                                               # "Devonian"
               ë     i                                       # elif
                ¹                                            # first item from input history
                 445‹                                        # is less than 445
                                ?                            # then output without trailing newline
                      ’¯ë„¹´€¤’™                             # "Silurian"
                                 ë     i                     # elif
                                  ¹                          # first item from input history
                                   486‹                      # is less than 486
                                                   ?         # then output without trailing newline
                                        ’€—€·É²·‹’™          # "Ordovician"
                                                    ë        # else
                                                            ?# output without trailing newline
                                                     ’§è¢°’™ # "Cambrian"
                                                             # implicit end if statement (5x)
| improve this answer | |
\$\endgroup\$

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.