-
Notifications
You must be signed in to change notification settings - Fork 349
Expand file tree
/
Copy pathch-1.raku
More file actions
65 lines (35 loc) · 716 Bytes
/
ch-1.raku
File metadata and controls
65 lines (35 loc) · 716 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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
use v6;
# AUTHOR: Robert DiCicco
# DATE: 2022-08-29
# Challenge 180 First Unique Character ( Raku )
my %letters;
my @arr;
my $index;
my @strs = ('Long Live Perl','Perl Weekly Challenge');
for ( @strs ) -> $str {
$index = 0;
print "Input: \$s = \"$str\"\n";
mysetup($str);
myprocess();
}
sub mysetup($str) {
%letters = ();
@arr = $str.comb;
for (@arr) {
$_ = lc($_);
if ! %letters{$_} {
%letters{$_} = 1;
} else {
%letters{$_}++;
}
}
}
sub myprocess {
while $index <= @arr.end {
if (%letters{@arr[$index]} == 1) {
print("Output: $index as \"@arr[$index]\" is the first unique character\n\n");
last;
}
$index++;
}
}