From 0bf4da02c3bce478dc2669fc3f6bfa035da1c3d3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ingy=20d=C3=B6t=20Net?= Date: Sat, 1 Jul 2023 19:04:33 -0400 Subject: [PATCH] Data update --- Lang/ANSI-BASIC/Dragon-curve | 1 + Lang/ARM-Assembly/K-d-tree | 1 + Lang/BASIC/Totient-function | 1 + Lang/BCPL/Totient-function | 1 + Lang/CLU/Totient-function | 1 + Lang/COBOL/Totient-function | 1 + Lang/Cowgol/Totient-function | 1 + Lang/Craft-Basic/Factorial-primes | 1 + Lang/Craft-Basic/Lucas-Lehmer-test | 1 + Lang/Craft-Basic/Prime-decomposition | 1 + Lang/Craft-Basic/Ultra-useful-primes | 1 + Lang/Draco/Totient-function | 1 + Lang/FreeBASIC/OpenWebNet-password | 1 + Lang/FutureBasic/Erd-s-Nicolas-numbers | 1 + Lang/FutureBasic/Mertens-function | 1 + Lang/Java/Babylonian-spiral | 1 + Lang/Java/Bioinformatics-Global-alignment | 1 + Lang/Kotlin/Bifid-cipher | 1 + Lang/MAD/Totient-function | 1 + Lang/Miranda/Totient-function | 1 + Lang/Modula-2/Totient-function | 1 + Lang/Oberon/Tau-number | 1 + Lang/PL-I/Totient-function | 1 + Lang/PL-M/Totient-function | 1 + Lang/Python/Ultra-useful-primes | 1 + Lang/Ruby/Achilles-numbers | 1 + Lang/Tiny-Craft-Basic/Babbage-problem | 1 + Lang/Tiny-Craft-Basic/Tau-number | 1 + Lang/XPL0/Simple-turtle-graphics | 1 + .../Zig/4-rings-or-4-squares-puzzle-2.zig | 10 +- .../Achilles-numbers/Ruby/achilles-numbers.rb | 23 + .../Craft-Basic/archimedean-spiral.basic | 4 +- .../Tiny-Craft-Basic/babbage-problem.basic | 12 + .../Java/babylonian-spiral.java | 88 +++ Task/Bifid-cipher/Kotlin/bifid-cipher.kotlin | 77 ++ .../Java/bioinformatics-global-alignment.java | 128 ++++ Task/Create-a-file/Phix/create-a-file.phix | 28 +- Task/Death-Star/Zig/death-star-8.zig | 8 +- .../Zig/department-numbers-2.zig | 6 +- .../Zig/department-numbers-4.zig | 6 +- .../ANSI-BASIC/dragon-curve.basic | 35 + .../FutureBasic/erd-s-nicolas-numbers.basic | 24 + .../Craft-Basic/euclid-mullin-sequence.basic | 12 +- .../Craft-Basic/factorial-primes.basic | 29 + Task/Here-document/Phix/here-document.phix | 64 +- Task/K-d-tree/00-TASK.txt | 1 - Task/K-d-tree/ARM-Assembly/k-d-tree.arm | 690 ++++++++++++++++++ .../Craft-Basic/lucas-lehmer-test.basic | 30 + .../EasyLang/mandelbrot-set.easy | 68 +- .../FutureBasic/mertens-function.basic | 34 + ...thmetic.math => modular-arithmetic-1.math} | 0 .../Mathematica/modular-arithmetic-2.math | 3 + Task/Nth/MiniScript/nth.mini | 6 +- .../FreeBASIC/openwebnet-password.basic | 61 ++ .../Phix/palindromic-gapful-numbers-2.phix | 2 +- .../Craft-Basic/prime-decomposition.basic | 73 ++ .../Zig/self-describing-numbers-3.zig | 2 +- .../Zig/sierpinski-triangle-1.zig | 6 +- .../Zig/sierpinski-triangle-5.zig | 4 +- .../XPL0/simple-turtle-graphics.xpl0 | 73 ++ ...ingly-linked-list-element-definition.swift | 10 +- .../J/sorting-algorithms-merge-sort-5.j | 4 +- Task/Subleq/00-TASK.txt | 12 +- Task/Tau-number/Craft-Basic/tau-number.basic | 2 - Task/Tau-number/Oberon/tau-number.oberon | 39 + .../Tiny-Craft-Basic/tau-number.basic | 32 + .../BASIC/totient-function.basic | 27 + .../BCPL/totient-function.bcpl | 31 + .../Totient-function/CLU/totient-function.clu | 50 ++ .../COBOL/totient-function.cobol | 93 +++ .../Cowgol/totient-function.cowgol | 61 ++ .../Draco/totient-function.draco | 39 + .../Totient-function/MAD/totient-function.mad | 45 ++ .../Miranda/totient-function.miranda | 25 + .../Modula-2/totient-function.mod2 | 62 ++ .../PL-I/totient-function.pli | 41 ++ .../PL-M/totient-function.plm | 66 ++ .../Totient-function/Ruby/totient-function.rb | 2 +- .../Craft-Basic/ultra-useful-primes.basic | 14 + .../Python/ultra-useful-primes.py | 15 + .../Craft-Basic/van-eck-sequence.basic | 2 - .../Vigen-re-cipher/Zig/vigen-re-cipher-3.zig | 4 +- 82 files changed, 2194 insertions(+), 118 deletions(-) create mode 120000 Lang/ANSI-BASIC/Dragon-curve create mode 120000 Lang/ARM-Assembly/K-d-tree create mode 120000 Lang/BASIC/Totient-function create mode 120000 Lang/BCPL/Totient-function create mode 120000 Lang/CLU/Totient-function create mode 120000 Lang/COBOL/Totient-function create mode 120000 Lang/Cowgol/Totient-function create mode 120000 Lang/Craft-Basic/Factorial-primes create mode 120000 Lang/Craft-Basic/Lucas-Lehmer-test create mode 120000 Lang/Craft-Basic/Prime-decomposition create mode 120000 Lang/Craft-Basic/Ultra-useful-primes create mode 120000 Lang/Draco/Totient-function create mode 120000 Lang/FreeBASIC/OpenWebNet-password create mode 120000 Lang/FutureBasic/Erd-s-Nicolas-numbers create mode 120000 Lang/FutureBasic/Mertens-function create mode 120000 Lang/Java/Babylonian-spiral create mode 120000 Lang/Java/Bioinformatics-Global-alignment create mode 120000 Lang/Kotlin/Bifid-cipher create mode 120000 Lang/MAD/Totient-function create mode 120000 Lang/Miranda/Totient-function create mode 120000 Lang/Modula-2/Totient-function create mode 120000 Lang/Oberon/Tau-number create mode 120000 Lang/PL-I/Totient-function create mode 120000 Lang/PL-M/Totient-function create mode 120000 Lang/Python/Ultra-useful-primes create mode 120000 Lang/Ruby/Achilles-numbers create mode 120000 Lang/Tiny-Craft-Basic/Babbage-problem create mode 120000 Lang/Tiny-Craft-Basic/Tau-number create mode 120000 Lang/XPL0/Simple-turtle-graphics create mode 100644 Task/Achilles-numbers/Ruby/achilles-numbers.rb create mode 100644 Task/Babbage-problem/Tiny-Craft-Basic/babbage-problem.basic create mode 100644 Task/Babylonian-spiral/Java/babylonian-spiral.java create mode 100644 Task/Bifid-cipher/Kotlin/bifid-cipher.kotlin create mode 100644 Task/Bioinformatics-Global-alignment/Java/bioinformatics-global-alignment.java create mode 100644 Task/Dragon-curve/ANSI-BASIC/dragon-curve.basic create mode 100644 Task/Erd-s-Nicolas-numbers/FutureBasic/erd-s-nicolas-numbers.basic create mode 100644 Task/Factorial-primes/Craft-Basic/factorial-primes.basic create mode 100644 Task/K-d-tree/ARM-Assembly/k-d-tree.arm create mode 100644 Task/Lucas-Lehmer-test/Craft-Basic/lucas-lehmer-test.basic create mode 100644 Task/Mertens-function/FutureBasic/mertens-function.basic rename Task/Modular-arithmetic/Mathematica/{modular-arithmetic.math => modular-arithmetic-1.math} (100%) create mode 100644 Task/Modular-arithmetic/Mathematica/modular-arithmetic-2.math create mode 100644 Task/OpenWebNet-password/FreeBASIC/openwebnet-password.basic create mode 100644 Task/Prime-decomposition/Craft-Basic/prime-decomposition.basic create mode 100644 Task/Simple-turtle-graphics/XPL0/simple-turtle-graphics.xpl0 create mode 100644 Task/Tau-number/Oberon/tau-number.oberon create mode 100644 Task/Tau-number/Tiny-Craft-Basic/tau-number.basic create mode 100644 Task/Totient-function/BASIC/totient-function.basic create mode 100644 Task/Totient-function/BCPL/totient-function.bcpl create mode 100644 Task/Totient-function/CLU/totient-function.clu create mode 100644 Task/Totient-function/COBOL/totient-function.cobol create mode 100644 Task/Totient-function/Cowgol/totient-function.cowgol create mode 100644 Task/Totient-function/Draco/totient-function.draco create mode 100644 Task/Totient-function/MAD/totient-function.mad create mode 100644 Task/Totient-function/Miranda/totient-function.miranda create mode 100644 Task/Totient-function/Modula-2/totient-function.mod2 create mode 100644 Task/Totient-function/PL-I/totient-function.pli create mode 100644 Task/Totient-function/PL-M/totient-function.plm create mode 100644 Task/Ultra-useful-primes/Craft-Basic/ultra-useful-primes.basic create mode 100644 Task/Ultra-useful-primes/Python/ultra-useful-primes.py diff --git a/Lang/ANSI-BASIC/Dragon-curve b/Lang/ANSI-BASIC/Dragon-curve new file mode 120000 index 0000000000..1650355f05 --- /dev/null +++ b/Lang/ANSI-BASIC/Dragon-curve @@ -0,0 +1 @@ +../../Task/Dragon-curve/ANSI-BASIC \ No newline at end of file diff --git a/Lang/ARM-Assembly/K-d-tree b/Lang/ARM-Assembly/K-d-tree new file mode 120000 index 0000000000..e682e1d7f3 --- /dev/null +++ b/Lang/ARM-Assembly/K-d-tree @@ -0,0 +1 @@ +../../Task/K-d-tree/ARM-Assembly \ No newline at end of file diff --git a/Lang/BASIC/Totient-function b/Lang/BASIC/Totient-function new file mode 120000 index 0000000000..fc7748e2f4 --- /dev/null +++ b/Lang/BASIC/Totient-function @@ -0,0 +1 @@ +../../Task/Totient-function/BASIC \ No newline at end of file diff --git a/Lang/BCPL/Totient-function b/Lang/BCPL/Totient-function new file mode 120000 index 0000000000..03af983992 --- /dev/null +++ b/Lang/BCPL/Totient-function @@ -0,0 +1 @@ +../../Task/Totient-function/BCPL \ No newline at end of file diff --git a/Lang/CLU/Totient-function b/Lang/CLU/Totient-function new file mode 120000 index 0000000000..75822d5b75 --- /dev/null +++ b/Lang/CLU/Totient-function @@ -0,0 +1 @@ +../../Task/Totient-function/CLU \ No newline at end of file diff --git a/Lang/COBOL/Totient-function b/Lang/COBOL/Totient-function new file mode 120000 index 0000000000..7fb7ff8b43 --- /dev/null +++ b/Lang/COBOL/Totient-function @@ -0,0 +1 @@ +../../Task/Totient-function/COBOL \ No newline at end of file diff --git a/Lang/Cowgol/Totient-function b/Lang/Cowgol/Totient-function new file mode 120000 index 0000000000..c04389da1a --- /dev/null +++ b/Lang/Cowgol/Totient-function @@ -0,0 +1 @@ +../../Task/Totient-function/Cowgol \ No newline at end of file diff --git a/Lang/Craft-Basic/Factorial-primes b/Lang/Craft-Basic/Factorial-primes new file mode 120000 index 0000000000..b9fe46064b --- /dev/null +++ b/Lang/Craft-Basic/Factorial-primes @@ -0,0 +1 @@ +../../Task/Factorial-primes/Craft-Basic \ No newline at end of file diff --git a/Lang/Craft-Basic/Lucas-Lehmer-test b/Lang/Craft-Basic/Lucas-Lehmer-test new file mode 120000 index 0000000000..68fae951b6 --- /dev/null +++ b/Lang/Craft-Basic/Lucas-Lehmer-test @@ -0,0 +1 @@ +../../Task/Lucas-Lehmer-test/Craft-Basic \ No newline at end of file diff --git a/Lang/Craft-Basic/Prime-decomposition b/Lang/Craft-Basic/Prime-decomposition new file mode 120000 index 0000000000..c28a3704bd --- /dev/null +++ b/Lang/Craft-Basic/Prime-decomposition @@ -0,0 +1 @@ +../../Task/Prime-decomposition/Craft-Basic \ No newline at end of file diff --git a/Lang/Craft-Basic/Ultra-useful-primes b/Lang/Craft-Basic/Ultra-useful-primes new file mode 120000 index 0000000000..6a976f0487 --- /dev/null +++ b/Lang/Craft-Basic/Ultra-useful-primes @@ -0,0 +1 @@ +../../Task/Ultra-useful-primes/Craft-Basic \ No newline at end of file diff --git a/Lang/Draco/Totient-function b/Lang/Draco/Totient-function new file mode 120000 index 0000000000..25a06f1db3 --- /dev/null +++ b/Lang/Draco/Totient-function @@ -0,0 +1 @@ +../../Task/Totient-function/Draco \ No newline at end of file diff --git a/Lang/FreeBASIC/OpenWebNet-password b/Lang/FreeBASIC/OpenWebNet-password new file mode 120000 index 0000000000..f52e66a57c --- /dev/null +++ b/Lang/FreeBASIC/OpenWebNet-password @@ -0,0 +1 @@ +../../Task/OpenWebNet-password/FreeBASIC \ No newline at end of file diff --git a/Lang/FutureBasic/Erd-s-Nicolas-numbers b/Lang/FutureBasic/Erd-s-Nicolas-numbers new file mode 120000 index 0000000000..fcb854e673 --- /dev/null +++ b/Lang/FutureBasic/Erd-s-Nicolas-numbers @@ -0,0 +1 @@ +../../Task/Erd-s-Nicolas-numbers/FutureBasic \ No newline at end of file diff --git a/Lang/FutureBasic/Mertens-function b/Lang/FutureBasic/Mertens-function new file mode 120000 index 0000000000..04a187ebf7 --- /dev/null +++ b/Lang/FutureBasic/Mertens-function @@ -0,0 +1 @@ +../../Task/Mertens-function/FutureBasic \ No newline at end of file diff --git a/Lang/Java/Babylonian-spiral b/Lang/Java/Babylonian-spiral new file mode 120000 index 0000000000..abc8ad8774 --- /dev/null +++ b/Lang/Java/Babylonian-spiral @@ -0,0 +1 @@ +../../Task/Babylonian-spiral/Java \ No newline at end of file diff --git a/Lang/Java/Bioinformatics-Global-alignment b/Lang/Java/Bioinformatics-Global-alignment new file mode 120000 index 0000000000..1bb0c2c75f --- /dev/null +++ b/Lang/Java/Bioinformatics-Global-alignment @@ -0,0 +1 @@ +../../Task/Bioinformatics-Global-alignment/Java \ No newline at end of file diff --git a/Lang/Kotlin/Bifid-cipher b/Lang/Kotlin/Bifid-cipher new file mode 120000 index 0000000000..46a8ba67c4 --- /dev/null +++ b/Lang/Kotlin/Bifid-cipher @@ -0,0 +1 @@ +../../Task/Bifid-cipher/Kotlin \ No newline at end of file diff --git a/Lang/MAD/Totient-function b/Lang/MAD/Totient-function new file mode 120000 index 0000000000..c0359b1414 --- /dev/null +++ b/Lang/MAD/Totient-function @@ -0,0 +1 @@ +../../Task/Totient-function/MAD \ No newline at end of file diff --git a/Lang/Miranda/Totient-function b/Lang/Miranda/Totient-function new file mode 120000 index 0000000000..ddb359f0ed --- /dev/null +++ b/Lang/Miranda/Totient-function @@ -0,0 +1 @@ +../../Task/Totient-function/Miranda \ No newline at end of file diff --git a/Lang/Modula-2/Totient-function b/Lang/Modula-2/Totient-function new file mode 120000 index 0000000000..529d07ac01 --- /dev/null +++ b/Lang/Modula-2/Totient-function @@ -0,0 +1 @@ +../../Task/Totient-function/Modula-2 \ No newline at end of file diff --git a/Lang/Oberon/Tau-number b/Lang/Oberon/Tau-number new file mode 120000 index 0000000000..aee6e48a0c --- /dev/null +++ b/Lang/Oberon/Tau-number @@ -0,0 +1 @@ +../../Task/Tau-number/Oberon \ No newline at end of file diff --git a/Lang/PL-I/Totient-function b/Lang/PL-I/Totient-function new file mode 120000 index 0000000000..f3337a0694 --- /dev/null +++ b/Lang/PL-I/Totient-function @@ -0,0 +1 @@ +../../Task/Totient-function/PL-I \ No newline at end of file diff --git a/Lang/PL-M/Totient-function b/Lang/PL-M/Totient-function new file mode 120000 index 0000000000..a0fceb4817 --- /dev/null +++ b/Lang/PL-M/Totient-function @@ -0,0 +1 @@ +../../Task/Totient-function/PL-M \ No newline at end of file diff --git a/Lang/Python/Ultra-useful-primes b/Lang/Python/Ultra-useful-primes new file mode 120000 index 0000000000..9e6b4061b0 --- /dev/null +++ b/Lang/Python/Ultra-useful-primes @@ -0,0 +1 @@ +../../Task/Ultra-useful-primes/Python \ No newline at end of file diff --git a/Lang/Ruby/Achilles-numbers b/Lang/Ruby/Achilles-numbers new file mode 120000 index 0000000000..66951b2251 --- /dev/null +++ b/Lang/Ruby/Achilles-numbers @@ -0,0 +1 @@ +../../Task/Achilles-numbers/Ruby \ No newline at end of file diff --git a/Lang/Tiny-Craft-Basic/Babbage-problem b/Lang/Tiny-Craft-Basic/Babbage-problem new file mode 120000 index 0000000000..887e8aa0f7 --- /dev/null +++ b/Lang/Tiny-Craft-Basic/Babbage-problem @@ -0,0 +1 @@ +../../Task/Babbage-problem/Tiny-Craft-Basic \ No newline at end of file diff --git a/Lang/Tiny-Craft-Basic/Tau-number b/Lang/Tiny-Craft-Basic/Tau-number new file mode 120000 index 0000000000..03f078203f --- /dev/null +++ b/Lang/Tiny-Craft-Basic/Tau-number @@ -0,0 +1 @@ +../../Task/Tau-number/Tiny-Craft-Basic \ No newline at end of file diff --git a/Lang/XPL0/Simple-turtle-graphics b/Lang/XPL0/Simple-turtle-graphics new file mode 120000 index 0000000000..fe3e8e7524 --- /dev/null +++ b/Lang/XPL0/Simple-turtle-graphics @@ -0,0 +1 @@ +../../Task/Simple-turtle-graphics/XPL0 \ No newline at end of file diff --git a/Task/4-rings-or-4-squares-puzzle/Zig/4-rings-or-4-squares-puzzle-2.zig b/Task/4-rings-or-4-squares-puzzle/Zig/4-rings-or-4-squares-puzzle-2.zig index 646cc281a4..f0ae49ed43 100644 --- a/Task/4-rings-or-4-squares-puzzle/Zig/4-rings-or-4-squares-puzzle-2.zig +++ b/Task/4-rings-or-4-squares-puzzle/Zig/4-rings-or-4-squares-puzzle-2.zig @@ -11,18 +11,18 @@ pub fn main() !void { { const nc = try getCombs(allocator, 1, 7, true); defer allocator.free(nc.combinations); - _ = try stdout.print("{d} unique solutions in 1 to 7\n", .{nc.num}); - _ = try stdout.print("{any}\n", .{nc.combinations}); + try stdout.print("{d} unique solutions in 1 to 7\n", .{nc.num}); + try stdout.print("{any}\n", .{nc.combinations}); } { const nc = try getCombs(allocator, 3, 9, true); defer allocator.free(nc.combinations); - _ = try stdout.print("{d} unique solutions in 3 to 9\n", .{nc.num}); - _ = try stdout.print("{any}\n", .{nc.combinations}); + try stdout.print("{d} unique solutions in 3 to 9\n", .{nc.num}); + try stdout.print("{any}\n", .{nc.combinations}); } { const nc = try getCombs(allocator, 0, 9, false); defer allocator.free(nc.combinations); - _ = try stdout.print("{d} non-unique solutions in 0 to 9\n", .{nc.num}); + try stdout.print("{d} non-unique solutions in 0 to 9\n", .{nc.num}); } } diff --git a/Task/Achilles-numbers/Ruby/achilles-numbers.rb b/Task/Achilles-numbers/Ruby/achilles-numbers.rb new file mode 100644 index 0000000000..f14668db87 --- /dev/null +++ b/Task/Achilles-numbers/Ruby/achilles-numbers.rb @@ -0,0 +1,23 @@ +require 'prime' + +def achilles?(n) + exponents = n.prime_division.map(&:last) + exponents.none?(1) && exponents.inject(&:gcd) == 1 +end + +def 𝜑(n) + n.prime_division.inject(1){|res, (pr, exp)| res * (pr-1) * pr**(exp-1) } +end + +achilleses = (2..).lazy.select{|n| achilles?(n) } + +n = 50 +puts "First #{n} Achilles numbers:" +achilleses.first(n).each_slice(10){|s| puts "%9d"*s.size % s} + +puts "\nFirst #{n} strong Achilles numbers:" +achilleses.select{|ach| achilles?(𝜑(ach)) }.first(n).each_slice(10){|s| puts "%9d"*s.size % s } + +puts +counts = achilleses.take_while{|ach| ach < 1000000}.map{|a| a.digits.size }.tally +counts.each{|k, v| puts "#{k} digits: #{v}" } diff --git a/Task/Archimedean-spiral/Craft-Basic/archimedean-spiral.basic b/Task/Archimedean-spiral/Craft-Basic/archimedean-spiral.basic index a98ef9fa36..03c8abf205 100644 --- a/Task/Archimedean-spiral/Craft-Basic/archimedean-spiral.basic +++ b/Task/Archimedean-spiral/Craft-Basic/archimedean-spiral.basic @@ -1,5 +1,5 @@ bgcolor 0, 0, 0 -cls +cls graphics fgcolor 255, 255, 0 define pi = 3.14, size = 80 @@ -13,5 +13,3 @@ for t = 0 to size * pi step .1 wait next t - -end diff --git a/Task/Babbage-problem/Tiny-Craft-Basic/babbage-problem.basic b/Task/Babbage-problem/Tiny-Craft-Basic/babbage-problem.basic new file mode 100644 index 0000000000..4d7374a1c5 --- /dev/null +++ b/Task/Babbage-problem/Tiny-Craft-Basic/babbage-problem.basic @@ -0,0 +1,12 @@ +10 print "calculating..." + +20 let n = 2 + +30 rem do + + 40 let n = n + 2 + +50 if (n ^ 2) % 1000000 <> 269696 then 30 + +60 print "The smallest number whose square ends in 269696 is: ", n +70 print "It's square is ", n * n diff --git a/Task/Babylonian-spiral/Java/babylonian-spiral.java b/Task/Babylonian-spiral/Java/babylonian-spiral.java new file mode 100644 index 0000000000..e1b02f0342 --- /dev/null +++ b/Task/Babylonian-spiral/Java/babylonian-spiral.java @@ -0,0 +1,88 @@ +import java.awt.Point; +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Paths; +import java.util.Comparator; +import java.util.HashSet; +import java.util.List; +import java.util.Set; +import java.util.stream.Collectors; +import java.util.stream.IntStream; +import java.util.stream.Stream; + +public final class BabylonianSpiral { + + public static void main(String[] aArgs) throws IOException { + List points = babylonianSpiral(10_000); + System.out.println("The first 40 points of the Babylonian spiral are:"); + for ( int i = 0, column = 0; i < 40; i++ ) { + System.out.print(String.format("%9s%s", + "(" + points.get(i).x + ", " + points.get(i).y + ")", ( ++column % 10 == 0 ) ? "\n" : " ")); + } + System.out.println(); + + String text = svgText(points, 800); + Files.write(Paths.get("BabylonianSpiralJava.svg"), text.getBytes()); + } + + private static List babylonianSpiral(int aStepCount) { + List squares = IntStream.rangeClosed(0, aStepCount).map( i -> i * i ).boxed().toList(); + List deltas = Stream.of( new Point(0, 0), new Point(0, 1) ).collect(Collectors.toList()); + long norm = 1; + + for ( int step = 0; step < aStepCount - 2; step++ ) { + Point previousPoint = deltas.get(deltas.size() - 1); + final double theta = Math.atan2(previousPoint.y, previousPoint.x); + Set candidates = new HashSet(); + while ( candidates.isEmpty() ) { + norm += 1; + for ( int i = 0; i < aStepCount; i++ ) { + long a = squares.get(i); + if ( a > norm / 2 ) { + break; + } + for ( int j = (int) Math.sqrt(norm) + 1; j >= 0; j-- ) { + long b = squares.get(j); + if ( a + b < norm ) { + break; + } + if ( a + b == norm ) { + candidates.addAll( + List.of( new Point(i, j), new Point(-i, j), new Point(i, -j), new Point(-i, -j), + new Point(j, i), new Point(-j, i), new Point(j, -i), new Point(-j, -i) )); + } + } + } + } + + Comparator comparatorPoint = (one, two) -> Double.compare( + ( theta - Math.atan2(one.y, one.x) + TAU ) % TAU, ( theta - Math.atan2(two.y, two.x) + TAU ) % TAU); + + Point minimum = candidates.stream().min(comparatorPoint).get(); + deltas.add(minimum); + } + + for ( int i = 0; i < deltas.size() - 1; i++ ) { + deltas.set(i + 1, new Point(deltas.get(i).x + deltas.get(i + 1).x, deltas.get(i).y + deltas.get(i + 1).y)); + } + return deltas; + } + + private static String svgText(List aPoints, int aSize) { + StringBuilder text = new StringBuilder(); + text.append("\n"); + text.append("\n"); + text.append("\n\n"); + + return text.toString(); + } + + private static final double TAU = 2 * Math.PI; + +} diff --git a/Task/Bifid-cipher/Kotlin/bifid-cipher.kotlin b/Task/Bifid-cipher/Kotlin/bifid-cipher.kotlin new file mode 100644 index 0000000000..c5d58a4398 --- /dev/null +++ b/Task/Bifid-cipher/Kotlin/bifid-cipher.kotlin @@ -0,0 +1,77 @@ +import kotlin.math.sqrt + +data class Square(private val square: String) { + private val dim: Int = + sqrt(square.length.toDouble()).toInt() + fun encode(ch: Char): Pair = + square.indexOf(ch).let { idx -> Pair(idx / dim, idx.mod(dim)) } + fun decode(pair: List): Char = + square[pair[0] * dim + pair[1]] + fun decode(row: Int, col: Int): Char = + square[row * dim + col] +} + +class Bifid(private val square: Square) { + fun encrypt(str: String): String { + fun expandAndScatter(str: String): IntArray { + val buffer = IntArray(str.length * 2) + str.forEachIndexed { i, ch -> + with(square.encode(ch)) { + buffer[i] = first + buffer[str.length + i] = second + } + } + return buffer + } + + val buffer = expandAndScatter(str) + + val characters: List = buffer.asIterable() + .windowed(size = 2, step = 2) + .map { square.decode(it) } + + return String(characters.toCharArray()) + } + + fun decrypt(str: String): String { + fun expand(str: String): IntArray { + val buffer = IntArray(str.length * 2) + for (i in buffer.indices step 2) { + with(square.encode(str[i / 2])) { + buffer[i] = first + buffer[1 + i] = second + } + } + return buffer + } + + val buffer = expand(str) + + val characters = str.toCharArray() + for (i in characters.indices) { + characters[i] = square.decode(buffer[i], buffer[characters.size + i]) + } + return String(characters) + } +} + +fun main() { + with (Bifid(Square("ABCDEFGHIKLMNOPQRSTUVWXYZ"))) { + println("\n### ABC... 5x5") + encrypt("ATTACKATDAWN").also { println("ATTACKATDAWN -> $it") } + decrypt("DQBDAXDQPDQH").also { println("DQBDAXDQPDQH -> $it") } + } + with(Bifid(Square("BGWKZQPNDSIOAXEFCLUMTHYVR"))) { + println("\n### BGW... 5x5") + encrypt("FLEEATONCE").also { println("FLEEATONCE -> $it") } + decrypt("UAEOLWRINS").also { println("UAEOLWRINS -> $it") } + + encrypt("ATTACKATDAWN").also { println("ATTACKATDAWN -> $it") } + decrypt("EYFENGIWDILA").also { println("EYFENGIWDILA -> $it") } + } + with(Bifid(Square("ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"))) { + println("\n### ABC... 6x6") + encrypt("THEINVASIONWILLSTARTONTHEFIRSTOFJANUARY").also { println("$it") } + decrypt("TBPDIPHJSPOTAIVMGPCZKNSCN09BFIHK64I7BM4").also { println("$it") } + } +} diff --git a/Task/Bioinformatics-Global-alignment/Java/bioinformatics-global-alignment.java b/Task/Bioinformatics-Global-alignment/Java/bioinformatics-global-alignment.java new file mode 100644 index 0000000000..c3f2f67f10 --- /dev/null +++ b/Task/Bioinformatics-Global-alignment/Java/bioinformatics-global-alignment.java @@ -0,0 +1,128 @@ +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.stream.Collectors; + +public final class BioinformaticsGlobalAlignment { + + public static void main(String[] aArgs) { + List> testSequences = Arrays.asList( + Arrays.asList( "TA", "AAG", "TA", "GAA", "TA" ), + Arrays.asList( "CATTAGGG", "ATTAG", "GGG", "TA" ), + Arrays.asList( "AAGAUGGA", "GGAGCGCAUC", "AUCGCAAUAAGGA" ), + Arrays.asList( "ATGAAATGGATGTTCTGAGTTGGTCAGTCCCAATGTGCGGGGTTTCTTTTAGTACGTCGGGAGTGGTATTAT", + "GGTCGATTCTGAGGACAAAGGTCAAGATGGAGCGCATCGAACGCAATAAGGATCATTTGATGGGACGTTTCGTCGACAAAGT", + "CTATGTTCTTATGAAATGGATGTTCTGAGTTGGTCAGTCCCAATGTGCGGGGTTTCTTTTAGTACGTCGGGAGTGGTATTATA", + "TGCTTTCCAATTATGTAAGCGTTCCGAGACGGGGTGGTCGATTCTGAGGACAAAGGTCAAGATGGAGCGCATC", + "AACGCAATAAGGATCATTTGATGGGACGTTTCGTCGACAAAGTCTTGTTTCGAGAGTAACGGCTACCGTCTT", + "GCGCATCGAACGCAATAAGGATCATTTGATGGGACGTTTCGTCGACAAAGTCTTGTTTCGAGAGTAACGGCTACCGTC", + "CGTTTCGTCGACAAAGTCTTGTTTCGAGAGTAACGGCTACCGTCTTCGATTCTGCTTATAACACTATGTTCT", + "TGCTTTCCAATTATGTAAGCGTTCCGAGACGGGGTGGTCGATTCTGAGGACAAAGGTCAAGATGGAGCGCATC", + "CGTAAAAAATTACAACGTCCTTTGGCTATCTCTTAAACTCCTGCTAAATGCTCGTGC", + "GATGGAGCGCATCGAACGCAATAAGGATCATTTGATGGGACGTTTCGTCGACAAAGTCTTGTTTCGAGAGTAACGGCTACCGTCTTCGATT", + "TTTCCAATTATGTAAGCGTTCCGAGACGGGGTGGTCGATTCTGAGGACAAAGGTCAAGATGGAGCGCATC", + "CTATGTTCTTATGAAATGGATGTTCTGAGTTGGTCAGTCCCAATGTGCGGGGTTTCTTTTAGTACGTCGGGAGTGGTATTATA", + "TCTCTTAAACTCCTGCTAAATGCTCGTGCTTTCCAATTATGTAAGCGTTCCGAGACGGGGTGGTCGATTCTGAGGACAAAGGTCAAGA" ) + ); + + for ( List test : testSequences ) { + for ( String superstring : shortestCommonSuperstrings(test) ) { + printReport(superstring); + } + } + } + + // Return a set containing all of the shortest common superstrings of the given list of strings. + private static Set shortestCommonSuperstrings(List aList) { + List deduplicated = deduplicate(aList); + Set shortest = new HashSet(); + shortest.add(String.join("", deduplicated)); + int shortestLength = aList.stream().mapToInt( s -> s.length() ).sum(); + + for ( List permutation : permutations(deduplicated) ) { + String candidate = permutation.stream().reduce("", (a, b) -> concatenate(a, b) ); + if ( candidate.length() < shortestLength ) { + shortest.clear(); + shortest.add(candidate); + shortestLength = candidate.length(); + } else if ( candidate.length() == shortestLength ) { + shortest.add(candidate); + } + } + return shortest; + } + + // Remove duplicate words and words which are substrings of other words in the given list. + private static List deduplicate(List aList) { + List unique = aList.stream().distinct().collect(Collectors.toList()); + List result = new ArrayList(unique); + List markedForRemoval = new ArrayList(); + for ( String testWord : result ) { + for ( String word : unique ) { + if ( ! word.equals(testWord) && word.contains(testWord) ) { + markedForRemoval.add(testWord); + } + } + } + result.removeAll(markedForRemoval); + return result; + } + + // Return aBefore concatenated with aAfter, removing the longest suffix of aBefore that matches a prefix of aAfter. + private static String concatenate(String aBefore, String aAfter) { + for ( int i = 0; i < aBefore.length(); i++ ) { + if ( aAfter.startsWith(aBefore.substring(i, aBefore.length())) ) { + return aBefore.substring(0, i) + aAfter; + } + } + return aBefore + aAfter; + } + + // Return all permutations of the given list of strings. + private static List> permutations(List aList) { + int[] indexes = new int[aList.size()]; + List> result = new ArrayList>(); + result.add( new ArrayList(aList) ); + int i = 0; + while ( i < aList.size() ) { + if ( indexes[i] < i ) { + final int j = ( i % 2 == 0 ) ? 0 : indexes[i]; + String temp = aList.get(j); + aList.set(j, aList.get(i)); + aList.set(i, temp); + result.add( new ArrayList(aList) ); + indexes[i]++; + i = 0; + } else { + indexes[i] = 0; + i++; + } + } + return result; + } + + // Print a report of the given string to the standard output device. + private static void printReport(String aText) { + char[] nucleotides = new char[] {'A', 'C', 'G', 'T' }; + Map bases = new HashMap(); + for ( char base : nucleotides ) { + bases.put(base, 0); + } + + for ( char ch : aText.toCharArray() ) { + bases.merge(ch, 1, Integer::sum); + } + final int total = bases.values().stream().reduce(0, Integer::sum); + + System.out.print("Nucleotide counts for: " + ( ( aText.length() > 50 ) ? System.lineSeparator() : "") ); + System.out.println(aText); + System.out.print(String.format("%s%d%s%d%s%d%s%d", + "Bases: A: ", bases.get('A'), ", C: ", bases.get('C'), ", G: ", bases.get('G'), ", T: ", bases.get('T'))); + System.out.println(", total: " + total + System.lineSeparator()); + } + +} diff --git a/Task/Create-a-file/Phix/create-a-file.phix b/Task/Create-a-file/Phix/create-a-file.phix index 0d807bdf49..bac008612d 100644 --- a/Task/Create-a-file/Phix/create-a-file.phix +++ b/Task/Create-a-file/Phix/create-a-file.phix @@ -1,15 +1,17 @@ -integer fn +(phixonline)--> + integer fn --- In the current working directory -system("mkdir docs",2) -fn = open("output.txt","w") -close(fn) + -- In the current working directory + system("mkdir docs",2) + fn = open("output.txt","w") + close(fn) --- In the filesystem root -system("mkdir \\docs",2) -fn = open("\\output.txt","w") -if fn=-1 then - puts(1,"unable to create \\output.txt\n") -else - close(fn) -end if + -- In the filesystem root + system("mkdir \\docs",2) + fn = open("\\output.txt","w") + if fn=-1 then + puts(1,"unable to create \\output.txt\n") + else + close(fn) + end if + + string ts1 = """ + this + "string"\thing""" -string ts2 = """this -"string"\thing""" + string ts2 = """this + "string"\thing""" -string ts3 = """ -_____________this - "string"\thing""" + string ts3 = """ + _____________this + "string"\thing""" -string ts4 = ` -this -"string"\thing` + string ts4 = ` + this + "string"\thing` -string ts5 = `this -"string"\thing` + string ts5 = `this + "string"\thing` -string ts6 = ` -_____________this - "string"\thing` + string ts6 = ` + _____________this + "string"\thing` -string ts7 = "this\n\"string\"\\thing" + string ts7 = "this\n\"string\"\\thing" -constant tests={ts1,ts2,ts3,ts4,ts5,ts6,ts7} -for i=1 to length(tests) do - for j=1 to length(tests) do - if tests[i]!=tests[j] then crash("error") end if - end for -end for -printf(1,""" -____________Everything - (all %d tests) - works - just - file.""",length(tests)) -printf(1,"""`""") -printf(1,`"""`) + constant tests={ts1,ts2,ts3,ts4,ts5,ts6,ts7} + for i=1 to length(tests) do + for j=1 to length(tests) do + if tests[i]!=tests[j] then crash("error") end if + end for + end for + printf(1,""" + ____________Everything + (all %d tests) + works + just + file.""",length(tests)) + printf(1,"""`""") + printf(1,`"""`) +