Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import strutils, math
- proc cut[T](num: T; x: int): int =
- num div pow(10.0, x.float).int
- proc nth[T](num: T; th: int): int =
- cut(num, th) - 10*cut(num, th+1)
- var counter = 0
- for i in 1_001..999_999:
- let
- sum_left = nth(i, 5) + nth(i, 4) + nth(i, 3)
- sum_right = nth(i, 2) + nth(i, 1) + nth(i, 0)
- if sum_left == sum_right:
- inc counter
- echo "Found $# happy tickets." % [$counter]
Advertisement
Add Comment
Please, Sign In to add comment