diff options
| author | 冯昶 <seaker@qq.com> | 2021-11-01 15:35:34 +0800 |
|---|---|---|
| committer | 冯昶 <seaker@qq.com> | 2021-11-01 15:35:34 +0800 |
| commit | 47c592ce79003fa05dc7f2d5d1f22c5ef2ff1b4e (patch) | |
| tree | e17cb3ca27261d8e37f610cd90a8081a2110e6ff /challenge-122 | |
| parent | 6feeaa5f2efa5e3a0e27aa9610f0f686ea7c34a8 (diff) | |
| parent | aa267843f108e0b591cbbf2f13428354c74b2f70 (diff) | |
| download | perlweeklychallenge-club-47c592ce79003fa05dc7f2d5d1f22c5ef2ff1b4e.tar.gz perlweeklychallenge-club-47c592ce79003fa05dc7f2d5d1f22c5ef2ff1b4e.tar.bz2 perlweeklychallenge-club-47c592ce79003fa05dc7f2d5d1f22c5ef2ff1b4e.zip | |
Merge remote-tracking branch 'upstream/master'
Diffstat (limited to 'challenge-122')
| -rw-r--r-- | challenge-122/karishma/README | 1 | ||||
| -rw-r--r-- | challenge-122/karishma/c/ch-1.c | 30 | ||||
| -rw-r--r-- | challenge-122/karishma/cpp/ch1.cpp | 17 | ||||
| -rw-r--r-- | challenge-122/karishma/js/ch-1.js | 6 | ||||
| -rw-r--r-- | challenge-122/paulo-custodio/Makefile | 2 | ||||
| -rw-r--r-- | challenge-122/paulo-custodio/perl/ch-1.pl | 26 | ||||
| -rw-r--r-- | challenge-122/paulo-custodio/perl/ch-2.pl | 55 | ||||
| -rw-r--r-- | challenge-122/paulo-custodio/python/ch-1.py | 25 | ||||
| -rw-r--r-- | challenge-122/paulo-custodio/python/ch-2.py | 52 | ||||
| -rw-r--r-- | challenge-122/paulo-custodio/t/test-1.yaml | 23 | ||||
| -rw-r--r-- | challenge-122/paulo-custodio/t/test-2.yaml | 30 |
11 files changed, 267 insertions, 0 deletions
diff --git a/challenge-122/karishma/README b/challenge-122/karishma/README new file mode 100644 index 0000000000..896eab1d74 --- /dev/null +++ b/challenge-122/karishma/README @@ -0,0 +1 @@ +Solutions by Karishma Rajput. diff --git a/challenge-122/karishma/c/ch-1.c b/challenge-122/karishma/c/ch-1.c new file mode 100644 index 0000000000..d52a21d311 --- /dev/null +++ b/challenge-122/karishma/c/ch-1.c @@ -0,0 +1,30 @@ +#include <stdio.h> +#include<stdlib.h> + +int main() { + int n=0; + int* ptr; + printf("Enter total number of inputs to be entered: "); + scanf("%d", &n); + ptr = (int*)calloc(n, sizeof(int)); + if (ptr == NULL) { + printf("Memory not allocated.\n"); + exit(0); + } + else { + for (int i = 1; i <= n; i++) { + int temp=0; + scanf("%d",&temp); + ptr[i] = temp; + } + printf("\n"); + } + int sum = 0; + for (int j = 1; j <= n; j++) { + sum += ptr[j]; + printf("%d ", sum / j); + } + printf("\n"); + free(ptr); + return 0; +}
\ No newline at end of file diff --git a/challenge-122/karishma/cpp/ch1.cpp b/challenge-122/karishma/cpp/ch1.cpp new file mode 100644 index 0000000000..821e88134d --- /dev/null +++ b/challenge-122/karishma/cpp/ch1.cpp @@ -0,0 +1,17 @@ +#include <iostream> +using namespace std; + +int main() { + int n=5; + int ptr[]={10,20,30,40,50}; + int sum = 0; + for (int j = 1; j <= n; j++) { + sum += ptr[j-1]; + int k= sum/j; + cout<<k; + cout<<endl; + } + cout<<endl; + + return 0; +}
\ No newline at end of file diff --git a/challenge-122/karishma/js/ch-1.js b/challenge-122/karishma/js/ch-1.js new file mode 100644 index 0000000000..c6be964b11 --- /dev/null +++ b/challenge-122/karishma/js/ch-1.js @@ -0,0 +1,6 @@ +let input = [10,20,30,40,50]; +let sum = 0; +for (let j = 1; j <= 5; j++) { + sum += input[j-1]; + console.log(sum/j); +}
\ No newline at end of file diff --git a/challenge-122/paulo-custodio/Makefile b/challenge-122/paulo-custodio/Makefile new file mode 100644 index 0000000000..6316089eb8 --- /dev/null +++ b/challenge-122/paulo-custodio/Makefile @@ -0,0 +1,2 @@ +all: + perl ../../challenge-001/paulo-custodio/test.pl diff --git a/challenge-122/paulo-custodio/perl/ch-1.pl b/challenge-122/paulo-custodio/perl/ch-1.pl new file mode 100644 index 0000000000..ea7ea0371a --- /dev/null +++ b/challenge-122/paulo-custodio/perl/ch-1.pl @@ -0,0 +1,26 @@ +#!/usr/bin/env perl + +# TASK #1 > Average of Stream +# Submitted by: Mohammad S Anwar +# You are given a stream of numbers, @N. +# +# Write a script to print the average of the stream at every point. +# +# Example +# Input: @N = (10, 20, 30, 40, 50, 60, 70, 80, 90, ...) +# Output: 10, 15, 20, 25, 30, 35, 40, 45, 50, ... +# +# Average of first number is 10. +# Average of first 2 numbers (10+20)/2 = 15 +# Average of first 3 numbers (10+20+30)/3 = 20 +# Average of first 4 numbers (10+20+30+40)/4 = 25 and so on. + +use Modern::Perl; + +my $sum = 0; +my $count = 0; +while (<>) { + $sum += $_; + $count++; + say sprintf("%.2f", $sum/$count); +} diff --git a/challenge-122/paulo-custodio/perl/ch-2.pl b/challenge-122/paulo-custodio/perl/ch-2.pl new file mode 100644 index 0000000000..de1bfb1ee4 --- /dev/null +++ b/challenge-122/paulo-custodio/perl/ch-2.pl @@ -0,0 +1,55 @@ +#!/usr/bin/env perl + +# TASK #2 > Basketball Points +# Submitted by: Mohammad S Anwar +# You are given a score $S. +# +# You can win basketball points e.g. 1 point, 2 points and 3 points. +# +# Write a script to find out the different ways you can score $S. +# +# Example +# Input: $S = 4 +# Output: 1 1 1 1 +# 1 1 2 +# 1 2 1 +# 1 3 +# 2 1 1 +# 2 2 +# 3 1 +# +# Input: $S = 5 +# Output: 1 1 1 1 1 +# 1 1 1 2 +# 1 1 2 1 +# 1 1 3 +# 1 2 1 1 +# 1 2 2 +# 1 3 1 +# 2 1 1 1 +# 2 1 2 +# 2 2 1 +# 2 3 +# 3 1 1 +# 3 2 + +use Modern::Perl; +use List::Util 'sum'; + +my $N = shift||0; +show_scores($N); + +sub show_scores { + my($N, @points) = @_; + my $s = @points ? sum(@points) : 0; + if ($s > $N) { + } + elsif ($s == $N) { + say "@points"; + } + else { + show_scores($N, @points, 1); + show_scores($N, @points, 2); + show_scores($N, @points, 3); + } +} diff --git a/challenge-122/paulo-custodio/python/ch-1.py b/challenge-122/paulo-custodio/python/ch-1.py new file mode 100644 index 0000000000..ab54b706fa --- /dev/null +++ b/challenge-122/paulo-custodio/python/ch-1.py @@ -0,0 +1,25 @@ +#!/usr/bin/env python3 + +# TASK #1 > Average of Stream +# Submitted by: Mohammad S Anwar +# You are given a stream of numbers, @N. +# +# Write a script to print the average of the stream at every point. +# +# Example +# Input: @N = (10, 20, 30, 40, 50, 60, 70, 80, 90, ...) +# Output: 10, 15, 20, 25, 30, 35, 40, 45, 50, ... +# +# Average of first number is 10. +# Average of first 2 numbers (10+20)/2 = 15 +# Average of first 3 numbers (10+20+30)/3 = 20 +# Average of first 4 numbers (10+20+30+40)/4 = 25 and so on. + +import sys + +sum = 0 +count = 0 +for line in sys.stdin: + sum += int(line) + count += 1 + print("{:.2f}".format(sum/count)) diff --git a/challenge-122/paulo-custodio/python/ch-2.py b/challenge-122/paulo-custodio/python/ch-2.py new file mode 100644 index 0000000000..0556080767 --- /dev/null +++ b/challenge-122/paulo-custodio/python/ch-2.py @@ -0,0 +1,52 @@ +#!/usr/bin/env python3 + +# TASK #2 > Basketball Points +# Submitted by: Mohammad S Anwar +# You are given a score $S. +# +# You can win basketball points e.g. 1 point, 2 points and 3 points. +# +# Write a script to find out the different ways you can score $S. +# +# Example +# Input: $S = 4 +# Output: 1 1 1 1 +# 1 1 2 +# 1 2 1 +# 1 3 +# 2 1 1 +# 2 2 +# 3 1 +# +# Input: $S = 5 +# Output: 1 1 1 1 1 +# 1 1 1 2 +# 1 1 2 1 +# 1 1 3 +# 1 2 1 1 +# 1 2 2 +# 1 3 1 +# 2 1 1 1 +# 2 1 2 +# 2 2 1 +# 2 3 +# 3 1 1 +# 3 2 + +import sys + +def show_scores(N): + def scores(N, points): + s = sum(points) + if s > N: + pass + elif s == N: + print(" ".join([str(x) for x in points])) + else: + scores(N, [*points, 1]) + scores(N, [*points, 2]) + scores(N, [*points, 3]) + scores(N, []) + +N = int(sys.argv[1]) +show_scores(N) diff --git a/challenge-122/paulo-custodio/t/test-1.yaml b/challenge-122/paulo-custodio/t/test-1.yaml new file mode 100644 index 0000000000..e62a1cd366 --- /dev/null +++ b/challenge-122/paulo-custodio/t/test-1.yaml @@ -0,0 +1,23 @@ +- setup: + cleanup: + args: + input: | + 10 + 20 + 30 + 40 + 50 + 60 + 70 + 80 + 90 + output: | + 10.00 + 15.00 + 20.00 + 25.00 + 30.00 + 35.00 + 40.00 + 45.00 + 50.00 diff --git a/challenge-122/paulo-custodio/t/test-2.yaml b/challenge-122/paulo-custodio/t/test-2.yaml new file mode 100644 index 0000000000..df6bd41cc9 --- /dev/null +++ b/challenge-122/paulo-custodio/t/test-2.yaml @@ -0,0 +1,30 @@ +- setup: + cleanup: + args: 4 + input: + output: | + 1 1 1 1 + 1 1 2 + 1 2 1 + 1 3 + 2 1 1 + 2 2 + 3 1 +- setup: + cleanup: + args: 5 + input: + output: | + 1 1 1 1 1 + 1 1 1 2 + 1 1 2 1 + 1 1 3 + 1 2 1 1 + 1 2 2 + 1 3 1 + 2 1 1 1 + 2 1 2 + 2 2 1 + 2 3 + 3 1 1 + 3 2 |
