-
Notifications
You must be signed in to change notification settings - Fork 349
Expand file tree
/
Copy pathch-1.pl
More file actions
29 lines (25 loc) · 658 Bytes
/
ch-1.pl
File metadata and controls
29 lines (25 loc) · 658 Bytes
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
#!/usr/bin/env perl
use strict;
use warnings;
use experimental qw{ say postderef signatures state };
my @inputs = ( 'Perl Weekly Challenge', 'Long Live Perl', 'AA BB CC D' );
for my $input (@inputs) {
my $i = first_uniq_char($input);
say <<END;
Input: \$s = "$input"
Output: $i
END
}
sub first_uniq_char( $string ) {
my @string = split //, $string;
OUTER: for my $i ( 0 .. -1 + scalar @string ) {
my $c = $string[$i];
for my $j ( 0 .. -1 + scalar @string ) {
next if $i == $j;
my $d = $string[$j];
next OUTER if $c eq $d;
}
return $i;
}
return -1;
}