From 34e5d873797f79c00e5334a6dd2ed06172e64c41 Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Mon, 21 Nov 2022 16:15:00 +0100 Subject: [PATCH] general: ex4: add solution --- general/ex4.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100755 general/ex4.py diff --git a/general/ex4.py b/general/ex4.py new file mode 100755 index 0000000..d86d5ae --- /dev/null +++ b/general/ex4.py @@ -0,0 +1,19 @@ +#!/usr/bin/env python + + +def naive_solution(x: int) -> int: + assert 0 <= x < 10, f"{x} is not a digit" + xx = x * 10 + x + xxx = xx * 10 + x + xxxx = xxx * 10 + x + return x + xx + xxx + xxxx + + +def solution(x: int) -> int: + assert 0 <= x < 10, f"{x} is not a digit" + return x * 1234 + + +if __name__ == "__main__": + for x in range(10): + print(f"{naive_solution(x)} == {solution(x)}")