I encountered some silly code from a game and I figured this would actually turn into a fun golfing problem, so:
Given any ASCII string in the limited char range specified below.
Append as few characters as possible such that, given:
i = 1
sum = 0
for char in string
sum += char.intval * i++
end for
sum % 1000 == 0
Where intval
is the ASCII value of the character.
Both the string prefix and your permitted chars are: A-Z a-z 0-9 . _
You may assume the numeric result of the pseudo-code above is a number that fits within an unsigned 32-bit int (i.e. no input will be given that causes sum
to exceed 2^32-1 after appending the minimum possible chars to satisfy sum
)
You may choose to output the input concatenated with your calculated suffix string, or just your suffix string as you prefer.
Example
Given the input ddd
the shortest solution would be appending one more d
because (100 + (100*2) + (100*3) + (100*4)) % 1000 == 0