Puzzle: Century From Year [reference]

Century From Year” is a coding puzzle that people can be attempted in the following languages: cpp, python, javascript, haskell, go, csharp, c, ruby, crystal, php, typescript, powershell, scala, groovy, coffeescript, java, julia, lua, r, kotlin, nim, nasm, clojure, rust, dart, elixir, fsharp, racket, reason, shell, factor, sql, purescript, forth, elm, swift, ocaml, vb, erlang, fortran, objc, solidity, prolog, and cfml.

  • Difficulty: 8 kyu
  • Stars: 442
  • Votes: 4135
  • Category: reference
  • Tags: Fundamentals, Numbers, Data Types, Mathematics, Algorithms, Logic, Basic Language Features, Dates/Time
  • Source: codewars



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.

Task :

Given a year, return the century it is in.

Input , Output Examples ::

centuryFromYear(1705)  returns (18)
centuryFromYear(1900)  returns (19)
centuryFromYear(1601)  returns (17)
centuryFromYear(2000)  returns (20)

(century 1705)  returns 18
(century 1900)  returns 19
(century 1601)  returns 17
(century 2000)  returns 20

In SQL, you will be given a table `years` with a column `yr` for the year. Return a table with a column `century`.

Hope you enjoy it … Awaiting for Best Practice Codes

Enjoy Learning !!!

Solve It Here

Click the link below to solve it on Codewars:


This puzzle was posted by a Slackbot via a slash command. If you want to help work on the app, send a message to @Josh.

If you don’t want to see the coding puzzles when you visit the forum, you can go into your settings and mute the puzzles category.

1 Like

Try solving it without any conditional logic.