From 7b07d041a8c01b78ca1d311502b5e93b5d0a5153 Mon Sep 17 00:00:00 2001 From: Simon Green Date: Sun, 7 Jan 2024 20:46:00 +1100 Subject: Simon's solution to challenge 250 --- challenge-250/sgreen/python/ch-1.py | 23 +++++++++++++++++++++++ challenge-250/sgreen/python/ch-2.py | 17 +++++++++++++++++ 2 files changed, 40 insertions(+) create mode 100755 challenge-250/sgreen/python/ch-1.py create mode 100755 challenge-250/sgreen/python/ch-2.py (limited to 'challenge-250/sgreen/python') diff --git a/challenge-250/sgreen/python/ch-1.py b/challenge-250/sgreen/python/ch-1.py new file mode 100755 index 0000000000..d907d03257 --- /dev/null +++ b/challenge-250/sgreen/python/ch-1.py @@ -0,0 +1,23 @@ +#!/usr/bin/env python3 + +import sys + + +def main(ints): + solution = -1 + + # Loop through each position + for idx in range(len(ints)): + # The index mod 10 is the value at this position + if idx % 10 == ints[idx]: + # We have the best solution, so no need to continue looping + solution = idx + break + + print(solution) + + +if __name__ == '__main__': + # Convert input into integers + array = [int(n) for n in sys.argv[1:]] + main(array) diff --git a/challenge-250/sgreen/python/ch-2.py b/challenge-250/sgreen/python/ch-2.py new file mode 100755 index 0000000000..9ee64eea3f --- /dev/null +++ b/challenge-250/sgreen/python/ch-2.py @@ -0,0 +1,17 @@ +#!/usr/bin/env python3 + +import re +import sys + + +def calculate_value(s): + '''Return the number if it looks like an integer else the length of string''' + return int(s) if re.search(r'^\d+$', s) else len(s) + + +def main(values): + print(max(map(calculate_value, values))) + + +if __name__ == '__main__': + main(sys.argv[1:]) -- cgit