DEV Community

Simon Green
Simon Green

Posted on

The Weekly Challenge 081

It's a public holiday in Queensland, so nothing better to do than smash out this week's The Weekly Challenge early.

TASK #1 › Common Base String

There probably is some CPAN module that does this, but I avoid using CPAN modules for TWC, except List::Util (which is in Perl core).

For this task, I went through a loop one letter at a time. That string can be considered a base string of both strings if the base string is repeated one or more times to match the entire string.


» ./ abcdabcd abcdabcdabcdabcd
abcd abcdabcd

» ./ aaa aa
Enter fullscreen mode Exit fullscreen mode

TASK #2 › Frequency Sort

This task was more straight forward, and can be broken into the following steps:

  1. Check the input is a file and readable.
  2. Read the file, and slurp it into a string.
  3. Remove characters to exclude.
  4. Put the words (separated by white-spaces \s+) into a frequency hash.
  5. Sort the frequencies numerical.
  6. Display the strings that match the frequency in order.


» ./ input.txt 
1 But City It Jet Juliet Latino New Romeo Side Story Their Then West York adaptation any anything at award-winning away become before begin best classic climactic coexist control dance do doesn't end ending escalates families feuding form former friend gains gangs goes happened hatred heartbreaking highway hoping in know love lovers meet meeting neither no one plan planning point romantic rumble run secret sends sister streets strikes terribly their two under understanding until violence warring what when where white whoever wins with wrong younger

2 Bernardo Jets Riff Sharks The by it led tragedy

3 Maria Tony a can of stop

4 to

9 and the
Enter fullscreen mode Exit fullscreen mode

Top comments (0)