Welcome to HBH! If you have tried to register and didn't get a verification email, please using the following link to resend the verification email.
Javascript 16 - Python Code Bank
Javascript 16
takes less than a second
##### target checksum is 88692587, because sum starts with 1, and not 0, we can start sum with 0
##### and treat the checksum as 88692588.
##### because we are using only integers, the checksum must be divisable by the length of the word.
##### The only reasonable lengths for this are 9, 12, 18. 12 being the most reasonable.
##### The equation were solving is:
#####
##### 88692588 / (n + 1) = sum from 1 to N of: (i^3 * Ai^2)
##### where n + 1 is the length of the string, i is the index of the character, Ai is the index of the character in the "tab" array
##### range of characters in tab array: 0, 19-85
targetValue = 7391049
SUCCESS = 0
FAILURE = -1
"""
translate int array to string
"""
def translateArr(arr):
wordDic = " azertyuiopqsdfghjklmwxcvbnAZERTYUIOPQSDFGHJKLMWXCVBN0123456789_$&#@"
wordArr = "a"
for i in arr:
wordArr += wordDic[i]
return wordArr
"""
sums the array by the formula
"""
def arrSum(arr):
sum = 0
for i in range(len(arr)):
sum += (arr[i]**2) * ((i+1)**3)
return sum
"""
initializes the array
"""
def initArr(arr, fromIndex):
for i in range(fromIndex):
arr.append(0)
"""
resets the array memebers from an index downwards
"""
def resetArr(arr, fromIndex):
for i in range(fromIndex):
arr[i] = 0
"""
creates an array which will answer the riddle
"""
def createArr(arr, i):
for j in range(86, 18, -1):
arr[i] = j
sum = arrSum(arr)
if targetValue < sum:
continue
if targetValue == sum:
print translateArr(arr)
return SUCCESS
if 0 != i:
if SUCCESS == createArr(arr, i - 1):
return SUCCESS
else:
resetArr(arr, i)
continue
return FAILURE
arr = []
initArr(arr, 11)
createArr(arr, len(arr) - 1)
Comments
Sorry but there are no comments to display