SpinalHDL
1 / 1
View past submissionsLeaderboard

Description

Counterfeit

You've intercepted a shipment of cash from a counterfeiting ring. The feds need you to identify the fakes.

The forgers got lazy. Every counterfeit bill has a serial number made of some digit sequence repeated at least twice. Examples: 123123 (123 twice), 7777 (7 four times), 565656 (56 three times).

Your input is a list of serial number ranges to check. Each range gives its first and last serial number.

No serial numbers have leading zeros.

Given the ranges, find all counterfeit serial numbers and return their sum.

Clarifications:

  • "Repeated" means the digit sequence appears two or more times. A single digit by itself is not counterfeit (e.g., 1 is not, 11 is).
  • Each range is inclusive and provided as (low, high) with low <= high. You do not need to handle reversed ranges.
  • Ranges may overlap; treat each range independently when summing (i.e., a serial number can contribute multiple times if it appears in multiple ranges).
  • Ranges can cross digit-length boundaries (e.g., 0–1000). You must handle mixed digit lengths; there is no guarantee that all serials in a range have the same number of digits.

Example: Ranges [(10, 25), (100, 115)]:

  • 10-25: 11, 22 (counterfeit)
  • 100-115: 111 (counterfeit)

Answer: 11 + 22 + 111 = 144

Input

ranges

Stream of 24-bit Unsigned Integer Pair
Serial number ranges to check.

Output

31-bit Unsigned Integer
Sum of all counterfeit serial numbers.