Back
Close
  • 1

Learning Opportunities

This puzzle can be solved using the following concepts. Practice using these concepts and improve your skills.

Statement

 Goal

Knister is a dice game played on a 5×5 scorecard. Each round, two six-sided dice are rolled and the player writes their sum (a number from 2 to 12) in an empty cell. After 25 rounds the card is full and gets scored.

The card is scored line by line. There are 12 lines: the 5 rows, the 5 columns and the 2 diagonals. Every cell belongs to several lines; the centre cell even belongs to four.

Each line scores points for the combination formed by its five numbers:


Combination Definition Points Example
---------------------------------------------------------
Pair Only one value 1 4 5 6 7 5
appears exactly
twice
Two pairs Two distinct values 3 5 6 6 10 5
appear exactly
twice each
Three of a kind One value appears 3 7 8 7 7 4
exactly three
times
Full house Three of a kind 8 4 9 4 4 9
plus a pair

Four of a kind One value appears 6 6 3 6 6 6
exactly four
times
Five of a kind One value appears 10 8 8 8 8 8
exactly five
times
Straight 7 appears in a 8 7 10 8 6 9
containing a 7 straight

Straight 7 does not appear 12 3 5 6 2 4
without a 7 in a straight


- A straight is five consecutive numbers, in any order. Straights do not wrap around: for example, 10 11 12 2 3 is not a straight.
- A line scores exactly one combination: the one that describes all five numbers. A smaller combination formed by a subset of the five numbers does not count. For example, a full house scores 8, not 3 + 1.
- A line without any of these combinations scores 0.
- Points scored on the two diagonals are doubled.

(7 is the most likely sum of two dice, so a straight that avoids it is rarer and worth more.)

Output the total score of the scorecard.
Input
5 lines: 5 space-separated integers value, one row of the scorecard.
Output
One integer: the total score of the scorecard.
Constraints
2 ≤ value ≤ 12
Example
Input
5 6 9 2 7
3 10 8 10 5
4 5 11 6 10
7 9 4 8 2
12 4 5 7 6
Output
1

A higher resolution is required to access the IDE