aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMohammad S Anwar <Mohammad.Anwar@yahoo.com>2020-09-20 12:54:10 +0100
committerGitHub <noreply@github.com>2020-09-20 12:54:10 +0100
commitbae936a4696dc4314489ce6b7bac87f227f2c852 (patch)
tree10d35b59c3fc0351bf4dcc00cd4ce1813085b703
parent27dfd8aca8b802b4de1ee0527ab35c60421541bf (diff)
parent7d19e6afee0f7c1245e151ce673931ce8849f57e (diff)
downloadperlweeklychallenge-club-bae936a4696dc4314489ce6b7bac87f227f2c852.tar.gz
perlweeklychallenge-club-bae936a4696dc4314489ce6b7bac87f227f2c852.tar.bz2
perlweeklychallenge-club-bae936a4696dc4314489ce6b7bac87f227f2c852.zip
Merge pull request #2328 from ash/master
078 in C++ and Python by ash
-rw-r--r--challenge-078/ash/cpp/ch-2.cpp32
-rw-r--r--challenge-078/ash/python/ch-1.py19
-rw-r--r--challenge-078/ash/python/ch-2.py19
3 files changed, 70 insertions, 0 deletions
diff --git a/challenge-078/ash/cpp/ch-2.cpp b/challenge-078/ash/cpp/ch-2.cpp
new file mode 100644
index 0000000000..c3133a8c06
--- /dev/null
+++ b/challenge-078/ash/cpp/ch-2.cpp
@@ -0,0 +1,32 @@
+/*
+ Task 2 from
+ https://perlweeklychallenge.org/blog/perl-weekly-challenge-078/
+
+ Comments: https://andrewshitov.com/2020/09/14/the-weekly-challenge-078/
+
+ Compile:
+ $ g++ -std=c++17 ch-2.cpp
+
+ Output:
+
+ $ ./a.out
+ 40 50 10 20 30
+ 50 10 20 30 40
+*/
+
+#include <iostream>
+#include <vector>
+
+using namespace std;
+
+int main() {
+ vector<int> a = {10, 20, 30, 40, 50};
+ vector<int> b = {3, 4};
+
+ for (auto shift : b) {
+ for (auto pos = 0; pos != a.size(); pos++) {
+ cout << a[(pos + shift) % a.size()] << ' ';
+ }
+ cout << endl;
+ }
+}
diff --git a/challenge-078/ash/python/ch-1.py b/challenge-078/ash/python/ch-1.py
new file mode 100644
index 0000000000..2f6911a626
--- /dev/null
+++ b/challenge-078/ash/python/ch-1.py
@@ -0,0 +1,19 @@
+# Task 1 from
+# https://perlweeklychallenge.org/blog/perl-weekly-challenge-078/
+#
+# Comments: https://andrewshitov.com/2020/09/14/the-weekly-challenge-078/
+#
+# Output:
+#
+# $ python3 ch-1.py
+# 10
+# 7
+# 6
+# 1
+
+data = 9, 10, 7, 5, 6, 1
+
+for i in range(len(data) - 1):
+ if data[i] > max(data[i+1:]):
+ print(data[i])
+print(data[-1])
diff --git a/challenge-078/ash/python/ch-2.py b/challenge-078/ash/python/ch-2.py
new file mode 100644
index 0000000000..079e92d1b0
--- /dev/null
+++ b/challenge-078/ash/python/ch-2.py
@@ -0,0 +1,19 @@
+# Task 2 from
+# https://perlweeklychallenge.org/blog/perl-weekly-challenge-078/
+#
+# Comments: https://andrewshitov.com/2020/09/14/the-weekly-challenge-078/
+#
+# Output:
+#
+# [40, 50, 10, 20, 30]
+# [50, 10, 20, 30, 40]
+
+from collections import deque
+
+a = [10, 20, 30, 40, 50]
+b = [3, 4]
+
+for x in b:
+ d = deque(a)
+ d.rotate(-x)
+ print(list(d))