Advertisement
Guest User

Untitled

a guest
Mar 20th, 2018
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.09 KB | None | 0 0
  1. def is_number_balanced(num):
  2. num = (list(str(num)))
  3. num = [int(i) for i in num]
  4. half = len(num) // 2
  5.  
  6. if len(num) % 2:
  7. lhs = num[:half]
  8. rhs = num[half + 1:]
  9. else:
  10. lhs = num[:half]
  11. rhs = num[half:]
  12.  
  13. return sum(lhs) == sum(rhs)
  14.  
  15.  
  16. print(is_number_balanced(9))
  17. print(is_number_balanced(4518))
  18. print(is_number_balanced(28471))
  19. print(is_number_balanced(1238033))
  20. print("\n\n")
  21.  
  22.  
  23. def increasing_or_decreasing(seq):
  24. result = []
  25.  
  26. for x in range(0, len(seq) - 1):
  27. if(seq[x + 1] > seq[x]):
  28. result.append(1)
  29. elif (seq[x + 1] == seq[x]):
  30. result.append(0)
  31. else:
  32. result.append(-1)
  33.  
  34. if sum(result) == len(result):
  35. return "Up!"
  36. elif sum(result) == -len(result):
  37. return "Down!"
  38. else:
  39. return False
  40.  
  41.  
  42. print(increasing_or_decreasing([1, 2, 3, 4, 5]))
  43. print(increasing_or_decreasing([5, 6, -10]))
  44. print(increasing_or_decreasing([1, 1, 1, 1]))
  45. print(increasing_or_decreasing([9, 8, 7, 6]))
  46. print("\n\n")
  47.  
  48.  
  49. # def get_largest_palindrome(num):
  50.  
  51.  
  52.  
  53.  
  54. def sum_of_numbers(input_string):
  55. nums = [0]
  56. temp = ""
  57. prev = False
  58.  
  59. for i in range(len(input_string)):
  60. if input_string[i].isdigit():
  61. if not i == len(input_string) - 1:
  62. temp += input_string[i]
  63. prev = True
  64. else:
  65. temp += input_string[i]
  66. nums.append(temp)
  67. else:
  68. if prev:
  69. nums.append(temp)
  70. prev = False
  71. temp = ""
  72.  
  73. nums = [int(i) for i in nums]
  74. return sum(nums)
  75.  
  76.  
  77. print(sum_of_numbers("ab125cd3"))
  78. print(sum_of_numbers("ab12"))
  79. print(sum_of_numbers("ab"))
  80. print(sum_of_numbers("1101"))
  81. print(sum_of_numbers("1111O"))
  82. print(sum_of_numbers("1abc33xyz22"))
  83. print(sum_of_numbers("0hfabnek"))
  84. print("\n\n")
  85.  
  86.  
  87. def birthday_ranges(birthdays, ranges):
  88. people = []
  89. counter = 0
  90.  
  91. for period in ranges:
  92. for day in birthdays:
  93. if period[0] <= day and period[1] >= day:
  94. counter += 1
  95. people.append(counter)
  96. counter = 0
  97.  
  98. return people
  99.  
  100.  
  101. print(birthday_ranges([1, 2, 3, 4, 5],
  102. [(1, 2), (1, 3), (1, 4), (1, 5), (4, 6)]))
  103. print(birthday_ranges([5, 10, 6, 7, 3, 4, 5, 11, 21, 300, 15],
  104. [(4, 9), (6, 7), (200, 225), (300, 365)]))
  105. print("\n\n")
  106.  
  107.  
  108. def group(elem):
  109. from itertools import groupby
  110.  
  111. return [list(grp) for k, grp in groupby(elem)]
  112.  
  113.  
  114. def capitalise(a):
  115. return a
  116.  
  117.  
  118. def numbers_to_message(pressed_sequence):
  119. keypad = [[" "], [""], ["a", "b", "c"], ["d", "e", "f"],
  120. ["g", "h", "i"], ["j", "k", "l"], ["m", "n", "o"],
  121. ["p", "q", "r", "s"], ["t", "u", "v"], ["w", "x", "y", "z"]]
  122.  
  123. pressed_sequence = group(pressed_sequence)
  124. # print(keypad)
  125.  
  126. for item in pressed_sequence:
  127. print(len(item))
  128. if item == 1:
  129. continue
  130. else:
  131. continue
  132.  
  133. print(numbers_to_message([2, -1, 2, 2, -1, 2, 2, 2]))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement