aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--challenge-109/lubos-kolouch/perl/ch-1.pl16
-rw-r--r--challenge-109/lubos-kolouch/perl/ch-2.pl18
-rw-r--r--challenge-109/lubos-kolouch/python/ch-1.py18
-rw-r--r--challenge-109/lubos-kolouch/python/ch-2.py12
4 files changed, 64 insertions, 0 deletions
diff --git a/challenge-109/lubos-kolouch/perl/ch-1.pl b/challenge-109/lubos-kolouch/perl/ch-1.pl
new file mode 100644
index 0000000000..16d67eb7d2
--- /dev/null
+++ b/challenge-109/lubos-kolouch/perl/ch-1.pl
@@ -0,0 +1,16 @@
+sub chowla {
+ my ($n) = @_;
+ my $sum = 0;
+ for my $i (2 .. sqrt($n)) {
+ if ($n % $i == 0) {
+ $sum += $i;
+ $sum += $n/$i unless $i == $n/$i;
+ }
+ }
+ return $sum;
+}
+
+for my $n (1 .. 20) {
+ print chowla($n), "\n";
+}
+
diff --git a/challenge-109/lubos-kolouch/perl/ch-2.pl b/challenge-109/lubos-kolouch/perl/ch-2.pl
new file mode 100644
index 0000000000..f0ef66e780
--- /dev/null
+++ b/challenge-109/lubos-kolouch/perl/ch-2.pl
@@ -0,0 +1,18 @@
+use List::Util qw(sum);
+
+my @numbers = (1,2,3,4,5,6,7);
+
+for my $perm (permute(@numbers)) {
+ my ($a, $b, $c, $d, $e, $f, $g) = @$perm;
+ if (sum($a, $b) == sum($b, $c, $d) and sum($b, $c, $d) == sum($d, $e, $f) and sum($d, $e, $f) == sum($f, $g)) {
+ print "a = $a\nb = $b\nc = $c\nd = $d\ne = $e\nf = $f\ng = $g\n";
+ last;
+ }
+}
+
+sub permute {
+ my @items = @_;
+ return [] unless @items;
+ return map { [@items[$_], @$_] } 0..$#items for permute(@items[0..$_-1, $_+1..$#items]) for 0..$#items;
+}
+
diff --git a/challenge-109/lubos-kolouch/python/ch-1.py b/challenge-109/lubos-kolouch/python/ch-1.py
new file mode 100644
index 0000000000..0a72a5859e
--- /dev/null
+++ b/challenge-109/lubos-kolouch/python/ch-1.py
@@ -0,0 +1,18 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+
+import math
+
+
+def chowla(n):
+ sum = 0
+ for i in range(2, math.isqrt(n) + 1):
+ if n % i == 0:
+ sum += i
+ if i != n//i:
+ sum += n//i
+ return sum
+
+
+for n in range(1, 21):
+ print(chowla(n))
diff --git a/challenge-109/lubos-kolouch/python/ch-2.py b/challenge-109/lubos-kolouch/python/ch-2.py
new file mode 100644
index 0000000000..7e545b4499
--- /dev/null
+++ b/challenge-109/lubos-kolouch/python/ch-2.py
@@ -0,0 +1,12 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+
+from itertools import permutations
+
+numbers = [1, 2, 3, 4, 5, 6, 7]
+
+for perm in permutations(numbers):
+ a, b, c, d, e, f, g = perm
+ if sum([a, b]) == sum([b, c, d]) == sum([d, e, f]) == sum([f, g]):
+ print(f"a = {a}\nb = {b}\nc = {c}\nd = {d}\ne = {e}\nf = {f}\ng = {g}\n")
+ break