44
1
I think we've all done this as a kid: some websites require a minimum age of 18, so we just subtract a few years from the year of birth and voilà, we 'are' 18+.
In addition, for most rides at amusement parks the minimum height to enter is 1.40 meters (here in The Netherlands it as at least). Of course this can be cheated less easily than age, but you could wear shoes with thick heels, put your hair up, wear a hat, stand on your toes, etc.
Input:
Your program/function accepts a positive integer or decimal.
Output:
- Is the input an integer
>= 18
? Simply print the input. - Is the input an integer
0-17
? Print18
. - Is the input a decimal
>= 1.4
? Simply print the input. - Is the input a decimal
0.0-1.4
? Print1.4
.
Challenge rules:
- Assume the input will always be in the range of
0-122
(oldest woman ever was 122) or0.0-2.72
(tallest man ever was 2.72). - You are allowed to take the input as a String, object, or anything else you prefer.
- The decimal inputs will never have more than three decimal places after the decimal point.
2
or2.
both aren't valid outputs for2.0
. You are free to output2.00
or2.000
instead of2.0
however.
Just like the input the output will never have more than three decimal places after the point.
General rules:
- This is code-golf, so shortest answer in bytes wins.
Don't let code-golf languages discourage you from posting answers with non-codegolfing languages. Try to come up with an as short as possible answer for 'any' programming language. - Standard rules apply for your answer, so you are allowed to use STDIN/STDOUT, functions/method with the proper parameters, full programs. Your call.
- Default Loopholes are forbidden.
- If possible, please add a link with a test for your code.
- Also, please add an explanation if necessary.
Test cases:
0 -> 18
1 -> 18
2 -> 18
12 -> 18
18 -> 18
43 -> 43
115 -> 115
122 -> 122
0.0 -> 1.4
1.04 -> 1.4
1.225 -> 1.4
1.399 -> 1.4
1.4 -> 1.4
1.74 -> 1.74
2.0 -> 2.0
2.72 -> 2.72
Can we assume that the input is free of leading zeros? – Toby Speight – 2016-09-29T12:45:12.617
@TobySpeight Yes, no leading zeros. – Kevin Cruijssen – 2016-09-29T12:48:20.770
2
0.0-2.72 (tallest man ever was 2.72).
- You aren't0.0
when you're born... – Johan Karlsson – 2016-09-29T13:49:53.7131@JohanKarlsson I know, thought about adding a minimum, but I decided to just let it start at
0
and0.0
. :) The addedtallest man ever was 2.72
andoldest woman ever was 122
was just added as informational facts for those interested. – Kevin Cruijssen – 2016-09-29T13:54:31.967According to meta, you can overload a function for different types of input. link
– corvus_192 – 2016-09-30T05:47:19.3539"[...] so we just add a few years to the year of birth [...]" Shouldn't you subtract a few years from the year of birth? – wythagoras – 2016-10-02T17:35:30.257
@wythagoras Sharp. I'll edit it. – Kevin Cruijssen – 2016-10-03T13:42:27.987