https://www.codingame.com/training/easy/count-as-i-count

Send your feedback or ask for help here!

Created by @Magicien-d-oz,validated by @bbb000bbbyyy.

If you have any issues, feel free to ping them.

https://www.codingame.com/training/easy/count-as-i-count

Send your feedback or ask for help here!

Created by @Magicien-d-oz,validated by @bbb000bbbyyy.

If you have any issues, feel free to ping them.

They donâ€™t have forum accounts.

TBF, they barely have CG accounts at all: they only solve community puzzles in the exact same language as the puzzle author.

CGâ€™s been notified last time already, but have apparently chosen not to act on it.

3 Likes

Thank you for the gentle reminder.

Indeed, those two accounts are fake accounts. Iâ€™ve tried to investigate and understand from which regular account they could come, without result for now.

Iâ€™ve removed their moderation rights. The approvals theyâ€™ve done canâ€™t be easily undone though.

4 Likes

It seems I misunderstand the calculation logic behind this puzzle as I fail all test below 47.

For me the (bad) solutions are

45 : 38

46 : 17

47 : 7

48 : 3

49 : 1

50 : 1

What is the right solution for 45 and 46? Maybe that would help to see where do I go wrongâ€¦

Thanks.

45 -> 40, the rest is correct.

Thanks, this helped a lot. It turned out that my implementation of the â€śmax-4-roundsâ€ť rule was faulty.

Hello,

Iâ€™ve been stuck on the puzzle Count as I count for two days. I get the good result for tests #1 (47) and #3 (49) but I get wrong results (way too high) as soon as the score to reach is a little high. Can anyone please help me ? Iâ€™ve tried to mix loops and recursion and I think Iâ€™m on the right path, but Iâ€™m not going anywhere with my code. Thank you.

Hi everyone,

my code solve problem till to 39, but when i try to solve 38 I found an incorrect result.

These my permutations:

(follow this rule:

X|Y|Z are the pins fallen (permutations) â€“

[X,Y+40] is the Y pins fallen altogether (permutations of X,Y+40),

[X+40,Y] is the X pins fallen (permutations of X+40,Y) and so on.

==> (sum of permutations)

1|11 (2) â€“ [1,51] (2) ==> (4)

1|1|10 (3) â€“ [1,1,50] (3) ==> (6)

1|2|9 (6) â€“ [1,42,9] (6),[1,42,49] (6),[1,2,49] (6) ==> (24)

1|3|8 (6) â€“ [1,43,8] (6),[1,43,48] (6),[1,3,48] (6) ==> (24)

1|4|7 (6) â€“ [1,44,7] (6),[1,44,47] (6),[1,4,47] (6) ==> (24)

1|5|6 (6) â€“ [1,45,6] (6),[1,45,46] (6),[1,5,46] (6) ==> (24)

1|1|1|9 (4) â€“ [1,1,1,49] (4) ==> (8)

1|1|2|8 (12) â€“ [1,1,42,8] (12),[1,1,42,48] (12),[1,1,2,48] (12) ==> (48)

1|1|3|7 (12) â€“ [1,1,43,7] (12),[1,1,43,47] (12),[1,1,3,47] (12) ==> (48)

1|1|4|6 (12) â€“ [1,1,44,6] (12),[1,1,44,46] (12),[1,1,4,46] (12) ==> (48)

1|1|5|5 (6) â€“ [1,1,45,5] (12),[1,1,45,45] (6) ==> (24)

1|2|2|7 (12) â€“ [1,42,2,7] (24),[1,42,42,7] (12),[1,42,42,47] (12),[1,2,42,47] (24),[1,2,2,47] (12) ==> (96)

1|2|3|6 (24) â€“ [1,42,3,6] (24),[1,42,43,6] (24),[1,42,43,46] (24),[1,2,43,6] (24),[1,2,43,46] (24),[1,2,3,46] (24) ==> (168)

1|2|4|5 (24) â€“ [1,42,4,5] (24),[1,42,44,5] (24),[1,42,44,45] (24),[1,2,44,5] (24),[1,2,44,45] (24),[1,2,4,45] (24) ==> (168)

1|3|3|5 (12) â€“ [1,43,3,5] (24),[1,43,43,5] (12),[1,43,43,45] (12),[1,3,43,45] (24),[1,3,3,45] (12) ==> (96)

1|3|4|4 (12) â€“ [1,43,4,4] (12),[1,43,44,4] (24),[1,43,44,44] (12),[1,3,44,4] (24),[1,3,44,44] (12) ==> (96)

2|10 (2) â€“ [42,10] (2),[42,50] (2),[2,50] (2) ==> (8)

2|2|8 (3) â€“ [42,2,8] (6),[42,42,8] (3),[42,42,48] (3),[2,42,48] (6),[2,2,48] (3) ==> (24)

2|3|7 (6) â€“ [42,3,7] (6),[42,43,7] (6),[42,43,47] (6),[2,43,7] (6),[2,43,47] (6),[2,3,47] (6) ==> (42)

2|4|6 (6) â€“ [42,4,6] (6),[42,44,6] (6),[42,44,46] (6),[2,44,6] (6),[2,44,46] (6),[2,4,46] (6) ==> (42)

2|5|5 (3) â€“ [42,5,5] (3),[42,45,5] (6),[42,45,45] (3),[2,45,5] (6),[2,45,45] (3) ==> (24)

2|2|2|6 (4) â€“ [42,2,2,6] (12),[42,42,2,6] (12),[42,42,42,6] (4),[42,42,42,46] (4),[2,42,42,46] (12),[2,2,42,46] (12),[2,2,2,46] (4) ==> (64)

2|2|3|5 (12) â€“ [42,2,3,5] (24),[42,42,3,5] (12),[42,42,43,5] (12),[42,42,43,45] (12),[2,42,43,5] (24),[2,42,43,45] (24),[2,2,43,5] (12),[2,2,43,45] (12),[2,2,3,45] (12) ==> (156)

2|2|4|4 (6) â€“ [42,2,4,4] (12),[42,42,4,4] (6),[42,42,44,4] (12),[42,42,44,44] (6),[2,42,44,4] (24),[2,42,44,44] (12),[2,2,44,4] (12),[2,2,44,44] (6) ==> (96)

2|3|3|4 (12) â€“ [42,3,3,4] (12),[42,43,3,4] (24),[42,43,43,4] (12),[42,43,43,44] (12),[2,43,3,4] (24),[2,43,43,4] (12),[2,43,43,44] (12),[2,3,43,44] (24),[2,3,3,44] (12) ==> (156)

3|9 (2) â€“ [43,9] (2),[43,49] (2),[3,49] (2) ==> (8)

3|3|6 (3) â€“ [43,3,6] (6),[43,43,6] (3),[43,43,46] (3),[3,43,46] (6),[3,3,46] (3) ==> (24)

3|4|5 (6) â€“ [43,4,5] (6),[43,44,5] (6),[43,44,45] (6),[3,44,5] (6),[3,44,45] (6),[3,4,45] (6) ==> (42)

3|3|3|3 (1) â€“ [43,3,3,3] (4),[43,43,3,3] (6),[43,43,43,3] (4),[43,43,43,43] (1) ==> (16)

4|8 (2) â€“ [44,8] (2),[44,48] (2),[4,48] (2) ==> (8)

4|4|4 (1) â€“ [44,4,4] (3),[44,44,4] (3),[44,44,44] (1) ==> (8)

5|7 (2) â€“ [45,7] (2),[45,47] (2),[5,47] (2) ==> (8)

6|6 (1) â€“ [46,6] (2),[46,46] (1) ==> (4)

12 (1) â€“ [52] (1) ==> (2)

The total sum is 1638 instead of 1776.

i cannot understand what miss in my solution.

I donâ€™t understand the logic of the exercice. Why in the exemple, it is possible to have â€śP1 P1 P1â€ť and not â€ś1 1 1â€ť?

3 Likes

Because if you have 1 it meen you dropped one pin but if you dropped one pin you need to take the number on it. So you canâ€™t have 1.

I havenâ€™t the slightest idea how to do this one

1 Like

Is there a maximum number of pins? For example if the initial score is 0 can I knock down 50 pins?

1 Like

There is an impossible test case for this one, I didnâ€™t see it.

Unclear description. What does it mean number without P? â€śwhen the number is not accompanied it means the number of keels droppedâ€ť - and what is the sum of their numbers?

The sum of their numbers doesnâ€™t matter, if you hit 3 of them you get 3 points.

The value of a keel only matters when it is the only one being hit.

1 Like

I donâ€™t know how I didnâ€™t see

â€ś-If a player knocks down more than one pin, he marks the number of pins knocked downâ€ť

Ok, thank you

Just curious if anyone can do it with equation other than while for or recursive

I doubt it is possible to find a closed-form solution for the very general case.

However, we can find some formulas. 4 months ago, I published my solution (in python3) where, too bored to write a boring recursive solution, I tried to find such a formula. I almost succeeded. (but this is ugly and uncommented).

First, I ignore the different counting with one or more pins to get a more elegant exercise. So there is exactly one possibility to score each value between 0 and N (I start from 0 because it simplify a lot the calculus)

The function Combin(N, k, n) gives the number of possibilities to score n within k rounds with possible scoring ranging from 0 to N values. As you can see, for k fixed, it is possible to find a closed-form formula, which can be generalized quite easily for all k via sums and products (but this is no more closed-form)

The case disjunction in the print is to catch up with the different scoring with 1 or more pins.

To find out how I came up with these formulas, take N infinite (the problem become much more simpler). Then this is the same method with N finite, but this is a bit more involved.

4 Likes

yea i was trying to come up with a single formula based on â€śn pick râ€ť formulas but in the end using loops/recursion didnâ€™t timeout so took the lazy way out. then again this is a programming site and not a discrete math course.

1 Like