Advertisement
jxsl13

Swedish number plates

Oct 3rd, 2019
210
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.57 KB | None | 0 0
  1. """
  2. Swedish car plates: ABC123
  3. where 123 must be either
  4. 1 + 2 = 3 // right
  5. 1 - 2 = 3 // wrong
  6. 1 * 2 = 3 // wrong
  7. 1 / 2 = 3 // wrong
  8. => Is a valid plate,
  9. cuz one arithmetic operation works
  10. and the third number can be created using one of these
  11. arithmetic operations in the correct order of the numbers.
  12. """
  13.  
  14.  
  15. valid_numbers = [int(i) for i in range(10)]
  16. alphabet = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z']
  17.  
  18. num_letter_combinations = len(alphabet) ** 3
  19.  
  20. result = set()
  21. num_number_combinations = 0
  22.  
  23. for i in range(10):
  24.     for j in range(10):
  25.         if i + j in valid_numbers:
  26.             r = i * 100 + j * 10 + (i + j)
  27.             result.add(r)
  28.             print(i, "+", j, "=", i + j, ";%03d" % r)
  29.  
  30.         if i - j in valid_numbers:
  31.             r = i * 100 + j * 10 + (i - j)
  32.             result.add(r)
  33.             print(i, "-", j, "=", i - j, ";%03d" % r)
  34.  
  35.         if j > 0 and i % j == 0 and i / j in valid_numbers:
  36.             r = i * 100 + j * 10 + (i / j)
  37.             result.add(r)
  38.             print(i, "/", j, "=", int(i / j), ";%03d" % r)
  39.        
  40.         if i * j in valid_numbers:
  41.             r = i * 100 + j * 10 + (i * j)
  42.             result.add(r)
  43.             print(i, "*", j, "=", i * j, ";%03d" % r)
  44.  
  45. result = list(result)
  46. result.sort()
  47. num_number_combinations = len(result)
  48.  
  49.  
  50. print("Letter Combinations:", num_letter_combinations)
  51. print("Number Combinations:", num_number_combinations)
  52. print("Total Combinations:", num_letter_combinations * num_number_combinations)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement