SpinalHDL
1 / 1
View past submissionsLeaderboard

Description

Railgun Calibration

Your electromagnetic railgun consists of a linear array of accelerator coils. Each coil is rated from 1-9 based on its magnetic field strength. The coils must fire in their physical order along the barrel - you cannot rearrange them.

Due to power constraints, you can only energize exactly 3 coils per shot. Each successive coil has an exponentially diminishing effect on the projectile's final velocity - the first energized coil contributes far more than the second, which contributes far more than the third. This means selecting the highest-rated coils for the early positions is critical.

The coil activation sequence determines your acceleration profile. To maximize muzzle velocity, you must select the 3 coils that produce the highest possible activation code - the number formed by reading the selected coils' ratings from breech to muzzle.

Example: If your coil array is 23456 and you energize coils at positions 2, 4, and 5, your activation code would be 356. In the array 976543212222222, the maximum activation code is 976 - achieved by energizing the first three coils.

Additional examples:

  • 722222222222218728 (select the 7 at the start, any 2, and the 8 at the end)
  • 345345345345389589 (select the 5, 8, and 9 near the end)
  • 636363922214333943 (select the 9, then the 4, then a 3)

Given your railgun's coil configuration as a stream of 4-bit BCD digits (values 1-9), output the maximum 3-digit activation code as an integer.

Input

coils

Stream of 4-bit Unsigned Integer
Coil ratings (1-9) in BCD format.

Output

64-bit Unsigned Integer
Maximum 3-digit activation code as integer.