From 7818adc9a1b33d20af1f48d4aebfbd86cecde184 Mon Sep 17 00:00:00 2001 From: Titouan Rigoudy Date: Sat, 27 Sep 2014 12:30:42 -0400 Subject: [PATCH] Solved Sherlock and the Beast --- .../sherlock_and_the_beast.py | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 sherlock_and_the_beast/sherlock_and_the_beast.py diff --git a/sherlock_and_the_beast/sherlock_and_the_beast.py b/sherlock_and_the_beast/sherlock_and_the_beast.py new file mode 100644 index 0000000..736e849 --- /dev/null +++ b/sherlock_and_the_beast/sherlock_and_the_beast.py @@ -0,0 +1,25 @@ +#!/usr/bin/python3 + +# https://www.hackerrank.com/challenges/sherlock-and-the-beast + +import sys + +def largest_decent_number(num_digits): + if num_digits in [1,2,4,7]: + return '-1' + quot3, mod3 = divmod(num_digits, 3) + if mod3 == 0: + return '555' * quot3 + elif mod3 == 1: + return '555' * (quot3 - 3) + '3333333333' + elif mod3 == 2: + return '555' * (quot3 - 1) + '33333' + + +def main(): + num_tests = int(sys.stdin.readline()) + for _ in range(num_tests): + print(largest_decent_number(int(sys.stdin.readline()))) + +if __name__ == '__main__': + main() \ No newline at end of file