aboutsummaryrefslogtreecommitdiff
path: root/challenge-085/ash
diff options
context:
space:
mode:
authorAbigail <abigail@abigail.be>2020-11-08 19:40:05 +0100
committerAbigail <abigail@abigail.be>2020-11-08 19:40:05 +0100
commit4e34dd5d0e89307aca9f4cd3bb6072c07f942ff1 (patch)
tree52495c7853bf31c427ec26f500c66c5bed6753b4 /challenge-085/ash
parent520db2cfca438cdc9a78932e5f479e28abee150b (diff)
parentff7475c4559b1087f402725a7c526d3f780e3434 (diff)
downloadperlweeklychallenge-club-4e34dd5d0e89307aca9f4cd3bb6072c07f942ff1.tar.gz
perlweeklychallenge-club-4e34dd5d0e89307aca9f4cd3bb6072c07f942ff1.tar.bz2
perlweeklychallenge-club-4e34dd5d0e89307aca9f4cd3bb6072c07f942ff1.zip
Merge branch 'master' of https://github.com/manwar/perlweeklychallenge-club
Diffstat (limited to 'challenge-085/ash')
-rw-r--r--challenge-085/ash/blog.txt1
-rw-r--r--challenge-085/ash/cpp/ch-1.cpp40
-rw-r--r--challenge-085/ash/python/ch-1.py16
-rw-r--r--challenge-085/ash/raku/ch-1.raku7
-rw-r--r--challenge-085/ash/raku/ch-2.raku10
5 files changed, 74 insertions, 0 deletions
diff --git a/challenge-085/ash/blog.txt b/challenge-085/ash/blog.txt
new file mode 100644
index 0000000000..7d89bc0ded
--- /dev/null
+++ b/challenge-085/ash/blog.txt
@@ -0,0 +1 @@
+https://andrewshitov.com/2020/11/02/raku-challenge-week-85/
diff --git a/challenge-085/ash/cpp/ch-1.cpp b/challenge-085/ash/cpp/ch-1.cpp
new file mode 100644
index 0000000000..a3f533c450
--- /dev/null
+++ b/challenge-085/ash/cpp/ch-1.cpp
@@ -0,0 +1,40 @@
+/*
+ Task 1 from
+ https://perlweeklychallenge.org/blog/perl-weekly-challenge-085/#TASK1
+
+ $ g++ -std=c++17 ch-1.cpp
+ $ ./a.out
+ 1
+*/
+
+#include <iostream>
+#include <vector>
+
+using namespace std;
+
+int main() {
+ vector<double> r = {1.2, 0.4, 0.1, 2.5};
+ // vector<double> r = {0.2, 1.5, 0.9, 1.1};
+
+ bool found = false;
+ for (unsigned int c = 0; c != 2 << (r.size() - 1); c++) {
+ unsigned int mask = c;
+ unsigned int unit_bits = 0;
+ double sum = 0;
+ for (unsigned int bitpos = r.size(); bitpos; bitpos--) {
+ unsigned int current_bit = mask & 1;
+ unit_bits += current_bit;
+ mask >>= 1;
+
+ if (current_bit) sum += r[bitpos - 1];
+ }
+
+ if (unit_bits == 3 && sum > 1 && sum < 2) {
+ cout << 1 << endl;
+ found = true;
+ break;
+ }
+ }
+
+ if (!found) cout << 0 << endl;
+}
diff --git a/challenge-085/ash/python/ch-1.py b/challenge-085/ash/python/ch-1.py
new file mode 100644
index 0000000000..008c3b951d
--- /dev/null
+++ b/challenge-085/ash/python/ch-1.py
@@ -0,0 +1,16 @@
+#!/usr/bin/env python3
+#
+# Task 1 from
+# https://perlweeklychallenge.org/blog/perl-weekly-challenge-085/#TASK1
+
+from itertools import combinations
+
+r = [1.2, 0.4, 0.1, 2.5]
+# r = [0.2, 1.5, 0.9, 1.1]
+
+for row in combinations(r, 3):
+ if 1 < sum(row) < 2:
+ print(1)
+ break
+else:
+ print(0)
diff --git a/challenge-085/ash/raku/ch-1.raku b/challenge-085/ash/raku/ch-1.raku
new file mode 100644
index 0000000000..c792d8ef13
--- /dev/null
+++ b/challenge-085/ash/raku/ch-1.raku
@@ -0,0 +1,7 @@
+#!/usr/bin/env raku
+#
+# Task 1 from
+# https://perlweeklychallenge.org/blog/perl-weekly-challenge-085/
+
+my @r = 1.2, 0.4, 0.1, 2.5;
+say +so 1 < any(@r.combinations(3)>>.sum) < 2;
diff --git a/challenge-085/ash/raku/ch-2.raku b/challenge-085/ash/raku/ch-2.raku
new file mode 100644
index 0000000000..e18abbd7ce
--- /dev/null
+++ b/challenge-085/ash/raku/ch-2.raku
@@ -0,0 +1,10 @@
+#!/usr/bin/env raku
+#
+# Task 2 from
+# https://perlweeklychallenge.org/blog/perl-weekly-challenge-085/
+
+my $N = @*ARGS[0] // 8;
+
+for 1..^$N X ^$N -> ($a, $b) {
+ say "$N = $a^$b" if $N == $a ** $b;
+}