diff options
| author | Frank Oosterhuis <frank.oosterhuis@getthere.nl> | 2020-10-09 15:15:41 +0200 |
|---|---|---|
| committer | Frank Oosterhuis <frank.oosterhuis@getthere.nl> | 2020-10-09 15:15:41 +0200 |
| commit | 57a96cc9711fbab23187d8b1d10a1ad55a030d3e (patch) | |
| tree | 06431ab616a10b4e5764cdf000bf55d181961516 | |
| parent | de6bd836702f7165f9a03ba643c94b8a6f84f3f1 (diff) | |
| download | perlweeklychallenge-club-57a96cc9711fbab23187d8b1d10a1ad55a030d3e.tar.gz perlweeklychallenge-club-57a96cc9711fbab23187d8b1d10a1ad55a030d3e.tar.bz2 perlweeklychallenge-club-57a96cc9711fbab23187d8b1d10a1ad55a030d3e.zip | |
WordCount
| -rw-r--r-- | challenge-081/frankivo/README | 1 | ||||
| -rw-r--r-- | challenge-081/frankivo/scala/WestSideStory.txt | 3 | ||||
| -rw-r--r-- | challenge-081/frankivo/scala/WordCount.scala | 22 |
3 files changed, 26 insertions, 0 deletions
diff --git a/challenge-081/frankivo/README b/challenge-081/frankivo/README new file mode 100644 index 0000000000..681b15b36c --- /dev/null +++ b/challenge-081/frankivo/README @@ -0,0 +1 @@ +Solution by Frank Oosterhuis. diff --git a/challenge-081/frankivo/scala/WestSideStory.txt b/challenge-081/frankivo/scala/WestSideStory.txt new file mode 100644 index 0000000000..7c77fa54a9 --- /dev/null +++ b/challenge-081/frankivo/scala/WestSideStory.txt @@ -0,0 +1,3 @@ +West Side Story
+
+The award-winning adaptation of the classic romantic tragedy "Romeo and Juliet". The feuding families become two warring New York City gangs, the white Jets led by Riff and the Latino Sharks, led by Bernardo. Their hatred escalates to a point where neither can coexist with any form of understanding. But when Riff's best friend (and former Jet) Tony and Bernardo's younger sister Maria meet at a dance, no one can do anything to stop their love. Maria and Tony begin meeting in secret, planning to run away. Then the Sharks and Jets plan a rumble under the highway--whoever wins gains control of the streets. Maria sends Tony to stop it, hoping it can end the violence. It goes terribly wrong, and before the lovers know what's happened, tragedy strikes and doesn't stop until the climactic and heartbreaking ending.
\ No newline at end of file diff --git a/challenge-081/frankivo/scala/WordCount.scala b/challenge-081/frankivo/scala/WordCount.scala new file mode 100644 index 0000000000..c9917146d4 --- /dev/null +++ b/challenge-081/frankivo/scala/WordCount.scala @@ -0,0 +1,22 @@ +object WordCount {
+
+ def main(args: Array[String]): Unit = {
+ println(getCounts("WestSideStory.txt"))
+ }
+
+ def getCounts(filename: String): String = {
+ scala.io.Source.fromFile(filename)
+ .getLines
+ .mkString(" ")
+ .replaceAll("(\\.|\"|\\(|\\)|,|'s|--)", "")
+ .split(" ")
+ .filter(_.length > 0)
+ .groupMapReduce(identity)(_ => 1)(_ + _)
+ .groupBy(c => c._2)
+ .map(x => (x._1, x._2.keys))
+ .toList
+ .sortBy(_._1)
+ .map(x => s"${x._1} ${x._2.mkString(" ")}")
+ .mkString("\n\n")
+ }
+}
\ No newline at end of file |
