DNPotapov / Codewars-katas-

0 stars 0 forks source link

Char Code Calculation (7 kyu) #4

Open DNPotapov opened 1 year ago

DNPotapov commented 1 year ago
def calc(x):
    result = ""
    for item in x:
        result += str(ord(item))
    return (sum([int(i) for i in result]) - sum([int(i) for i in result.replace("7","1")]))
DNPotapov commented 1 year ago

Given a string, turn each character into its ASCII character code and join them together to create a number - let's call this number total1:

'ABC' --> 'A' = 65, 'B' = 66, 'C' = 67 --> 656667 Then replace any incidence of the number 7 with the number 1, and call this number 'total2':

total1 = 656667 ^ total2 = 656661 ^ Then return the difference between the sum of the digits in total1 and total2:

(6 + 5 + 6 + 6 + 6 + 7)

DNPotapov commented 1 year ago

https://www.codewars.com/kata/57f75cc397d62fc93d000059