25
In English, nouns can take on two different forms depending on whether they are singular (one) or plural (anything else). For example, we would say "1 dog" but "2 dogs", "0 dogs", "57 dogs" and so forth.
In Russian, there are three categories. Instead of "1 dog, 2 dogs, 5 dogs", in Russian it would be "1 собака, 2 собаки, 5 собак".
The categories are divided according to the following logic:
- "Singular": used for 1 and any number ending in 1, except for numbers ending in 11.
- Examples: 1 собака, 21 собака, 101 собака
- "Few": used for 2, 3, and 4, and any number ending in 2, 3, or 4 except for numbers ending in 12, 13, and 14.
- Examples: 2 собаки, 3 собаки, 4 собаки, 32 собаки, 43 собаки, 104 собаки
- "Many": anything that is not considered "Singular" or "Few".
- Examples: 0 собак, 5 собак, 11 собак, 13 собак, 25 собак, 111 собак, 114 собак
The challenge
Given an integer input in the range [0, 1000], return 1
if it belongs to the "singular" category, 2
if it belongs to the "few" category, and 5
if it belongs to the "many" category.
Your program may be a function or it can use STDIN. You may print to STDOUT or return a value from the function
This is a code golf challenge, so the solution with the fewest number of bytes wins.
Can we take input as a string? – Shaggy – 2017-05-31T15:50:36.230
1@Shaggy Yes, that's fine – Peter Olson – 2017-05-31T15:52:28.020
Pretty sure singular form is only used for 1. – Pavel – 2017-05-31T15:55:45.307
2
@Phoenix Not in Russian.
– Peter Olson – 2017-05-31T15:58:56.140But... I speak Russian, and have since I was three... It sounds so wrong. – Pavel – 2017-05-31T16:05:10.443
1@Phoenix Really? Sound normal to me. How would you say 21 dogs? Not двадцать одна собака? – Peter Olson – 2017-05-31T16:11:50.753
2Why
1
,2
, and5
in particular? Also, why can't I use exit codes? – CalculatorFeline – 2017-05-31T16:13:24.583@CalculatorFeline
1
,2
, and5
are just "prototypical" examples of each category. I thought about allowing any arbitrary set of three values but it seemed like it would be hard to specify without opening loopholes. W.r.t. exit codes - that sounds fine to me, I just hadn't considered that possibility. – Peter Olson – 2017-05-31T16:17:13.640двадцать один собак, is the only way that sounds right to me. Although your way is technically correct, apparantly >_> – Pavel – 2017-05-31T16:19:41.047
Well, if any output set is allowed then I can save 3 bytes. – CalculatorFeline – 2017-05-31T16:27:25.893
1"Двадцать одна собака" is perfectly fine, and it's the only way you can translate "21 dogs" to Russian (unless you're a lawyer) – anatolyg – 2017-05-31T17:58:13.037
6@Phoenix That sounds so completely wrong to me - broken Russian - I've always used the form in the question and I find it correct, and apparently it is – dkudriavtsev – 2017-05-31T20:10:49.373
@Phoenix From Wikipedia: "Most numbers ending with "1" (in any gender: оди́н, одна́, одно́) require Nominative singular for a noun: два́дцать одна́ маши́на (21 cars)"
– Dmiters – 2017-05-31T20:53:54.4202@CalculatorFeline If you start counting from 1, you get singular at 1, few first occurs at 2, many first show up at 5. Makes perfect sense :-) – LLlAMnYP – 2017-06-01T06:48:02.780
5Counting in Russian is extremely hard. It's perhaps worth noting that the final digit determines the case. 1=Nominative singular 2,3,4=Genitive singular, 5-0 Genitive plural. This changes with the case of the phrase, and as there are 6 cases, there are 24 forms of 'one' (which is masculine), 24 forms of 'two' (which is feminine) and so on. It is said of the professor of Russian in my local university would be unlikely to be able to translate "with 2345 dogs", because 'with' demands the instrumental case (a hard one). – smirkingman – 2017-06-01T12:18:55.773
@smirkingman, yep many native speakers do not get it right. – Andrew Savinykh – 2017-06-02T08:24:05.377