Groups
Groups
Sign in
Groups
Groups
scala-labs
Conversations
About
Send feedback
Help
Alternative solution for RecursionPatternMatchingExercise.zipMultiple
5 views
Skip to first unread message
Channing
unread,
Jun 21, 2011, 3:00:48 PM
6/21/11
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to scala-labs
Hi,
I think I have a smaller solution to the
RecursionPatternMatchingExercise.zipMultiple(WithDifferentSize)
exercises, at least the tests pass.
def zipMultiple(in: List[List[_]]): List[List[_]] = {
in match {
case Nil :: _ => Nil
case _ => {
val heads = in.map(_.head)
val tails = in.map(_.tail)
heads :: zipMultiple(tails)
}
}
}
def zipMultipleWithDifferentSize(in: List[List[_]]): List[List[_]] = {
val minLength = in.minBy(_.size).size
val chopped = in.map(_.take(minLength))
zipMultiple(chopped)
}
Jeroen van Erp
unread,
Jun 23, 2011, 3:45:49 AM
6/23/11
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to scala...@googlegroups.com
Hi Channing,
That also seems to do the trick indeed, smart solution!
Regards,
Jeroen
Channing Walton
unread,
Jun 23, 2011, 4:02:41 AM
6/23/11
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to scala...@googlegroups.com
well it took me an hour!! I hope to get quicker with this stuff :)
Reply all
Reply to author
Forward
0 new messages