Menu

1 / 2

PWC 373 Task 2: Let's Dance to List Division

DEV Community·Bob Lied·6 months ago
#nmR0sw3g
#example#perl#perlweeklychallenge#pwc#list
Reading 0:00
15s threshold

The task title reminded me of the song Let's Dance to Joy Division . Oddly applicable lyrics for a blog about programming: "But I worked something out last night that changed this little boy's brain, a small piece of advice that took 22 years in the make, and I will break it for you now. Please learn from my mistakes." And who doesn't love a wombat?

Task Description

You are given a list and a non-negative integer, $n . Write a script to divide the given list into $n equal parts. Return -1 if $n is more than the size of the list.

Example 1

Input: @list = ( 1,2,3,4,5), $n = 2 Output: ((1,2,3), (4,5))

Enter fullscreen mode

Exit fullscreen mode

5 / 2 = 2 remainder 1.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.