June 02, 2026

Solution for Codyssi 2025 - Games in a Storm

Link to the puzzle text

Part 1

In this puzzle, we have a list of tuple of a string and a tuple. The string encodes an arbitrary base number with the exact base set by the second part of the tuple. The letters used for the digits above 9 are the lowercase letters followed by the uppercase letters. We should write every number in base 10 and find the largest number out of the list.

We need a function for parsing a string using an arbitrary base. This is simply:

total = 0
for c in s:
total *= base
total += char_value(c, total)

With the function char_value transforming a single character into a number.

def char_value(c):
if "0" <= c <= "9":
return int(c)
elif "A" <= c <= "Z":
return ord(c) - ord("A") + 10
return ord(c) - ord("a") + 36

Once we call the function for parsing the string on all input lines, we can take the largest value out of them for the answer.

Part 2

In part 2, we should sum up all the parsed numbers and write the result back as a base-68 string. In base 68, the digits above 9 are the lowercase letters, then the uppercase letters followed by the characters !@#$%

Taking a number and writing it in base-68, this is basically the inverse of the previous function:

def num_to_string(num):
s = ""
digitschars = digits + ascii_uppercase + ascii_lowercase + "!@#$%^"
while num > 0:
last_digit = num % 68
s = digitschars[last_digit] + s
num //= 68
return s

This function is called with the sum of the parsed numbers from part 1 for the answer.

Part 3

In part 3, we should find the smallest base which can still represent the sum of all parsed numbers.

This can be done analitically. The largest number M with 4 characters in base N is M=N^4 -1. We can rewrite this so the base for a given number M must be N=M^(1/4) + 1. So we simply take the fourth-root of the sum, round it up and add one for the answer.

Link to my sol    utions

No comments:

Post a Comment