Skip to content

Latest commit

 

History

History
46 lines (25 loc) · 739 Bytes

Hex_Hash_Sum.md

File metadata and controls

46 lines (25 loc) · 739 Bytes

CodeWars Python Solutions


Hex Hash Sum

Complete the function that accepts a valid string and returns an integer.

Wait, that would be too easy! Every character of the string should be converted to the hex value of its ascii code, then the result should be the sum of the numbers in the hex strings (ignore letters).

Examples

"Yo" ==> "59 6f" ==> 5 + 9 + 6 = 20
"Hello, World!"  ==> 91
"Forty4Three"    ==> 113

Given Code

def hex_hash(code):
    pass

Solution

def hex_hash(code):
    return sum([sum([int(i) for i in hex(ord(c)) if i.isdigit()]) for c in code for i in c])

See on CodeWars.com