diff options
| author | Simon Green <mail@simon.green> | 2021-12-23 19:42:36 +1100 |
|---|---|---|
| committer | Simon Green <mail@simon.green> | 2021-12-23 19:42:36 +1100 |
| commit | 21f3a3e3921adb1d855618833cd662471c588015 (patch) | |
| tree | 0b74a4712a1300737c6c53e40c9c7a3cff6a6a5d /challenge-144/sgreen/python/ch-2.py | |
| parent | 1aa8ecccec917bbdee515fef036e8f84c47dae22 (diff) | |
| download | perlweeklychallenge-club-21f3a3e3921adb1d855618833cd662471c588015.tar.gz perlweeklychallenge-club-21f3a3e3921adb1d855618833cd662471c588015.tar.bz2 perlweeklychallenge-club-21f3a3e3921adb1d855618833cd662471c588015.zip | |
sgreen solutions to challenge 144
Diffstat (limited to 'challenge-144/sgreen/python/ch-2.py')
| -rwxr-xr-x | challenge-144/sgreen/python/ch-2.py | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/challenge-144/sgreen/python/ch-2.py b/challenge-144/sgreen/python/ch-2.py new file mode 100755 index 0000000000..086ad9a6f1 --- /dev/null +++ b/challenge-144/sgreen/python/ch-2.py @@ -0,0 +1,37 @@ +#!/usr/bin/env python + +import math +import sys + + +def main(inputs): + m = int(inputs[0]) + n = int(inputs[1]) + + if m < 1: + raise ValueError('The first number must be a positive integer') + if n < 1: + raise ValueError('The second number must be a positive integer') + + # We know the first three values in the sequence are the two numbers and + # the sum + seq = [m, n, m + n] + current_value = seq[-1] + 1 + + while len(seq) < 10: + sums = 0 + for i in range(m, math.ceil(current_value / 2)): + j = current_value - i + if i in seq and j in seq: + sums += 1 + + if sums == 1: + seq.append(current_value) + + current_value += 1 + + print(*seq, sep=', ') + + +if __name__ == '__main__': + main(sys.argv[1:]) |
