From 9645a374086232533ea6cccd74b8b035be54490f Mon Sep 17 00:00:00 2001 From: Stephen Lynn Date: Sat, 20 Jan 2024 08:44:12 +0800 Subject: pwc 252 --- challenge-252/steve-g-lynn/blog.txt | 1 + challenge-252/steve-g-lynn/perl/ch-1.pl | 16 ++++++++++++++++ challenge-252/steve-g-lynn/perl/ch-2.pl | 16 ++++++++++++++++ challenge-252/steve-g-lynn/python/ch-1.py | 14 ++++++++++++++ challenge-252/steve-g-lynn/python/ch-2.py | 15 +++++++++++++++ 5 files changed, 62 insertions(+) create mode 100644 challenge-252/steve-g-lynn/blog.txt create mode 100644 challenge-252/steve-g-lynn/perl/ch-1.pl create mode 100644 challenge-252/steve-g-lynn/perl/ch-2.pl create mode 100644 challenge-252/steve-g-lynn/python/ch-1.py create mode 100644 challenge-252/steve-g-lynn/python/ch-2.py diff --git a/challenge-252/steve-g-lynn/blog.txt b/challenge-252/steve-g-lynn/blog.txt new file mode 100644 index 0000000000..8751373bc6 --- /dev/null +++ b/challenge-252/steve-g-lynn/blog.txt @@ -0,0 +1 @@ +https://thiujiac.blogspot.com/2024/01/pwc-252.html diff --git a/challenge-252/steve-g-lynn/perl/ch-1.pl b/challenge-252/steve-g-lynn/perl/ch-1.pl new file mode 100644 index 0000000000..c30a0b50e1 --- /dev/null +++ b/challenge-252/steve-g-lynn/perl/ch-1.pl @@ -0,0 +1,16 @@ +# Perl 4.019 on DOSBOX + +sub special_numbers { + local (@ints)=@_; + local ($n) = scalar(@ints); + local ($i); + local ($retval) = 0; + foreach $i (1 .. $n) { + ($n % $i) || ($retval += ($ints[$i-1] * $ints[$i-1]) ); + } + $retval; +} + +print &special_numbers(1,2,3,4),"\n"; #21 +print &special_numbers(2,7,1,19,18,3),"\n"; #63 + diff --git a/challenge-252/steve-g-lynn/perl/ch-2.pl b/challenge-252/steve-g-lynn/perl/ch-2.pl new file mode 100644 index 0000000000..226ed11eff --- /dev/null +++ b/challenge-252/steve-g-lynn/perl/ch-2.pl @@ -0,0 +1,16 @@ +#perl 4.019 on DOSBOX + +sub unique_sum_zero { + local($n)=@_; + local(@retval)=(); + ($n % 2) && push( @retval, 0); + local ($i); + for $i (1 .. ($n/2)) { + push( @retval,(-$i, $i) ); + } + @retval; +} + +print join(',',&unique_sum_zero(5)),"\n"; #0,-1,1,-2,2 +print join(',',&unique_sum_zero(3)),"\n"; #0,-1,1 +print join(',',&unique_sum_zero(1)),"\n"; #0 diff --git a/challenge-252/steve-g-lynn/python/ch-1.py b/challenge-252/steve-g-lynn/python/ch-1.py new file mode 100644 index 0000000000..e28c465810 --- /dev/null +++ b/challenge-252/steve-g-lynn/python/ch-1.py @@ -0,0 +1,14 @@ + +# Python 1.4 beta on DOSBOX + +def special_numbers( ints ): + retval=0 + n=len(ints) + for i in range(n): + if ((n % (i+1)) == 0): + retval = retval + (ints[i]*ints[i]) + return retval + +print special_numbers([1,2,3,4]) +print special_numbers([2,7,1,19,18,3]) + diff --git a/challenge-252/steve-g-lynn/python/ch-2.py b/challenge-252/steve-g-lynn/python/ch-2.py new file mode 100644 index 0000000000..3947e22c8c --- /dev/null +++ b/challenge-252/steve-g-lynn/python/ch-2.py @@ -0,0 +1,15 @@ +# python 1.4 beta on DOSBOX + +def unique_sum_zero(n): + retval=[] + if ((n % 2) > 0): + retval.append(0) + for i in range(n/2): + retval.append(-(i+1)) + retval.append(i+1) + return retval + +print unique_sum_zero(5) #[0,-1,1,-2,2] +print unique_sum_zero(3) #[0,-1,1] +print unique_sum_zero(1) #[0] + -- cgit