aboutsummaryrefslogtreecommitdiff
path: root/challenge-081/arne-sommer/raku/common-base-string
blob: b99af78b6ebe08a16b4fe9f06ebd4bc64e7fbf1b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#! /usr/bin/env raku

unit sub MAIN (Str $A where $A.chars > 0, Str $B where $B.chars > 0, :v(:$verbose));

die "Different characters in A and B"
  unless $A.comb.unique.sort.join eq $B.comb.unique.sort.join;

my $a = $A.chars;
my $b = $B.chars;

my $unique = $A.comb.unique.elems;

my @cbs;

for $unique .. min($a, $b) -> $length
{
  my $c = $A.substr(0, $length);
  say ": Length: $length -> $c" if $verbose;

  @cbs.push: $c if $c x ($a / $length) eq $A && $c x ($b / $length) eq $B;
}

say '(' ~ @cbs.map({ '"' ~ $_ ~ '"' }).join(", ") ~ ')' if @cbs;