loading...

re: Daily Challenge #222 - Parse Bank Account Numbers VIEW POST

FULL DISCUSSION
 

This is a rather hacky Python solution that relies on a dictionary of strings mapping to digits. I made the assumption that input would come as an array of strings, one for each level of the digits.

Code

digit_dict = {" _ | | _ ": 0, "     |  |": 1,
              " _  _||_ ": 2, " _  _| _|": 3,
              "   |_|  |": 4, " _ |_  _|": 5,
              " _ |_ |_|": 6, " _   |  |": 7,
              " _ |_||_|": 8, " _ |_| _|" : 9}

def parse_bank_code(str_list, digit_dict):
  """
  Function that takes awkward digit string and and digit dict;
  returns a normal string of digits.
  """

  digits = []  # Holder for digits

  # Loop through three places at a time
  for i in range(0, len(str_list[0]), 3):

    # Take three characters from each level as a list
    digit = [x[i:i+3] for x in str_list]

    # Join the characters together and get the dict value
    digit = digit_dict["".join(digit)]

    # Add the digit as a string to the list
    digits.append(str(digit))

  # Return the final code
  return "".join(digits)
Code of Conduct Report abuse