# A long long time ago, in a galaxy … right here

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

• 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. – Adám Jul 8 '20 at 18:17
• (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! – caird coinheringaahing Jul 8 '20 at 18:40
• – pppery Jul 8 '20 at 18:52
• @Abigial I didn't change them back. Someone else did. – matt Jul 8 '20 at 21:01
• @Abigail, nor did Matt change them in the first place. – Shaggy Jul 8 '20 at 22:42

# 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.

# 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"  # 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". # J, 195 bytes Assumes that input is 0-542, otherwise ~+7 bytes. (CenMesPale{~66 252&I.);@,'ozoic/';QuaternaryNeogenePaleogeneCretaceousJurassicTriassicPermianCarboniferousDevonianSilurianOrdovicianCambrian{~(+/\3 20 43 79 56 51 47 60 60 25 41)I.]  Try it online! # 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! # 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! # Charcoal, 148 bytes Ｎθ§⪪Cen Mes Pale¦ ⁺‹θ⁶⁷‹θ²⁵³ozoic§⪪”↶0s⟧↶'⪪Q⟧⪪⪫(cＩ‹qκyＱυ⌕↖↙″⁼R¤´⁵σι↙¡Ｚ⟧+]IΦc№M⁰$✂%¹νν⬤～[Ｚ⊕←⊘↖τF¤Ｈ>¹Sk◨ⅈγδ；§⟦⬤▶%↨Φ；{θi∕Ｎβ” ＬΦＩ⪪”)¶5″⁶vρ⁶Ｓ⊘l²Ｋκ～y”³‹ιθ


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

Ｎθ


Input the year.

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


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

ozoic


Print the era suffix.

§⪪”...” ＬΦＩ⪪”...”³‹ιθ


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.)

# 05AB1E, 127125 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è'/ý™  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.

# 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)

• Hello again! :) – matt Jul 8 '20 at 20:13

# 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.

• 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 – Xcali Jul 8 '20 at 20:20
• Actually removing the list that @a represents altogether saves a few more bytes: 222 – Xcali Jul 8 '20 at 20:28
• Down to 202 using @Xcali's solution and compressing the list a bit: Try it online! – Dom Hastings Jul 15 '20 at 11:50

# 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

# Whitespace, 18411830 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.

• Typo? and then Ner ... but Nerogene isn’t a period. – matt Jul 20 '20 at 21:20
• @matt good catch! misread my handwriting, changing to ne. . . – nope Jul 20 '20 at 21:38

# 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.

# Io, 417 bytes

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!

# PHPwith -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!

# 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!

# 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)
`