DEV Community

Simon Green
Simon Green

Posted on

1

Weekly Challenge 094

Challenge 094

TASK #1 › Group Anagrams

Task

You are given an array of strings @S.

Write a script to group Anagrams together in any random order

My solution

This is pretty straight forward. Read the list of words, group them into a hash with the letters ordered, and then display the values of the hash. Simples.

Examples

» ./ch-1.pl opt bat saw tab pot top was
[ ("saw", "was"),
  ("bat", "tab"),
  ("opt", "pot", "top") ]

» ./ch-1.pl x
[ ("x") ]
Enter fullscreen mode Exit fullscreen mode

TASK #2 › Binary Tree to Linked List

Task

You are given a binary tree.

Write a script to represent the given binary tree as an object and flatten it to a linked list object. Finally print the linked list object.

My solution

Okay, confession time. When doing these challenges. I have two rules. 1) Never read people's solutions before doing my own, and 2) Don't use modules that aren't part of Perl core. Perl doesn't have a native linked list implementation, and therefore I am intentionally skipping half this task to get the end result.

This task is similar to last week's second task. My code is largely copied from that. Instead of storing the paths, I add to the @digits array as I walk the path.

Example

» ./ch-2.pl < example-1.txt 
1 -> 2 -> 4 -> 5 -> 6 -> 7 -> 3
Enter fullscreen mode Exit fullscreen mode

Heroku

Built for developers, by developers.

Whether you're building a simple prototype or a business-critical product, Heroku's fully-managed platform gives you the simplest path to delivering apps quickly — using the tools and languages you already love!

Learn More

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

Explore a trove of insights in this engaging article, celebrated within our welcoming DEV Community. Developers from every background are invited to join and enhance our shared wisdom.

A genuine "thank you" can truly uplift someone’s day. Feel free to express your gratitude in the comments below!

On DEV, our collective exchange of knowledge lightens the road ahead and strengthens our community bonds. Found something valuable here? A small thank you to the author can make a big difference.

Okay