aboutsummaryrefslogtreecommitdiff
path: root/challenge-255/dave-jacoby/perl/ch-1.pl
blob: 332918c8f41895cdf3fa0c9becbab1269b8e4cb3 (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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#!/usr/bin/env perl

use strict;
use warnings;
use experimental qw{ say postderef signatures state };

use Carp;
use List::Compare;

my @examples = (

    { s => "Perl",   t => "Preel" },
    { s => "Weekly", t => "Weeakly" },
    { s => "Box",    t => "Boxy" },
);

for my $example (@examples) {
    my $output = odd_character($example);
    my $s      = $example->{s};
    my $t      = $example->{t};

    say <<~"END";
    Input:  \$s = "$s" \$t = "$t" 
    Output: $output
    END
}

sub odd_character ($input) {
    my @s = sort split //, $input->{s};
    my @t = sort split //, $input->{t};
    say join  ', ', @s;
    say join  ', ', @t;
    return 7;
    my @output;
    while ( @s && @t ) {
        if ( $s[0] eq $t[0] ) {
            shift @s;
            shift @t;
        }
        else {
            if ( scalar @s > scalar @t ) {
                push @output, shift @s;
            }
            elsif ( scalar @s < scalar @t ) {
                push @output, shift @t;
            }
            else { croak 'Impossible Scenario' }
        }
    }
    push @output, @s if @s;
    push @output, @t if @t;
    return shift @output;
}