aboutsummaryrefslogtreecommitdiff
path: root/challenge-246/luca-ferrari/python/ch-2.py
diff options
context:
space:
mode:
author冯昶 <fengchang@novel-supertv.com>2023-12-11 18:11:32 +0800
committer冯昶 <fengchang@novel-supertv.com>2023-12-11 18:11:32 +0800
commite94f52525bf99cded9ba76e696b691c7a657500b (patch)
tree4e614b7233580b0aee9c58e23e87eff5e9331aee /challenge-246/luca-ferrari/python/ch-2.py
parent4ac02978fd0732a7fcc61a9def95e1e08100e4c9 (diff)
parent98df168725aa587bd4db1e24018dae1ca77b29da (diff)
downloadperlweeklychallenge-club-e94f52525bf99cded9ba76e696b691c7a657500b.tar.gz
perlweeklychallenge-club-e94f52525bf99cded9ba76e696b691c7a657500b.tar.bz2
perlweeklychallenge-club-e94f52525bf99cded9ba76e696b691c7a657500b.zip
Merge remote-tracking branch 'upstream/master'
Diffstat (limited to 'challenge-246/luca-ferrari/python/ch-2.py')
-rw-r--r--challenge-246/luca-ferrari/python/ch-2.py43
1 files changed, 43 insertions, 0 deletions
diff --git a/challenge-246/luca-ferrari/python/ch-2.py b/challenge-246/luca-ferrari/python/ch-2.py
new file mode 100644
index 0000000000..dbd0395ca7
--- /dev/null
+++ b/challenge-246/luca-ferrari/python/ch-2.py
@@ -0,0 +1,43 @@
+#!python
+
+#
+# Perl Weekly Challenge 246
+# Task 2
+#
+# See <https://perlweeklychallenge.org/blog/perl-weekly-challenge-246/>
+#
+
+import sys
+from itertools import count
+
+# task implementation
+def main( argv ):
+ nums = list( map( int, argv ) )
+ ko = len( nums ) - 2
+
+ for current_index in range( 2, len( nums ) ):
+ for p in count( start = 1 ):
+ for q in count( start = 1 ):
+ if nums[ current_index ] == ( p * nums[ current_index - 2 ] + q * nums[ current_index - 1 ] ) \
+ or nums[ current_index ] == ( p * -1 * nums[ current_index - 2 ] + q * nums[ current_index - 1 ] ) \
+ or nums[ current_index ] == ( p * -1 * nums[ current_index - 2 ] + q * -1 * nums[ current_index - 1 ] ) \
+ or nums[ current_index ] == ( p * nums[ current_index - 2 ] + q * -1 * nums[ current_index - 1 ] ):
+ ok = True
+ ko = ko - 1
+ break
+
+ if ok:
+ break
+
+ if ko == 0:
+ print( 'True' )
+ else:
+ print( 'False' )
+
+
+
+# invoke the main without the command itself
+if __name__ == '__main__':
+ main( sys.argv[ 1: ] )
+
+