aboutsummaryrefslogtreecommitdiff
path: root/challenge-092/ash/raku/ch-1.raku
blob: 80c1e8a541209a4e48a81dfa6fed1cf8304ec41e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#!/usr/bin/env raku
#
# Task 1 from
# https://perlweeklychallenge.org/blog/perl-weekly-challenge-092/

# Comments: https://andrewshitov.com/2020/12/21/raku-challenge-week-92-issue-1/

use Test;

unit sub MAIN(Str $a, Str $b);

sub is-isomorphic($a, $b) {
    +(([==] ($a, $b)>>.chars) && ([==] ($a.comb, $b.comb, ($a.comb Z~ $b.comb))>>.unique));
}

is(is-isomorphic('abc', 'def'), 1);
is(is-isomorphic('abb', 'xyy'), 1);
is(is-isomorphic('sum', 'add'), 0);

is(is-isomorphic('ACAB', 'XCXY'), 1);
is(is-isomorphic('AAB', 'XYZ'), 0);
is(is-isomorphic('AAB', 'XXZ'), 1);

is(is-isomorphic('abc', 'abc'), 1);
is(is-isomorphic('abc', 'ab'), 0);

is(is-isomorphic('aeiou', 'bcdfg'), 1);
is(is-isomorphic('aeiou', 'gxypq'), 1);
is(is-isomorphic('aaeeiioouu', 'bbccddffgg'), 1);
is(is-isomorphic('aeaieoiuo', 'gxgyxpyqp'), 1);

is(is-isomorphic('aeiou', 'bcdtg'), 1);
is(is-isomorphic('aeiou', 'qpyxg'), 1);
is(is-isomorphic('aaeeiioouu', 'bbccdxffgg'), 0);
is(is-isomorphic('aeaieoiuo', 'gxgyxpaejrkeruqp'), 0);