Text completion: Difference between revisions

Added Raku solution
m (Improve spacing)
(Added Raku solution)
Line 105:
 
Process finished with exit code 0
</pre>
 
=={{header|Raku}}==
(formerly Perl 6)
{{Trans|Java}}
<lang perl6>sub MAIN ( Str $user_word = 'complition', Str $filename = 'words.txt' ) {
my @s1 = $user_word.comb;
my @listed = gather for $filename.IO.lines -> $line {
my @s2 = $line.comb;
 
my $correct = 100 * sum( @s1 Zeq @s2)
/ max(+@s1, +@s2);
 
my $score = ( $correct >= 100 and @s1[0] eq @s2[0] ) ?? 100
!! ( $correct >= 80 and @s1[0] eq @s2[0] ) ?? $correct
!! ( $line.contains($user_word) and @s1 * 2 > @s2 ) ?? 80
!! 0;
take [$score, $line] if $score;
}
 
@listed = @listed[$_] with @listed.first: :k, { .[0] == 100 };
 
say "{.[0].fmt('%.2f')}% {.[1]}" for @listed;
}</lang>
{{out}}
<pre>80.00% compaction
90.00% completion
81.82% completions
80.00% complexion
</pre>
256

edits