aboutsummaryrefslogtreecommitdiff
path: root/challenge-252
diff options
context:
space:
mode:
authorMohammad Sajid Anwar <Mohammad.Anwar@yahoo.com>2024-01-20 11:19:01 +0000
committerGitHub <noreply@github.com>2024-01-20 11:19:01 +0000
commitf09e2f0737ddeeb6e15b051063257529a7b1ac25 (patch)
tree27eea865cbfa6eed6bdaff20c967fa4a380fb253 /challenge-252
parentac8392afeb871c0b388d45d2cbcf5fbfa9340fb2 (diff)
parent9645a374086232533ea6cccd74b8b035be54490f (diff)
downloadperlweeklychallenge-club-f09e2f0737ddeeb6e15b051063257529a7b1ac25.tar.gz
perlweeklychallenge-club-f09e2f0737ddeeb6e15b051063257529a7b1ac25.tar.bz2
perlweeklychallenge-club-f09e2f0737ddeeb6e15b051063257529a7b1ac25.zip
Merge pull request #9427 from steve-g-lynn/branch-for-challenge-252
pwc 252
Diffstat (limited to 'challenge-252')
-rw-r--r--challenge-252/steve-g-lynn/blog.txt1
-rw-r--r--challenge-252/steve-g-lynn/perl/ch-1.pl16
-rw-r--r--challenge-252/steve-g-lynn/perl/ch-2.pl16
-rw-r--r--challenge-252/steve-g-lynn/python/ch-1.py14
-rw-r--r--challenge-252/steve-g-lynn/python/ch-2.py15
5 files changed, 62 insertions, 0 deletions
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]
+