Rafraîchissoir

By Shahed Nooshmand

Perl Weekly Challenge: week 62

Task #1

Write a script that takes a list of email addresses (one per line) and sorts them first by the domain part of the email address, and then by the part to the left of the @ (known as the mailbox).

Note that the domain is case-insensitive, while the mailbox part is case sensitive. (Some email providers choose to ignore case, but that’s another matter entirely.)

Here’s a one-liner:

raku -e '.key.put for <name@example.org rjt@cpan.org Name@example.org rjt@CPAN.org user@alpha.example.org>.map({/(.+) "@" (.+)/; $_ => [$1.fc, ~$0]}).sort(*.value)'

Straightforward, isn’t it?

Task #2

Your job is to write a script to work with a three dimensional chess cube, M×M×M in size, and find a solution that maximizes the number of queens that can be placed in that cube without attacking each other. Output one possible solution.

Unfortunately, I couldn’t do this in one line. You can see the rather long solution, however, on GitHub.