From 11921311ef55ec79c9fce3edb0de53ca0a468a0e Mon Sep 17 00:00:00 2001 From: Andrew Shitov Date: Mon, 14 Sep 2020 09:46:34 +0200 Subject: ash 078 (1, 2) --- challenge-078/ash/blog.txt | 1 + challenge-078/ash/raku/ch-1.cpp | 30 ++++++++++++++++++++++++++++++ challenge-078/ash/raku/ch-1.raku | 12 ++++++++++++ challenge-078/ash/raku/ch-2.raku | 11 +++++++++++ 4 files changed, 54 insertions(+) create mode 100644 challenge-078/ash/blog.txt create mode 100644 challenge-078/ash/raku/ch-1.cpp create mode 100644 challenge-078/ash/raku/ch-1.raku create mode 100644 challenge-078/ash/raku/ch-2.raku (limited to 'challenge-078/ash') diff --git a/challenge-078/ash/blog.txt b/challenge-078/ash/blog.txt new file mode 100644 index 0000000000..0bed715d48 --- /dev/null +++ b/challenge-078/ash/blog.txt @@ -0,0 +1 @@ +https://andrewshitov.com/2020/09/14/the-weekly-challenge-078/ diff --git a/challenge-078/ash/raku/ch-1.cpp b/challenge-078/ash/raku/ch-1.cpp new file mode 100644 index 0000000000..875dc4a005 --- /dev/null +++ b/challenge-078/ash/raku/ch-1.cpp @@ -0,0 +1,30 @@ +/* + Task 1 from + https://perlweeklychallenge.org/blog/perl-weekly-challenge-078/ + + Comments: https://andrewshitov.com/2020/09/14/the-weekly-challenge-078/ + + Compile as: + $ g++ -std=c++17 ch-1.cpp +*/ + +#include +#include + +using namespace std; + +int main() { + vector a = {9, 10, 7, 5, 6, 1}; + + auto max = a.back(); + vector leaders = {max}; + for (auto i = a.rbegin(); i != a.rend(); i++) { + if (*i > max) { + max = *i; + leaders.push_back(max); + } + } + + for (auto i = leaders.rbegin(); i != leaders.rend(); i++) + cout << *i << endl; +} diff --git a/challenge-078/ash/raku/ch-1.raku b/challenge-078/ash/raku/ch-1.raku new file mode 100644 index 0000000000..d7cda4daed --- /dev/null +++ b/challenge-078/ash/raku/ch-1.raku @@ -0,0 +1,12 @@ +#!/usr/bin/env raku + +# Task 1 from +# https://perlweeklychallenge.org/blog/perl-weekly-challenge-078/ + +# Comments: https://andrewshitov.com/2020/09/14/the-weekly-challenge-078/ + +my @a = 9, 10, 7, 5, 6, 1; + +for @a.kv -> $i, $v { + say $v if $v > all(@a[$i^..*]); +} diff --git a/challenge-078/ash/raku/ch-2.raku b/challenge-078/ash/raku/ch-2.raku new file mode 100644 index 0000000000..af9f61a1e4 --- /dev/null +++ b/challenge-078/ash/raku/ch-2.raku @@ -0,0 +1,11 @@ +#!/usr/bin/env raku + +# Task 2 from +# https://perlweeklychallenge.org/blog/perl-weekly-challenge-078/ + +# Comments: https://andrewshitov.com/2020/09/14/the-weekly-challenge-078/ + +my @a = 10, 20, 30, 40, 50; +my @b = 3, 4; + +say @a.rotate($_) for @b; \ No newline at end of file -- cgit From 3e528a8fb023c20355d619bee624d261922274d4 Mon Sep 17 00:00:00 2001 From: Mohammad S Anwar Date: Mon, 14 Sep 2020 08:57:38 +0100 Subject: - Moved c++ solution to the correct folder. --- challenge-078/ash/cpp/ch-1.cpp | 30 ++++++++++++++++++++++++++++++ challenge-078/ash/raku/ch-1.cpp | 30 ------------------------------ 2 files changed, 30 insertions(+), 30 deletions(-) create mode 100644 challenge-078/ash/cpp/ch-1.cpp delete mode 100644 challenge-078/ash/raku/ch-1.cpp (limited to 'challenge-078/ash') diff --git a/challenge-078/ash/cpp/ch-1.cpp b/challenge-078/ash/cpp/ch-1.cpp new file mode 100644 index 0000000000..875dc4a005 --- /dev/null +++ b/challenge-078/ash/cpp/ch-1.cpp @@ -0,0 +1,30 @@ +/* + Task 1 from + https://perlweeklychallenge.org/blog/perl-weekly-challenge-078/ + + Comments: https://andrewshitov.com/2020/09/14/the-weekly-challenge-078/ + + Compile as: + $ g++ -std=c++17 ch-1.cpp +*/ + +#include +#include + +using namespace std; + +int main() { + vector a = {9, 10, 7, 5, 6, 1}; + + auto max = a.back(); + vector leaders = {max}; + for (auto i = a.rbegin(); i != a.rend(); i++) { + if (*i > max) { + max = *i; + leaders.push_back(max); + } + } + + for (auto i = leaders.rbegin(); i != leaders.rend(); i++) + cout << *i << endl; +} diff --git a/challenge-078/ash/raku/ch-1.cpp b/challenge-078/ash/raku/ch-1.cpp deleted file mode 100644 index 875dc4a005..0000000000 --- a/challenge-078/ash/raku/ch-1.cpp +++ /dev/null @@ -1,30 +0,0 @@ -/* - Task 1 from - https://perlweeklychallenge.org/blog/perl-weekly-challenge-078/ - - Comments: https://andrewshitov.com/2020/09/14/the-weekly-challenge-078/ - - Compile as: - $ g++ -std=c++17 ch-1.cpp -*/ - -#include -#include - -using namespace std; - -int main() { - vector a = {9, 10, 7, 5, 6, 1}; - - auto max = a.back(); - vector leaders = {max}; - for (auto i = a.rbegin(); i != a.rend(); i++) { - if (*i > max) { - max = *i; - leaders.push_back(max); - } - } - - for (auto i = leaders.rbegin(); i != leaders.rend(); i++) - cout << *i << endl; -} -- cgit From 7d19e6afee0f7c1245e151ce673931ce8849f57e Mon Sep 17 00:00:00 2001 From: Andrew Shitov Date: Sun, 20 Sep 2020 13:46:14 +0200 Subject: 078 in C++ and Python by ash --- challenge-078/ash/cpp/ch-2.cpp | 32 ++++++++++++++++++++++++++++++++ challenge-078/ash/python/ch-1.py | 19 +++++++++++++++++++ challenge-078/ash/python/ch-2.py | 19 +++++++++++++++++++ 3 files changed, 70 insertions(+) create mode 100644 challenge-078/ash/cpp/ch-2.cpp create mode 100644 challenge-078/ash/python/ch-1.py create mode 100644 challenge-078/ash/python/ch-2.py (limited to 'challenge-078/ash') 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 +#include + +using namespace std; + +int main() { + vector a = {10, 20, 30, 40, 50}; + vector 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)) -- cgit