Get the century of a year

Your program has to have an year like 1957 to be the input and then output the century of that year.

For example:

In: 1946
Out: 20
In: 1705
Out: 18
In: 1900
Out: 19
In: 100
Out: 1
In: 2001
Out 21


because 1946 is in the 20th century.

Keep in mind that 2000 should be 20th century or 1900 should be in 19th century.

Therefore, the first century spans from the year 1 up to and including the year 100, the second - from the year 101 up to and including the year 200, etc.

Any programming language is allowed and keep your code short and sweet. :)

Additional Challenge: Try to also include float values

• "Try to also include float values" Huh? What do you mean? – wastl Jul 23 '18 at 15:25
• @LuisfelipeDejesusMunoz Probably because it is trivial. – wastl Jul 23 '18 at 19:26
• Since when we are downvoting trivial challenges? – Dead Possum Jul 24 '18 at 12:43
• @DeadPossum I downvoted because this challenge is neither interesting nor golf-able. There is no algorithmic complexity in finding the century: nearly all answers simply implement the expression floor((year - 1)/100) + 1, and there aren't other clever optimizations that can be done to shorten the overall program; there aren't any "alternative approaches" to the challenge. Since most answers implement the exact same expression, this challenge looks no more interesting than a list of "floor," "decrement," "divide," and "increment" functions in various languages. – JungHwan Min Jul 24 '18 at 14:51
• How far in the future must our answers be correct until? Is it acceptable to only produce correct input up to the present year? (It matters in the R answer, we can save 2 bytes by only being correct up to the year 9998, possibly 9999) – JDL Jul 25 '18 at 15:34

Ruby, 14 bytes

->n{~-n/100+1}


Try it online!

I think it's squeezed as much as possible. I would love to see if anyone has any clever tricks to make this smaller.

Ruby, 16 bytes

->i{(i-1)/100+1}


Swift 4, 18 bytes

print((n-1)/100+1)


Try it online!

n is the input of the program

Excel, 152118 13 bytes

=INT(99%+A1%)


Input is in cell A1

• Does =LEFT(A1+99,2) work? I don't know Excel. – Post Rock Garf Hunter Jul 23 '18 at 15:31
• @WW It would except it has the same failure I just noted in my original: Fails on years <= 1000. I used that method on the new formula, though, to save a byte. – Engineer Toast Jul 23 '18 at 15:56
• Doesn't =CEILING(A1/100,1) work for 18 bytes? – Neil Jul 23 '18 at 16:09
• @Neil Maybe, yes. Maybe I clearly didn't spend enough time on this because I saw it as a relatively easily challenge and overlooked some pitfalls and optimizations. – Engineer Toast Jul 23 '18 at 17:19
• @EngineerToast Change A1/100 to A1% for 15 bytes, or adapt the LEFT version to =INT(99%+A1%) for 13 bytes. – Chronocidal Jul 25 '18 at 14:14

x86_64 machine language on Linux, 12 bytes

0:   97                      xchg   %eax,%edi
1:   ff c8                   dec    %eax
3:   6a 64                   pushq  \$0x64
5:   59                      pop    %rcx
6:   99                      cltd
7:   f7 f9                   idiv   %ecx
9:   ff c0                   inc    %eax
b:   c3                      retq


Try it online!