Menu

Post image 1
Post image 2
1 / 2
0

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

DEV Community·Bob Lied·19 days ago
#nmR0sw3g
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. The extra element goes into the first chunk. Example 2 Input: @list = (1,2,3,4,5,6), $n = 3 Output: ((1,2), (3,4), (5,6)) Enter fullscreen mode Exit fullscreen mode 6 / 3 = 2 remainder 0.…

Continue reading — create a free account

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

Read More