From 2bd5f0594278a6086492879b9ff1582e677ca817 Mon Sep 17 00:00:00 2001 From: Kang-min Liu Date: Wed, 7 Oct 2020 00:05:30 +0900 Subject: a naive solution of task 080.1 --- challenge-081/gugod/raku/ch-1.raku | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 challenge-081/gugod/raku/ch-1.raku (limited to 'challenge-081') diff --git a/challenge-081/gugod/raku/ch-1.raku b/challenge-081/gugod/raku/ch-1.raku new file mode 100644 index 0000000000..b84d053ef5 --- /dev/null +++ b/challenge-081/gugod/raku/ch-1.raku @@ -0,0 +1,20 @@ +#!/usr/bin/env raku + +# raku challenge-081/gugod/raku/ch-1.raku abcdabcd abcdabcdabcdabcd +# (abcd abcdabcd) + +sub MAIN (Str $A, Str $B) { + say common-base-string($A, $B); +} + +sub common-base-string (Str $A, Str $B) { + return ( base-string($A) ∩ base-string($B) ).keys; +} + +sub base-string (Str $s) { + return (1..$s.chars).grep( + -> $n { + ($s.chars mod $n == 0) + && ($s.substr(0,$n) x ($s.chars div $n)) eq $s + }).map(-> $n { $s.substr(0,$n) }); +} -- cgit From 2a7f54ab092f795e9e88613f6e48b4d794a8c99d Mon Sep 17 00:00:00 2001 From: Julio Date: Tue, 6 Oct 2020 17:44:56 +0200 Subject: Add solution for week 81 --- challenge-081/juliodcs/perl/ch-1.pl | 6 ++++++ challenge-081/juliodcs/perl/ch-2.pl | 19 +++++++++++++++++++ challenge-081/juliodcs/perl/input | 3 +++ challenge-081/juliodcs/raku/ch-1.raku | 3 +++ challenge-081/juliodcs/raku/ch-2.raku | 15 +++++++++++++++ challenge-081/juliodcs/raku/input | 3 +++ 6 files changed, 49 insertions(+) create mode 100644 challenge-081/juliodcs/perl/ch-1.pl create mode 100644 challenge-081/juliodcs/perl/ch-2.pl create mode 100644 challenge-081/juliodcs/perl/input create mode 100644 challenge-081/juliodcs/raku/ch-1.raku create mode 100644 challenge-081/juliodcs/raku/ch-2.raku create mode 100644 challenge-081/juliodcs/raku/input (limited to 'challenge-081') diff --git a/challenge-081/juliodcs/perl/ch-1.pl b/challenge-081/juliodcs/perl/ch-1.pl new file mode 100644 index 0000000000..199408a21f --- /dev/null +++ b/challenge-081/juliodcs/perl/ch-1.pl @@ -0,0 +1,6 @@ +use strict; +use warnings; +use feature 'say'; +use List::MoreUtils 'uniq'; + +say for uniq map { /^(.+)\1+$/; $1 // () } @ARGV; diff --git a/challenge-081/juliodcs/perl/ch-2.pl b/challenge-081/juliodcs/perl/ch-2.pl new file mode 100644 index 0000000000..92b58fe97b --- /dev/null +++ b/challenge-081/juliodcs/perl/ch-2.pl @@ -0,0 +1,19 @@ +use strict; +use warnings; +use File::Slurp; +use List::AllUtils qw(reduce uniq); +use Const::Fast; +use experimental 'signatures'; + +const my $rx_words => qr/ + (?-\p{L}+)* # Match dash-separated words + (?>'(?!s\b)\p{L}+)? # It may end with 「'」 + word (except for 「's」) +/ix; +const my @words => read_file('input') =~ m/$rx_words/g; +const my %scores => %{ +reduce { $a->{$b}++; $a } {}, @words }; +const my $add => sub($h, $w) { push $h->{$scores{$w}}->@*, $w; $h }; +const my %inverse => %{ +reduce { $add->($a, $b) } {}, keys %scores }; + +printf "$_ %s\n\n", join q( ), sort @{$inverse{$_}} for sort keys %inverse; diff --git a/challenge-081/juliodcs/perl/input b/challenge-081/juliodcs/perl/input new file mode 100644 index 0000000000..7c77fa54a9 --- /dev/null +++ b/challenge-081/juliodcs/perl/input @@ -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/juliodcs/raku/ch-1.raku b/challenge-081/juliodcs/raku/ch-1.raku new file mode 100644 index 0000000000..6ee984714b --- /dev/null +++ b/challenge-081/juliodcs/raku/ch-1.raku @@ -0,0 +1,3 @@ +use v6.d; + +say @*ARGS.map({ /^ (.+) $0+ $/; $0 }).grep(so *).map(~*).unique; diff --git a/challenge-081/juliodcs/raku/ch-2.raku b/challenge-081/juliodcs/raku/ch-2.raku new file mode 100644 index 0000000000..c7e103f4ee --- /dev/null +++ b/challenge-081/juliodcs/raku/ch-2.raku @@ -0,0 +1,15 @@ +use v6.d; + +my $regex := rx/ :r # Don't backtrack + 「'」> # Don't match if preceded by word + 「'」 + # (avoids matching 「s」 in 「word's」) + <:L>+ [「-」<:L>+]* # Match dash-separated words + [「'」><:L>+]? # It may end with 「'」 + word (except for 「's」) +/; + +my @words := ('input'.IO.slurp ~~ m:g/$regex/)>>.Str; +my %score := ({}, |@words).reduce: { %^score{$^word}++; %^score } +my $add := { %^data{$^pair.value}.push: $^pair.key; %^data } +my %data := ({}, |%score.pairs).reduce: $add; + +printf "%s %s\n\n", .key, .value.sort.join: 「 」 for sort %data.pairs; diff --git a/challenge-081/juliodcs/raku/input b/challenge-081/juliodcs/raku/input new file mode 100644 index 0000000000..7c77fa54a9 --- /dev/null +++ b/challenge-081/juliodcs/raku/input @@ -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 -- cgit From bafce2336b7462f722bdbe728674273417e30fff Mon Sep 17 00:00:00 2001 From: Tyler Wardhaugh Date: Tue, 6 Oct 2020 08:56:50 -0700 Subject: Ch81: prepare files for new challenge --- challenge-081/tyler-wardhaugh/clojure/README.md | 16 ++++++---------- challenge-081/tyler-wardhaugh/clojure/deps.edn | 7 +++---- challenge-081/tyler-wardhaugh/clojure/pom.xml | 14 +++++++------- 3 files changed, 16 insertions(+), 21 deletions(-) (limited to 'challenge-081') diff --git a/challenge-081/tyler-wardhaugh/clojure/README.md b/challenge-081/tyler-wardhaugh/clojure/README.md index 27344ef9cb..3a0c44fe10 100644 --- a/challenge-081/tyler-wardhaugh/clojure/README.md +++ b/challenge-081/tyler-wardhaugh/clojure/README.md @@ -1,29 +1,25 @@ -# tw.weekly.c80 +# tw.weekly.c81 -The Weekly Challenge - #080 - Tyler Wardhaugh +The Weekly Challenge - #081 - Tyler Wardhaugh ## Usage Run the project directly (shows default output from both tasks): - $ clojure -m tw.weekly.c80.core + $ clojure -M -m tw.weekly.c81.core Run the project's tests (which are samples from the task descriptions): - $ clojure -A:test:runner + $ clojure -M:test:runner Run Task #1 with input - $ clojure -m tw.weekly.c80.t1 A1 A2 A3 [...] - -Benchmark both methods defined in Task #1: - - $ clojure -m tw.weekly.c80.t1-bench + $ clojure -M -m tw.weekly.c81.t1 A B Run Task #2 with input: - $ clojure -m tw.weekly.c80.t2 A1 A2 A3 [...] + $ clojure -M -m tw.weekly.c81.t2 INPUT-FILE ## Project Template diff --git a/challenge-081/tyler-wardhaugh/clojure/deps.edn b/challenge-081/tyler-wardhaugh/clojure/deps.edn index c572dcdfc7..d74986e08e 100644 --- a/challenge-081/tyler-wardhaugh/clojure/deps.edn +++ b/challenge-081/tyler-wardhaugh/clojure/deps.edn @@ -1,6 +1,5 @@ {:paths ["src" "resources"] - :deps {org.clojure/clojure {:mvn/version "1.10.1"} - criterium/criterium {:mvn/version "0.4.6"}} + :deps {org.clojure/clojure {:mvn/version "1.10.1"}} :aliases {:test {:extra-paths ["test"] :extra-deps {org.clojure/test.check {:mvn/version "1.0.0"}}} @@ -11,5 +10,5 @@ :main-opts ["-m" "cognitect.test-runner" "-d" "test"]} :uberjar {:extra-deps {seancorfield/depstar {:mvn/version "1.0.94"}} - :main-opts ["-m" "hf.depstar.uberjar" "tw.weekly.c80.jar" - "-C" "-m" "tw.weekly.c80"]}}} + :main-opts ["-m" "hf.depstar.uberjar" "tw.weekly.c81.jar" + "-C" "-m" "tw.weekly.c81"]}}} diff --git a/challenge-081/tyler-wardhaugh/clojure/pom.xml b/challenge-081/tyler-wardhaugh/clojure/pom.xml index 525b004ca8..20a672bad9 100644 --- a/challenge-081/tyler-wardhaugh/clojure/pom.xml +++ b/challenge-081/tyler-wardhaugh/clojure/pom.xml @@ -2,11 +2,11 @@ 4.0.0 tw.weekly - tw.weekly.c80 + tw.weekly.c81 0.1.0-SNAPSHOT - tw.weekly.c80 - Challenge #080 - https://github.com/tw.weekly/tw.weekly.c80 + tw.weekly.c81 + Challenge #081 + https://github.com/tw.weekly/tw.weekly.c81 Eclipse Public License @@ -19,9 +19,9 @@ - https://github.com/tw.weekly/tw.weekly.c80 - scm:git:git://github.com/tw.weekly/tw.weekly.c80.git - scm:git:ssh://git@github.com/tw.weekly/tw.weekly.c80.git + https://github.com/tw.weekly/tw.weekly.c81 + scm:git:git://github.com/tw.weekly/tw.weekly.c81.git + scm:git:ssh://git@github.com/tw.weekly/tw.weekly.c81.git HEAD -- cgit From 952dfbc2740e2cd1d13dd22c3367c4f9bb11acfc Mon Sep 17 00:00:00 2001 From: Tyler Wardhaugh Date: Tue, 6 Oct 2020 08:56:51 -0700 Subject: Ch81: Task 1 --- .../clojure/src/tw/weekly/c81/core.clj | 9 ++++++++ .../clojure/src/tw/weekly/c81/t1.clj | 25 ++++++++++++++++++++++ .../clojure/test/tw/weekly/c81_test.clj | 8 +++++++ 3 files changed, 42 insertions(+) create mode 100644 challenge-081/tyler-wardhaugh/clojure/src/tw/weekly/c81/core.clj create mode 100644 challenge-081/tyler-wardhaugh/clojure/src/tw/weekly/c81/t1.clj create mode 100644 challenge-081/tyler-wardhaugh/clojure/test/tw/weekly/c81_test.clj (limited to 'challenge-081') diff --git a/challenge-081/tyler-wardhaugh/clojure/src/tw/weekly/c81/core.clj b/challenge-081/tyler-wardhaugh/clojure/src/tw/weekly/c81/core.clj new file mode 100644 index 0000000000..a0973e56a1 --- /dev/null +++ b/challenge-081/tyler-wardhaugh/clojure/src/tw/weekly/c81/core.clj @@ -0,0 +1,9 @@ +(ns tw.weekly.c81.core + (:require [tw.weekly.c81.t1 :as t1]) + (:gen-class)) + +(defn -main + "Run all tasks" + [& _] + (println "Task #1") + (t1/-main)) diff --git a/challenge-081/tyler-wardhaugh/clojure/src/tw/weekly/c81/t1.clj b/challenge-081/tyler-wardhaugh/clojure/src/tw/weekly/c81/t1.clj new file mode 100644 index 0000000000..13a382f7c6 --- /dev/null +++ b/challenge-081/tyler-wardhaugh/clojure/src/tw/weekly/c81/t1.clj @@ -0,0 +1,25 @@ +(ns tw.weekly.c81.t1) + +;;; Task description for TASK #1 › Common Base String +; You are given 2 strings, $A and $B. +; +; Write a script to find out common base strings in $A and $B. +; +; >>> A substring of a string $S is called base string if repeated concatenation of the substring results in the string.; +;;; + +(defn common-base-string + "Find the common base string of two strings." + [s1 s2] + (let [[[_ small] [large-len large]] (->> [s1 s2] (map (juxt count identity)) sort) + is-substring (fn [s] (= large (reduce str (-> (quot large-len (count s)) (repeat s)))))] + (->> (reductions str "" small) + (drop 1) + (filter is-substring)))) + +(defn -main + "Run Task 1 with two strings A and B, defaulting to the first example given in the task description." + [& args] + (let [[A B] (or (some->> args (take 2)) ["abcdabcd" "abcdabcdabcdabcd"]) + base (common-base-string A B)] + (println base))) diff --git a/challenge-081/tyler-wardhaugh/clojure/test/tw/weekly/c81_test.clj b/challenge-081/tyler-wardhaugh/clojure/test/tw/weekly/c81_test.clj new file mode 100644 index 0000000000..a9f3889aa1 --- /dev/null +++ b/challenge-081/tyler-wardhaugh/clojure/test/tw/weekly/c81_test.clj @@ -0,0 +1,8 @@ +(ns tw.weekly.c81-test + (:require [clojure.test :refer [deftest is testing]] + [tw.weekly.c81.t1 :refer [common-base-string]])) + +(deftest task-1 + (testing "Task 1, Common Base String" + (is (= (common-base-string "abcdabcd" "abcdabcdabcdabcd") ["abcd" "abcdabcd"])) + (is (= (common-base-string "aaa" "aa") ["a"])))) -- cgit From 01d318f579ad3fdae1b796d57e83daccbe2c4198 Mon Sep 17 00:00:00 2001 From: Tyler Wardhaugh Date: Tue, 6 Oct 2020 08:56:51 -0700 Subject: Ch81: Task 2 --- challenge-081/tyler-wardhaugh/clojure/deps.edn | 3 +- challenge-081/tyler-wardhaugh/clojure/pom.xml | 5 ++++ .../tyler-wardhaugh/clojure/resources/input | 3 ++ .../clojure/src/tw/weekly/c81/core.clj | 5 +++- .../clojure/src/tw/weekly/c81/t2.clj | 32 ++++++++++++++++++++++ .../clojure/test/tw/weekly/c81_test.clj | 15 +++++++++- 6 files changed, 60 insertions(+), 3 deletions(-) create mode 100644 challenge-081/tyler-wardhaugh/clojure/resources/input create mode 100644 challenge-081/tyler-wardhaugh/clojure/src/tw/weekly/c81/t2.clj (limited to 'challenge-081') diff --git a/challenge-081/tyler-wardhaugh/clojure/deps.edn b/challenge-081/tyler-wardhaugh/clojure/deps.edn index d74986e08e..8bbe260e55 100644 --- a/challenge-081/tyler-wardhaugh/clojure/deps.edn +++ b/challenge-081/tyler-wardhaugh/clojure/deps.edn @@ -1,5 +1,6 @@ {:paths ["src" "resources"] - :deps {org.clojure/clojure {:mvn/version "1.10.1"}} + :deps {org.clojure/clojure {:mvn/version "1.10.1"} + net.cgrand/xforms {:mvn/version "0.19.2"}} :aliases {:test {:extra-paths ["test"] :extra-deps {org.clojure/test.check {:mvn/version "1.0.0"}}} diff --git a/challenge-081/tyler-wardhaugh/clojure/pom.xml b/challenge-081/tyler-wardhaugh/clojure/pom.xml index 20a672bad9..a997eb3a20 100644 --- a/challenge-081/tyler-wardhaugh/clojure/pom.xml +++ b/challenge-081/tyler-wardhaugh/clojure/pom.xml @@ -30,6 +30,11 @@ clojure 1.10.1 + + net.cgrand + xforms + 0.19.2 + src diff --git a/challenge-081/tyler-wardhaugh/clojure/resources/input b/challenge-081/tyler-wardhaugh/clojure/resources/input new file mode 100644 index 0000000000..37001629ad --- /dev/null +++ b/challenge-081/tyler-wardhaugh/clojure/resources/input @@ -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. diff --git a/challenge-081/tyler-wardhaugh/clojure/src/tw/weekly/c81/core.clj b/challenge-081/tyler-wardhaugh/clojure/src/tw/weekly/c81/core.clj index a0973e56a1..146c6bd5fd 100644 --- a/challenge-081/tyler-wardhaugh/clojure/src/tw/weekly/c81/core.clj +++ b/challenge-081/tyler-wardhaugh/clojure/src/tw/weekly/c81/core.clj @@ -1,9 +1,12 @@ (ns tw.weekly.c81.core (:require [tw.weekly.c81.t1 :as t1]) + (:require [tw.weekly.c81.t2 :as t2]) (:gen-class)) (defn -main "Run all tasks" [& _] (println "Task #1") - (t1/-main)) + (t1/-main) + (println "Task #2") + (t2/-main)) diff --git a/challenge-081/tyler-wardhaugh/clojure/src/tw/weekly/c81/t2.clj b/challenge-081/tyler-wardhaugh/clojure/src/tw/weekly/c81/t2.clj new file mode 100644 index 0000000000..543a1f54b6 --- /dev/null +++ b/challenge-081/tyler-wardhaugh/clojure/src/tw/weekly/c81/t2.clj @@ -0,0 +1,32 @@ +(ns tw.weekly.c81.t2 + (:require [clojure.java.io :as io]) + (:require [clojure.pprint :refer [cl-format]]) + (:require [clojure.string :as str]) + (:require [net.cgrand.xforms :as x]) + (:require [net.cgrand.xforms.io :as xio])) + +;;; Task description for TASK #2 › Frequency Sort +; You are given file named input. +; +; Write a script to find the frequency of all the words. +; +; It should print the result as first column of each line should be the frequency of the the word followed by all the words of that frequency arranged in lexicographical order. Also sort the words in the ascending order of frequency. +;;; + +(defn word-frequency-sort + "Return a sorted word frequency map for a given text." + [source] + (let [cleaner (fn [s] (str/replace s #"(?:[.\"\(\),]|'s|--|\n)" " ")) + splitter (fn [s] (str/split s #" ")) + xf (comp (mapcat (comp splitter cleaner)) + (remove #{""}) + (x/by-key identity (x/into [])) + (x/by-key (comp count second) first (x/into (sorted-set))))] + (into (sorted-map) xf source))) + +(defn -main + "Run Task 2 with an input, defaulting to the example given in the task description." + [& args] + (let [input (or (some->> args first io/file) (io/resource "input")) + freqs (word-frequency-sort (xio/lines-in input))] + (cl-format true "~:{~a ~{~a~^ ~}~%~^~%~}" freqs))) diff --git a/challenge-081/tyler-wardhaugh/clojure/test/tw/weekly/c81_test.clj b/challenge-081/tyler-wardhaugh/clojure/test/tw/weekly/c81_test.clj index a9f3889aa1..4126410f68 100644 --- a/challenge-081/tyler-wardhaugh/clojure/test/tw/weekly/c81_test.clj +++ b/challenge-081/tyler-wardhaugh/clojure/test/tw/weekly/c81_test.clj @@ -1,8 +1,21 @@ (ns tw.weekly.c81-test (:require [clojure.test :refer [deftest is testing]] - [tw.weekly.c81.t1 :refer [common-base-string]])) + [clojure.java.io :as io] + [net.cgrand.xforms.io :as xio] + [tw.weekly.c81.t1 :refer [common-base-string]] + [tw.weekly.c81.t2 :refer [word-frequency-sort]])) (deftest task-1 (testing "Task 1, Common Base String" (is (= (common-base-string "abcdabcd" "abcdabcdabcdabcd") ["abcd" "abcdabcd"])) (is (= (common-base-string "aaa" "aa") ["a"])))) + +(deftest task-2 + (testing "Task 2, Frequency Sort" + (is (= (word-frequency-sort (xio/lines-in (io/resource "input"))) + (into (sorted-map) + {1 (into (sorted-set) #{"But" "City" "It" "Jet" "Juliet" "Latino" "New" "Romeo" "Side" "Story" "Their" "Then" "West" "York" "adaptation" "any" "anything" "at" "award-winning" "away" "become" "before" "begin" "best" "classic" "climactic" "coexist" "control" "dance" "do" "doesn't" "end" "ending" "escalates" "families" "feuding" "form" "former" "friend" "gains" "gangs" "goes" "happened" "hatred" "heartbreaking" "highway" "hoping" "in" "know" "love" "lovers" "meet" "meeting" "neither" "no" "one" "plan" "planning" "point" "romantic" "rumble" "run" "secret" "sends" "sister" "streets" "strikes" "terribly" "their" "two" "under" "understanding" "until" "violence" "warring" "what" "when" "where" "white" "whoever" "wins" "with" "wrong" "younger"}) + 2 (into (sorted-set) #{"Bernardo" "Jets" "Riff" "Sharks" "The" "by" "it" "led" "tragedy"}) + 3 (into (sorted-set) #{"Maria" "Tony" "a" "can" "of" "stop"}) + 4 #{"to"} + 9 (into (sorted-set) #{"and" "the"})}))))) -- cgit From 5a7b6deedb64b69ddad17271be3714f5d0f1334c Mon Sep 17 00:00:00 2001 From: Dave Jacoby Date: Tue, 6 Oct 2020 17:53:24 -0400 Subject: Challenge 81 --- challenge-081/dave-jacoby/perl/ch-1.pl | 50 ++++++++++++++++++++++++++++++++++ challenge-081/dave-jacoby/perl/ch-2.pl | 34 +++++++++++++++++++++++ challenge-081/dave-jacoby/perl/input | 3 ++ 3 files changed, 87 insertions(+) create mode 100755 challenge-081/dave-jacoby/perl/ch-1.pl create mode 100755 challenge-081/dave-jacoby/perl/ch-2.pl create mode 100644 challenge-081/dave-jacoby/perl/input (limited to 'challenge-081') diff --git a/challenge-081/dave-jacoby/perl/ch-1.pl b/challenge-081/dave-jacoby/perl/ch-1.pl new file mode 100755 index 0000000000..3a753f09e8 --- /dev/null +++ b/challenge-081/dave-jacoby/perl/ch-1.pl @@ -0,0 +1,50 @@ +#!/usr/bin/env perl + +use strict; +use warnings; +use feature qw{ say signatures state }; +no warnings qw{ experimental }; + +my $comment = <<'DOC'; +You are given 2 strings, $A and $B. + +Write a script to find out common base strings in $A and $B. + +A substring of a string $S is called base string if repeated concatenation of the substring results in the string. + +Example 1: +Input: + $A = "abcdabcd" + $B = "abcdabcdabcdabcd" + +Output: + ("abcd", "abcdabcd") +Example 2: +Input: + $A = "aaa" + $B = "aa" + +Output: + ("a") +DOC + +common_base( "abcdabcd", "abcdabcdabcdabcd" ); +common_base( "aaa", "aa" ); + +sub common_base ( @words ) { + my ( $aa, $bb ) = sort { length $a <=> length $b } @words; + my %output; + + for my $i ( 0 .. length $aa ) { + for my $j ( $i + 1 .. length $aa ) { + my $aaa = $aa; + my $bbb = $bb; + my $sub = substr( $aa, $i, $j ); + $aaa =~ s/$sub//gmix; + $bbb =~ s/$sub//gmix; + $output{$sub} = 1 if $aaa eq '' && $bbb eq ''; + } + } + say join ', ', keys %output; +} + diff --git a/challenge-081/dave-jacoby/perl/ch-2.pl b/challenge-081/dave-jacoby/perl/ch-2.pl new file mode 100755 index 0000000000..bca7719a96 --- /dev/null +++ b/challenge-081/dave-jacoby/perl/ch-2.pl @@ -0,0 +1,34 @@ +#!/usr/bin/env perl + +use strict; +use warnings; +use feature qw{ say signatures state }; +no warnings qw{ experimental }; + +use List::Util qw{max}; + +my $file = $ARGV[0]; +$file = defined $file && -f $file ? $file : 'input'; + +frequency_sort($file); + +sub frequency_sort( $file ) { + if ( -f $file && open my $fh, '<', $file ) { + my $corpus = join '', <$fh>; + $corpus =~ s/[,\.\(\)\"]/ /g; + $corpus =~ s/\'s/ /g; + $corpus =~ s/--/ /g; + my %words; + for my $word ( split /\s+/, $corpus ) { + $words{$word}++; + } + my $max = max values %words; + + for my $c ( 1 .. $max ) { + my @words = sort grep { $words{$_} == $c } keys %words; + say join ' ', $c, @words, "\n" if scalar @words; + } + + close $fh; + } +} diff --git a/challenge-081/dave-jacoby/perl/input b/challenge-081/dave-jacoby/perl/input new file mode 100644 index 0000000000..37001629ad --- /dev/null +++ b/challenge-081/dave-jacoby/perl/input @@ -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. -- cgit From 2a164009eaff581dc487a5fc955c7421a8ba7a31 Mon Sep 17 00:00:00 2001 From: Dave Jacoby Date: Tue, 6 Oct 2020 19:33:44 -0400 Subject: Better loops --- challenge-081/dave-jacoby/perl/ch-1.pl | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'challenge-081') diff --git a/challenge-081/dave-jacoby/perl/ch-1.pl b/challenge-081/dave-jacoby/perl/ch-1.pl index 3a753f09e8..44dccb6c91 100755 --- a/challenge-081/dave-jacoby/perl/ch-1.pl +++ b/challenge-081/dave-jacoby/perl/ch-1.pl @@ -36,14 +36,18 @@ sub common_base ( @words ) { my %output; for my $i ( 0 .. length $aa ) { - for my $j ( $i + 1 .. length $aa ) { + for my $j ( 1 .. ( length $aa ) - $i ) { my $aaa = $aa; my $bbb = $bb; my $sub = substr( $aa, $i, $j ); + my $pad = ' ' x $i; $aaa =~ s/$sub//gmix; $bbb =~ s/$sub//gmix; + next unless $aaa eq '' && $bbb eq ''; + # say qq{ $pad$sub\t$aaa\t$bbb}; $output{$sub} = 1 if $aaa eq '' && $bbb eq ''; } + } say join ', ', keys %output; } -- cgit From a7ebfccc0bd4f36b3fd94a517cb299d6c3c45de2 Mon Sep 17 00:00:00 2001 From: Roger Bell_West Date: Wed, 7 Oct 2020 10:15:24 +0100 Subject: Blog post for #81. --- challenge-081/roger-bell-west/blog.txt | 1 + 1 file changed, 1 insertion(+) create mode 100644 challenge-081/roger-bell-west/blog.txt (limited to 'challenge-081') diff --git a/challenge-081/roger-bell-west/blog.txt b/challenge-081/roger-bell-west/blog.txt new file mode 100644 index 0000000000..480796de5c --- /dev/null +++ b/challenge-081/roger-bell-west/blog.txt @@ -0,0 +1 @@ +https://blog.firedrake.org/archive/2020/10/Perl_Weekly_Challenge_81__Base_Frequency.html -- cgit From 6750dc1c85e2796da0b31970e0a64d2585386ac2 Mon Sep 17 00:00:00 2001 From: Jose Luis Perez Date: Wed, 7 Oct 2020 12:26:47 +0200 Subject: base strings 1st iteration --- challenge-081/jluis/README | 1 + challenge-081/jluis/perl/ch-1.pl | 53 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+) create mode 100644 challenge-081/jluis/README create mode 100644 challenge-081/jluis/perl/ch-1.pl (limited to 'challenge-081') diff --git a/challenge-081/jluis/README b/challenge-081/jluis/README new file mode 100644 index 0000000000..ff80e1d3bd --- /dev/null +++ b/challenge-081/jluis/README @@ -0,0 +1 @@ +Solution by jluis diff --git a/challenge-081/jluis/perl/ch-1.pl b/challenge-081/jluis/perl/ch-1.pl new file mode 100644 index 0000000000..8549a26895 --- /dev/null +++ b/challenge-081/jluis/perl/ch-1.pl @@ -0,0 +1,53 @@ +#!/usr/bin/env perl + +use strict; +use warnings; + +sub base { + # bassed on Abigil's prime number regex + # get all base strings of $_[0] + # a base string is one that concateneted 0 or more times can generate + # the original string + my $orig = shift; + my @bases; + my $length = 1; + while (1) { + last unless $orig =~ /^(.{$length,}?)\1+$/; + push @bases,$1; + $length = 1+length($1); + } + return (@bases,$orig) +} + +sub format_list { + my $out = "("; + while (my $val = shift) { + $out .= '"'.$val.'"'; + $out .= ',' if defined @_[0]; + } + return "$out)"; +} + +sub common_base { + my @A = base(shift); + my @B = base(shift); + my @result; + my $AIndex = 0; + my $BIndex = 0; + while ($AIndex <= $#A and $BIndex <= $#B) { + if ($A[$AIndex] eq $B[$BIndex]) { + push @result,$A[$AIndex]; + $AIndex += 1; + $BIndex += 1; + next; + } + last if length($A[$AIndex]) == length($B[$BIndex]); + if (length($A[$AIndex]) > length($B[$BIndex])) { + $BIndex += 1; + } else { + $AIndex += 1; + } + } + return @result; +} +CORE::say format_list common_base 'aa'x210,'a'x105; -- cgit From 347371e27ff3dd862b942ed73a867473b3bedb3a Mon Sep 17 00:00:00 2001 From: Jose Luis Perez Date: Wed, 7 Oct 2020 13:21:05 +0200 Subject: second chalenge done --- challenge-081/jluis/perl/ch-2.pl | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 challenge-081/jluis/perl/ch-2.pl (limited to 'challenge-081') diff --git a/challenge-081/jluis/perl/ch-2.pl b/challenge-081/jluis/perl/ch-2.pl new file mode 100644 index 0000000000..010b34985f --- /dev/null +++ b/challenge-081/jluis/perl/ch-2.pl @@ -0,0 +1,23 @@ +use strict; +use warnings; +use 5.010; + +open(my $input,'<','input') or die "Can't open input: $!"; + +my %freq; +while(<$input>){ + chomp; + s/\.|"|\(|\)|,|'s|--/ /g; + while (s/\s*(\w+)\s*//) { + $freq{$1} = 0 unless defined $freq{$1}; + $freq{$1} += 1; + } +} + +my @results; +for my $key (sort keys %freq) { + $results[$freq{$key}] = "$freq{$key}" unless defined $results[$freq{$key}]; + $results[$freq{$key}] .= " $key"; +} + +defined($_) and say for @results; -- cgit From 1bf08a8547aab0cc7f60923ad26f516afcc6e5ff Mon Sep 17 00:00:00 2001 From: Kang-min Liu Date: Wed, 7 Oct 2020 22:46:49 +0900 Subject: solution of 081.2 --- challenge-081/gugod/raku/ch-2.raku | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 challenge-081/gugod/raku/ch-2.raku (limited to 'challenge-081') diff --git a/challenge-081/gugod/raku/ch-2.raku b/challenge-081/gugod/raku/ch-2.raku new file mode 100644 index 0000000000..62a014f118 --- /dev/null +++ b/challenge-081/gugod/raku/ch-2.raku @@ -0,0 +1,28 @@ +#!/usr/bin/env raku + +sub MAIN (Str $input = 'input') { + print-frequency-table( word-frequency( IO::Path.new($input) ) ); +} + +sub word-frequency ( $fh ) { + my %freq; + my $prev = ''; + for $fh.split(//) -> $token { + if $token.match(/<:Letter>/) && !($token eq "s" && $prev eq "'") { + %freq{$token} += 1; + } + $prev = $token; + } + + return %freq; +} + +sub print-frequency-table ( %freq ) { + my %rfreq; + for %freq.pairs -> $it { + %rfreq{ $it.value }.append( $it.key ); + } + for %rfreq.keys.sort -> $n { + say $n ~ ' ' ~ %rfreq{$n}.sort.join(' '); + } +} -- cgit From c65c694f21ce314c2a47e9a0bf5b4d3a0c993cb4 Mon Sep 17 00:00:00 2001 From: Jose Luis Perez Diez Date: Wed, 7 Oct 2020 19:35:20 +0200 Subject: Add usage information --- challenge-081/jluis/perl/ch-1.pl | 25 +++++++++++++++++++++---- challenge-081/jluis/perl/ch-2.pl | 9 ++++++++- 2 files changed, 29 insertions(+), 5 deletions(-) mode change 100644 => 100755 challenge-081/jluis/perl/ch-1.pl mode change 100644 => 100755 challenge-081/jluis/perl/ch-2.pl (limited to 'challenge-081') diff --git a/challenge-081/jluis/perl/ch-1.pl b/challenge-081/jluis/perl/ch-1.pl old mode 100644 new mode 100755 index 8549a26895..0563d11964 --- a/challenge-081/jluis/perl/ch-1.pl +++ b/challenge-081/jluis/perl/ch-1.pl @@ -2,12 +2,29 @@ use strict; use warnings; +use 5.010; + +if ($#ARGV != 1) { + say <){ chomp; s/\.|"|\(|\)|,|'s|--/ /g; - while (s/\s*(\w+)\s*//) { + while (/(\w+)/g) { $freq{$1} = 0 unless defined $freq{$1}; $freq{$1} += 1; } -- cgit From dd2635a5d37c5a853c5400613eb63c5fc301539c Mon Sep 17 00:00:00 2001 From: Jörg Sommrey <28217714+jo-37@users.noreply.github.com> Date: Mon, 5 Oct 2020 11:05:51 +0200 Subject: Solution to task 1 --- challenge-081/jo-37/perl/ch-1.pl | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100755 challenge-081/jo-37/perl/ch-1.pl (limited to 'challenge-081') diff --git a/challenge-081/jo-37/perl/ch-1.pl b/challenge-081/jo-37/perl/ch-1.pl new file mode 100755 index 0000000000..61941ab415 --- /dev/null +++ b/challenge-081/jo-37/perl/ch-1.pl @@ -0,0 +1,31 @@ +#!/usr/bin/perl + +use Test2::V0; + +# Find common base strings in two given strings. +sub cbs { + + # Combine both strings by joining them with a newline. + # The strings must not contain newlines. + local $_ = shift . "\n" . shift; + + # Collect all common base strings. + # Note: "dot" does not match a newline here. + my @base; + m{ + ^ (.+?) \1*+ \n \1++ \z # capture base string for both + (?{push @base, $1}) # collect captured base string + (*FAIL) # force backtracking + }x; + + @base; +} + +is [cbs("abcdabcd", "abcdabcdabcdabcd")], ["abcd", "abcdabcd"], + "first example"; + +is [cbs("aaa", "aa")], ["a"], "second example"; + +is [cbs("abcabc", "abcdabcdabcd")], [], "no common base strings"; + +done_testing; -- cgit From 90730d8ef9b174c6d736b63be07ebfd17e3632bd Mon Sep 17 00:00:00 2001 From: Jörg Sommrey <28217714+jo-37@users.noreply.github.com> Date: Mon, 5 Oct 2020 14:44:00 +0200 Subject: Solution to task 2 --- challenge-081/jo-37/perl/ch-2.pl | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100755 challenge-081/jo-37/perl/ch-2.pl (limited to 'challenge-081') diff --git a/challenge-081/jo-37/perl/ch-2.pl b/challenge-081/jo-37/perl/ch-2.pl new file mode 100755 index 0000000000..50f80268d7 --- /dev/null +++ b/challenge-081/jo-37/perl/ch-2.pl @@ -0,0 +1,29 @@ +#!/usr/bin/perl + +use strict; +use warnings; +use List::Util qw(uniqnum pairgrep pairkeys); + +# Use the input data provided by the DATA filehandle if no file name +# is given. +*ARGV = *DATA{IO} unless @ARGV; + +# Override some defaults: line endings, field separator and slurp mode +local ($\, $,, $/) = ("\n\n", ' '); + +# Build a hash of word/frequency pairs from input data. Incorporate +# specified exceptions into the split expression. +my %freq; +$freq{$_}++ foreach split qr{[\."),]*\s+[("]*|--|'s\s+}, <>; + +# For each frequency, extract the corresponding words from %freq, sort +# and print them. +# Note: "pairkeys" needs to be protected from being interpreted as a +# comparator sub name by sort. +print $_, sort +(pairkeys pairgrep {$b == $_} %freq) + foreach uniqnum sort {$a <=> $b} values %freq; + +__DATA__ +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. -- cgit From 796001952cdb0d6517968b065cfdb18f08dee950 Mon Sep 17 00:00:00 2001 From: Mohammad S Anwar Date: Wed, 7 Oct 2020 22:23:17 +0100 Subject: - Added Perl solution to Frequency Sort task. --- challenge-081/mohammad-anwar/perl/ch-2.pl | 58 +++++++++++++++++++++++++++++++ challenge-081/mohammad-anwar/perl/input | 3 ++ 2 files changed, 61 insertions(+) create mode 100644 challenge-081/mohammad-anwar/perl/ch-2.pl create mode 100644 challenge-081/mohammad-anwar/perl/input (limited to 'challenge-081') diff --git a/challenge-081/mohammad-anwar/perl/ch-2.pl b/challenge-081/mohammad-anwar/perl/ch-2.pl new file mode 100644 index 0000000000..2f9a27fbe5 --- /dev/null +++ b/challenge-081/mohammad-anwar/perl/ch-2.pl @@ -0,0 +1,58 @@ +#!/usr/bin/perl + +# +# Perl Weekly Challenge - 081 +# +# Task #2: Frequency Count +# +# https://perlweeklychallenge.org/blog/perl-weekly-challenge-081 +# + +use strict; +use warnings; + +frequency_count(fetch_words($ARGV[0])); + +# +# +# SUBROUTINES + +sub fetch_words { + my ($file) = @_; + + open(my $fh, "<:encoding(UTF-8)", $file) + or die "ERROR: Unable to open $file: $!\n"; + + my %words = (); + while (my $line = <$fh>) { + chomp $line; + $line =~ s/\.//g; + $line =~ s/\"//g; + $line =~ s/\(//g; + $line =~ s/\)//g; + $line =~ s/\,//g; + $line =~ s/\'s//g; + $line =~ s/\-\-/ /g; + foreach my $word (split /\s/, $line) { + $words{$word} += 1; + } + } + + close($fh); + + return \%words; +} + +sub frequency_count { + my ($words) = @_; + + my %frequency = (); + foreach my $word (keys %$words) { + $frequency{$words->{$word}} .= " " . $word; + } + + foreach my $count (sort { $a <=> $b } keys %frequency) { + my @words = split / /, $frequency{$count}; + printf("%d%s\n", $count, join(" ", sort @words)); + } +} diff --git a/challenge-081/mohammad-anwar/perl/input b/challenge-081/mohammad-anwar/perl/input new file mode 100644 index 0000000000..37001629ad --- /dev/null +++ b/challenge-081/mohammad-anwar/perl/input @@ -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. -- cgit From 3ac525e86f510b1c666672fa8d6697fd4b1ab91e Mon Sep 17 00:00:00 2001 From: Flavio Poletti Date: Wed, 7 Oct 2020 23:46:28 +0200 Subject: Add polettix's solution for PWC081 --- challenge-081/polettix/blog.txt | 1 + challenge-081/polettix/blog1.txt | 1 + challenge-081/polettix/perl/ch-1.pl | 69 +++++++++++++++++++++++++++++++++++++ challenge-081/polettix/perl/ch-2.pl | 48 ++++++++++++++++++++++++++ 4 files changed, 119 insertions(+) create mode 100644 challenge-081/polettix/blog.txt create mode 100644 challenge-081/polettix/blog1.txt create mode 100644 challenge-081/polettix/perl/ch-1.pl create mode 100644 challenge-081/polettix/perl/ch-2.pl (limited to 'challenge-081') diff --git a/challenge-081/polettix/blog.txt b/challenge-081/polettix/blog.txt new file mode 100644 index 0000000000..70d6168bed --- /dev/null +++ b/challenge-081/polettix/blog.txt @@ -0,0 +1 @@ +https://github.polettix.it/ETOOBUSY/2020/10/08/pwc081-common-base-string/ diff --git a/challenge-081/polettix/blog1.txt b/challenge-081/polettix/blog1.txt new file mode 100644 index 0000000000..2577d90c34 --- /dev/null +++ b/challenge-081/polettix/blog1.txt @@ -0,0 +1 @@ +https://github.polettix.it/ETOOBUSY/2020/10/09/pwc081-frequency-sort/ diff --git a/challenge-081/polettix/perl/ch-1.pl b/challenge-081/polettix/perl/ch-1.pl new file mode 100644 index 0000000000..b48ea56f87 --- /dev/null +++ b/challenge-081/polettix/perl/ch-1.pl @@ -0,0 +1,69 @@ +#!/usr/bin/env perl +use 5.024; +use warnings; +use experimental qw< postderef signatures >; +no warnings qw< experimental::postderef experimental::signatures >; + +sub proper_factors ($n) { grep { $n % $_ == 0} (2 .. int($n/2))} + +sub min_period ($string) { + my $n = length $string; + + CANDIDATE: + for my $k (1, proper_factors($n)) { + my $m = $n / $k; # sub-sequences we have to test + for my $i (0 .. $k - 1) { # sub-sequence iterator + my $char = substr $string, $i, 1; + for my $s (1 .. $m - 1) { # sequence iterator + next CANDIDATE if $char ne substr $string, $k * $s + $i, 1; + } + } + # yay! + return $k; + } + + # nothing found, minimum period is the string's length + return $n; +} + +sub min_common_base ($A, $B) { + my $pA = min_period($A); + my $pB = min_period($B); + return if $pB != $pA; # they must be equal + my $candidate = substr $A, 0, $pA; + return $candidate if $candidate eq substr $B, 0, $pB; + return; +} + +sub common_bases ($A, $B) { + defined(my $b = min_common_base($A, $B)) or return; + + my $l = length $b; + my ($rA, $rB) = map {length($_) / $l} ($A, $B); + ($rA, $rB) = ($rB, $rA) if $rA > $rB; + + return map { $rB % $_ ? () : $b x $_ } (1, proper_factors($rA), $rA); +} + +sub common_bases_brute_force ($A, $B) { + my ($lA, $lB) = (length($A), length($B)); + ($A, $B, $lA, $lB) = ($B, $A, $lB, $lA) if $lA > $lB; + my @retval; + CANDIDATE: + for my $l (1 .. int($lA / 2), $lA) { + next CANDIDATE if ($lA % $l) || ($lB % $l); + my $base = substr $A, 0, $l; + for my $s ($A, $B) { + next CANDIDATE if $s ne $base x (length($s) / $l); + } + push @retval, $base; + } + return @retval; +} + +for my $input ( + ['abcdabcd', 'abcdabcdabcdabcd'], + ['aaa', 'aa'], +){ + say '(', join(', ', map {qq{"$_"}} common_bases_brute_force($input->@*)), ')'; +} diff --git a/challenge-081/polettix/perl/ch-2.pl b/challenge-081/polettix/perl/ch-2.pl new file mode 100644 index 0000000000..46124837c4 --- /dev/null +++ b/challenge-081/polettix/perl/ch-2.pl @@ -0,0 +1,48 @@ +#!/usr/bin/env perl +use 5.024; +use warnings; +use experimental qw< postderef signatures >; +no warnings qw< experimental::postderef experimental::signatures >; +use autodie; + +sub frequency_sort ($input = 'input') { + + # Allow for getting an open filehandle as input + my $fh = ref($input) ? $input : do {open my $fh, '<', $input; $fh}; + + # Count occurrences for all words, just for starters + my %count_for; + while (<$fh>) { + s{(?: [."(),] | 's | -- )+}{ }gmxs; # ignore stuff + $count_for{$_}++ for grep {length > 0} split m{\s+}mxs; + } + + # Invert "count by word" to "words by count" + my %words_for; + while (my ($word, $count) = each %count_for) { + push $words_for{$count}->@*, $word; + } + + say join "\n\n", map { + # Sort words for $count lexicographically + join ' ', $_, sort {$a cmp $b} $words_for{$_}->@*; + } sort {$a <=> $b} keys %words_for; +} + +frequency_sort(\*DATA); + +__DATA__ +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. -- cgit