Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from math import ceil
- def isHappyTicket(ticketNumber):
- ticket = str(ticketNumber)
- leftHalfSum = sum(list(map(int, ticket[:3])))
- rightHalfSum = sum(list(map(int, ticket[3:])))
- return leftHalfSum == rightHalfSum
- def isPalindrome(str):
- m = ceil(len(str) / 2)
- return str[:m] == str[:m-1:-1]
- def main():
- numberOfHappyTicket = 0
- happyTicketPol = 0
- start = 100000
- end = start * 10
- for ticket in range(start, end):
- if isHappyTicket(ticket):
- numberOfHappyTicket += 1
- if isPalindrome(str(ticket)):
- happyTicketPol += 1
- print(f"Number of happy tickets: {numberOfHappyTicket}\nNumber of palindromes: {happyTicketPol}")
- if __name__ == "__main__":
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement