aboutsummaryrefslogtreecommitdiff
path: root/challenge-285
diff options
context:
space:
mode:
authorJörg Sommrey <28217714+jo-37@users.noreply.github.com>2024-09-06 20:21:32 +0200
committerJörg Sommrey <28217714+jo-37@users.noreply.github.com>2024-09-06 20:27:09 +0200
commitdca33381b049b1a7fa550d08b67cd08e5e4a1ccb (patch)
treeb7c41869ca7313830576986517de96d6108d7466 /challenge-285
parent0c9d8d680098f5515616488eceedbcfae8c5fea7 (diff)
downloadperlweeklychallenge-club-dca33381b049b1a7fa550d08b67cd08e5e4a1ccb.tar.gz
perlweeklychallenge-club-dca33381b049b1a7fa550d08b67cd08e5e4a1ccb.tar.bz2
perlweeklychallenge-club-dca33381b049b1a7fa550d08b67cd08e5e4a1ccb.zip
Solution to task 1
Diffstat (limited to 'challenge-285')
-rwxr-xr-xchallenge-285/jo-37/perl/ch-1.pl62
1 files changed, 62 insertions, 0 deletions
diff --git a/challenge-285/jo-37/perl/ch-1.pl b/challenge-285/jo-37/perl/ch-1.pl
new file mode 100755
index 0000000000..9a7d0620f4
--- /dev/null
+++ b/challenge-285/jo-37/perl/ch-1.pl
@@ -0,0 +1,62 @@
+#!/usr/bin/perl -s
+
+use v5.24;
+use Test2::V0;
+use Graph::Directed;
+
+our ($tests, $examples);
+
+run_tests() if $tests || $examples; # does not return
+
+die <<EOS unless @ARGV;
+usage: $0 [-examples] [-tests] [ROUTE...]
+
+-examples
+ run the examples from the challenge
+
+-tests
+ run some tests
+
+ROUTE...
+ routes given as origin-destination, e.g A-B
+
+EOS
+
+
+### Input and Output
+
+say for no_connection(map [split qr/-/, $_], @ARGV);
+
+
+### Implementation
+#
+# For details see:
+# https://github.sommrey.de/the-bears-den/2024/09/06/ch-285.html#task-1
+
+
+sub no_connection {
+ Graph::Directed->new(edges => \@_)->sink_vertices;
+}
+
+
+### Examples and tests
+
+sub run_tests {
+ SKIP: {
+ skip "examples" unless $examples;
+
+ is [no_connection(["B","C"], ["D","B"], ["C","A"])], ["A"],
+ "example 1";
+ is [no_connection(["A","Z"])], ["Z"],
+ "example 2";
+ }
+
+ SKIP: {
+ skip "tests" unless $tests;
+
+ is [no_connection(["A", "B"], ["B", "C"], ["C", "A"])], [], 'cycle';
+ }
+
+ done_testing;
+ exit;
+}