PWC 220
PWC 220 I switched to Raku this week. Both challenges are easier to tackle with Raku. Challenge 1 (Common characters) We are given a list of words, and asked to return a sorted list of the characters that are found in every word in the list (ignoring case). Here is the subroutine: sub common_characters( @words ) { [(&)] @words.map( {$_.lc.comb.Set} ) } For each word in @words, lowercase it, then split into characters, then store each unique character in a set . Then working on the resulting list of sets, call the reduce meta-operator [..] on the set intersection "(&)" operator, i.e., call [(&)] or "reduce using intersection" on the list of sets, to get the intersection of every set, or the characters that are found in every set. This returns a set, whose say method automatically prints the elements in sorted order (one of the task specifications). Challenge 2 (Squareful) We are given a list of integers @ints say. We are asked to identify every permu...