/
ch-1.raku
57 lines (48 loc) · 1.27 KB
/
ch-1.raku
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
#!/usr/bin/env raku
=begin comment
------------------------------------------------
AUTHOR: Robert DiCicco
DATE : 2023-09-13
Challenge 234 Task 1 Common Characters ( Raku )
------------------------------------------------
=end comment
use v6;
my @wordlist = (["java", "javascript", "julia"],["bella", "label", "roller"],["cool", "lock", "cook"]);
for (@wordlist) -> @wds {
my $wordnum = @wds.elems;
my %seen = ();
my $charlist = "";
say "Input: \@words = ",@wds;
my $cnt = 0;
while $cnt < 3 {
$charlist ~= @wds[$cnt];
$cnt++;
}
my @arr = split("",$charlist);
for ( @arr) -> $c {
%seen{$c} += 1;
}
print "Output: (";
for %seen.keys -> $k {
if $k ne ' ' {
if %seen{$k} >= $wordnum && %seen{$k} < (2 * $wordnum) {
print "$k ";
} elsif %seen{$k} == (2 * $wordnum) {
print "$k $k "
}
}
}
print ")\n\n";
}
=begin comment
------------------------------------------------
SAMPLE OUTPUT
raku .\CommonCharacters.rk
Input: @words = [java javascript julia]
Output: (a j )
Input: @words = [bella label roller]
Output: (e l l )
Input: @words = [cool lock cook]
Output: (o c )
------------------------------------------------
=end comment