123456789101112131415161718192021222324252627282930313233343536373839404142 |
- <?php
- declare(strict_types=1);
- function score(string $word): int {
- $score = 0;
- $chars = mb_str_split(mb_strtoupper($word));
- foreach ($chars as $char) {
- $score += match ($char) {
- 'D', 'G' => 2,
- 'B', 'C', 'M', 'P' => 3,
- 'F', 'H', 'V', 'W', 'Y' => 4,
- 'K' => 5,
- 'J', 'X' => 8,
- 'Q', 'Z' => 10,
- default => 1,
- };
- }
- return $score;
- }
|