diff options
| author | Tyler Wardhaugh <tyler.wardhaugh@gmail.com> | 2020-09-22 15:28:49 -0700 |
|---|---|---|
| committer | Tyler Wardhaugh <tyler.wardhaugh@gmail.com> | 2020-09-22 20:54:58 -0700 |
| commit | 9fd19396bf90b0e79dbf22cfca1428dc479b6a3c (patch) | |
| tree | d631ba5140777cb4e8a6c4e7cb2d85a077412668 | |
| parent | 9dad8eb5c718146e406109092dc12aefc829886f (diff) | |
| download | perlweeklychallenge-club-9fd19396bf90b0e79dbf22cfca1428dc479b6a3c.tar.gz perlweeklychallenge-club-9fd19396bf90b0e79dbf22cfca1428dc479b6a3c.tar.bz2 perlweeklychallenge-club-9fd19396bf90b0e79dbf22cfca1428dc479b6a3c.zip | |
Task 2
9 files changed, 81 insertions, 8 deletions
diff --git a/challenge-079/tyler-wardhaugh/clojure/README.md b/challenge-079/tyler-wardhaugh/clojure/README.md index b576ec7183..37d274beb5 100644 --- a/challenge-079/tyler-wardhaugh/clojure/README.md +++ b/challenge-079/tyler-wardhaugh/clojure/README.md @@ -21,6 +21,17 @@ Run Task #2 with input: $ clojure -m tw.weekly.c79.t2 A1 A2 A3 [...] +See SVG files in the `resources` directory for the histograms drawn for each of the tests for Task 2: + + + + + + + + + + ## Project Template I used Sean Corfield's clj-new to generate the project template diff --git a/challenge-079/tyler-wardhaugh/clojure/deps.edn b/challenge-079/tyler-wardhaugh/clojure/deps.edn index 236f47e5b1..988d683304 100644 --- a/challenge-079/tyler-wardhaugh/clojure/deps.edn +++ b/challenge-079/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"} + metasoarous/oz {:mvn/version "1.6.0-alpha26"}} :aliases {:test {:extra-paths ["test"] :extra-deps {org.clojure/test.check {:mvn/version "1.0.0"}}} diff --git a/challenge-079/tyler-wardhaugh/clojure/pom.xml b/challenge-079/tyler-wardhaugh/clojure/pom.xml index 9644c7aec7..a5ef0fbd29 100644 --- a/challenge-079/tyler-wardhaugh/clojure/pom.xml +++ b/challenge-079/tyler-wardhaugh/clojure/pom.xml @@ -30,6 +30,11 @@ <artifactId>clojure</artifactId> <version>1.10.1</version> </dependency> + <dependency> + <groupId>metasoarous</groupId> + <artifactId>oz</artifactId> + <version>1.6.0-alpha26</version> + </dependency> </dependencies> <build> <sourceDirectory>src</sourceDirectory> diff --git a/challenge-079/tyler-wardhaugh/clojure/resources/t2.test1.svg b/challenge-079/tyler-wardhaugh/clojure/resources/t2.test1.svg new file mode 100644 index 0000000000..c3f51d8d13 --- /dev/null +++ b/challenge-079/tyler-wardhaugh/clojure/resources/t2.test1.svg @@ -0,0 +1 @@ +<svg class="marks" width="158" height="243" viewBox="0 0 158 243" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"><rect width="158" height="243" fill="white"></rect><g fill="none" stroke-miterlimit="10" transform="translate(33,10)"><g class="mark-group role-frame root" role="graphics-object" aria-roledescription="group mark container"><g transform="translate(0,0)"><path class="background" aria-hidden="true" d="M0.5,0.5h120v200h-120Z" stroke="#ddd"></path><g><g class="mark-group role-axis" aria-hidden="true"><g transform="translate(0.5,0.5)"><path class="background" aria-hidden="true" d="M0,0h0v0h0Z" pointer-events="none"></path><g><g class="mark-rule role-axis-grid" pointer-events="none"><line transform="translate(0,200)" x2="120" y2="0" stroke="#ddd" stroke-width="1" opacity="1"></line><line transform="translate(0,160)" x2="120" y2="0" stroke="#ddd" stroke-width="1" opacity="1"></line><line transform="translate(0,120)" x2="120" y2="0" stroke="#ddd" stroke-width="1" opacity="1"></line><line transform="translate(0,80)" x2="120" y2="0" stroke="#ddd" stroke-width="1" opacity="1"></line><line transform="translate(0,40)" x2="120" y2="0" stroke="#ddd" stroke-width="1" opacity="1"></line><line transform="translate(0,0)" x2="120" y2="0" stroke="#ddd" stroke-width="1" opacity="1"></line></g></g><path class="foreground" aria-hidden="true" d="" pointer-events="none" display="none"></path></g></g><g class="mark-group role-axis" role="graphics-symbol" aria-roledescription="axis" aria-label="X-axis titled 'x' for a discrete scale with 6 values: 0, 1, 2, 3, 4, 5"><g transform="translate(0.5,200.5)"><path class="background" aria-hidden="true" d="M0,0h0v0h0Z" pointer-events="none"></path><g><g class="mark-rule role-axis-tick" pointer-events="none"><line transform="translate(10,0)" x2="0" y2="5" stroke="#888" stroke-width="1" opacity="1"></line><line transform="translate(30,0)" x2="0" y2="5" stroke="#888" stroke-width="1" opacity="1"></line><line transform="translate(50,0)" x2="0" y2="5" stroke="#888" stroke-width="1" opacity="1"></line><line transform="translate(70,0)" x2="0" y2="5" stroke="#888" stroke-width="1" opacity="1"></line><line transform="translate(90,0)" x2="0" y2="5" stroke="#888" stroke-width="1" opacity="1"></line><line transform="translate(110,0)" x2="0" y2="5" stroke="#888" stroke-width="1" opacity="1"></line></g><g class="mark-text role-axis-label" pointer-events="none"><text text-anchor="end" transform="translate(9.5,7) rotate(270) translate(0,3)" font-family="sans-serif" font-size="10px" fill="#000" opacity="1">0</text><text text-anchor="end" transform="translate(29.5,7) rotate(270) translate(0,3)" font-family="sans-serif" font-size="10px" fill="#000" opacity="1">1</text><text text-anchor="end" transform="translate(49.5,7) rotate(270) translate(0,3)" font-family="sans-serif" font-size="10px" fill="#000" opacity="1">2</text><text text-anchor="end" transform="translate(69.5,7) rotate(270) translate(0,3)" font-family="sans-serif" font-size="10px" fill="#000" opacity="1">3</text><text text-anchor="end" transform="translate(89.5,7) rotate(270) translate(0,3)" font-family="sans-serif" font-size="10px" fill="#000" opacity="1">4</text><text text-anchor="end" transform="translate(109.5,7) rotate(270) translate(0,3)" font-family="sans-serif" font-size="10px" fill="#000" opacity="1">5</text></g><g class="mark-rule role-axis-domain" pointer-events="none"><line transform="translate(0,0)" x2="120" y2="0" stroke="#888" stroke-width="1" opacity="1"></line></g><g class="mark-text role-axis-title" pointer-events="none"><text text-anchor="middle" transform="translate(60,25.5615234375)" font-family="sans-serif" font-size="11px" font-weight="bold" fill="#000" opacity="1">x</text></g></g><path class="foreground" aria-hidden="true" d="" pointer-events="none" display="none"></path></g></g><g class="mark-group role-axis" role="graphics-symbol" aria-roledescription="axis" aria-label="Y-axis titled 'Sum of y' for a linear scale with values from 0 to 5"><g transform="translate(0.5,0.5)"><path class="background" aria-hidden="true" d="M0,0h0v0h0Z" pointer-events="none"></path><g><g class="mark-rule role-axis-tick" pointer-events="none"><line transform="translate(0,200)" x2="-5" y2="0" stroke="#888" stroke-width="1" opacity="1"></line><line transform="translate(0,160)" x2="-5" y2="0" stroke="#888" stroke-width="1" opacity="1"></line><line transform="translate(0,120)" x2="-5" y2="0" stroke="#888" stroke-width="1" opacity="1"></line><line transform="translate(0,80)" x2="-5" y2="0" stroke="#888" stroke-width="1" opacity="1"></line><line transform="translate(0,40)" x2="-5" y2="0" stroke="#888" stroke-width="1" opacity="1"></line><line transform="translate(0,0)" x2="-5" y2="0" stroke="#888" stroke-width="1" opacity="1"></line></g><g class="mark-text role-axis-label" pointer-events="none"><text text-anchor="end" transform="translate(-7,203)" font-family="sans-serif" font-size="10px" fill="#000" opacity="1">0</text><text text-anchor="end" transform="translate(-7,163)" font-family="sans-serif" font-size="10px" fill="#000" opacity="1">1</text><text text-anchor="end" transform="translate(-7,123)" font-family="sans-serif" font-size="10px" fill="#000" opacity="1">2</text><text text-anchor="end" transform="translate(-7,83)" font-family="sans-serif" font-size="10px" fill="#000" opacity="1">3</text><text text-anchor="end" transform="translate(-7,42.99999999999999)" font-family="sans-serif" font-size="10px" fill="#000" opacity="1">4</text><text text-anchor="end" transform="translate(-7,3)" font-family="sans-serif" font-size="10px" fill="#000" opacity="1">5</text></g><g class="mark-rule role-axis-domain" pointer-events="none"><line transform="translate(0,200)" x2="0" y2="-200" stroke="#888" stroke-width="1" opacity="1"></line></g><g class="mark-text role-axis-title" pointer-events="none"><text text-anchor="middle" transform="translate(-16.5615234375,100) rotate(-90) translate(0,-2)" font-family="sans-serif" font-size="11px" font-weight="bold" fill="#000" opacity="1">Sum of y</text></g></g><path class="foreground" aria-hidden="true" d="" pointer-events="none" display="none"></path></g></g><g class="mark-rect role-mark marks" role="graphics-object" aria-roledescription="rect mark container"><path aria-label="x: 0; Sum of y: 2; c: green" role="graphics-symbol" aria-roledescription="bar" d="M1,120h18v80h-18Z" fill="green"></path><path aria-label="x: 0; Sum of y: 0; c: blue" role="graphics-symbol" aria-roledescription="bar" d="M1,120h18v0h-18Z" fill="blue"></path><path aria-label="x: 1; Sum of y: 1; c: green" role="graphics-symbol" aria-roledescription="bar" d="M21,160h18v40h-18Z" fill="green"></path><path aria-label="x: 1; Sum of y: 1; c: blue" role="graphics-symbol" aria-roledescription="bar" d="M21,120h18v40h-18Z" fill="blue"></path><path aria-label="x: 2; Sum of y: 4; c: green" role="graphics-symbol" aria-roledescription="bar" d="M41,39.99999999999999h18v160h-18Z" fill="green"></path><path aria-label="x: 2; Sum of y: 0; c: blue" role="graphics-symbol" aria-roledescription="bar" d="M41,39.99999999999999h18v0h-18Z" fill="blue"></path><path aria-label="x: 3; Sum of y: 1; c: green" role="graphics-symbol" aria-roledescription="bar" d="M61,160h18v40h-18Z" fill="green"></path><path aria-label="x: 3; Sum of y: 3; c: blue" role="graphics-symbol" aria-roledescription="bar" d="M61,39.99999999999999h18v120h-18Z" fill="blue"></path><path aria-label="x: 4; Sum of y: 2; c: green" role="graphics-symbol" aria-roledescription="bar" d="M81,120h18v80h-18Z" fill="green"></path><path aria-label="x: 4; Sum of y: 2; c: blue" role="graphics-symbol" aria-roledescription="bar" d="M81,39.99999999999999h18v80h-18Z" fill="blue"></path><path aria-label="x: 5; Sum of y: 5; c: green" role="graphics-symbol" aria-roledescription="bar" d="M101,0h18v200h-18Z" fill="green"></path><path aria-label="x: 5; Sum of y: 0; c: blue" role="graphics-symbol" aria-roledescription="bar" d="M101,0h18v0h-18Z" fill="blue"></path></g></g><path class="foreground" aria-hidden="true" d="" display="none"></path></g></g></g></svg>
\ No newline at end of file diff --git a/challenge-079/tyler-wardhaugh/clojure/resources/t2.test2.svg b/challenge-079/tyler-wardhaugh/clojure/resources/t2.test2.svg new file mode 100644 index 0000000000..1d37ffddb2 --- /dev/null +++ b/challenge-079/tyler-wardhaugh/clojure/resources/t2.test2.svg @@ -0,0 +1 @@ +<svg class="marks" width="158" height="243" viewBox="0 0 158 243" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"><rect width="158" height="243" fill="white"></rect><g fill="none" stroke-miterlimit="10" transform="translate(33,10)"><g class="mark-group role-frame root" role="graphics-object" aria-roledescription="group mark container"><g transform="translate(0,0)"><path class="background" aria-hidden="true" d="M0.5,0.5h120v200h-120Z" stroke="#ddd"></path><g><g class="mark-group role-axis" aria-hidden="true"><g transform="translate(0.5,0.5)"><path class="background" aria-hidden="true" d="M0,0h0v0h0Z" pointer-events="none"></path><g><g class="mark-rule role-axis-grid" pointer-events="none"><line transform="translate(0,200)" x2="120" y2="0" stroke="#ddd" stroke-width="1" opacity="1"></line><line transform="translate(0,160)" x2="120" y2="0" stroke="#ddd" stroke-width="1" opacity="1"></line><line transform="translate(0,120)" x2="120" y2="0" stroke="#ddd" stroke-width="1" opacity="1"></line><line transform="translate(0,80)" x2="120" y2="0" stroke="#ddd" stroke-width="1" opacity="1"></line><line transform="translate(0,40)" x2="120" y2="0" stroke="#ddd" stroke-width="1" opacity="1"></line><line transform="translate(0,0)" x2="120" y2="0" stroke="#ddd" stroke-width="1" opacity="1"></line></g></g><path class="foreground" aria-hidden="true" d="" pointer-events="none" display="none"></path></g></g><g class="mark-group role-axis" role="graphics-symbol" aria-roledescription="axis" aria-label="X-axis titled 'x' for a discrete scale with 6 values: 0, 1, 2, 3, 4, 5"><g transform="translate(0.5,200.5)"><path class="background" aria-hidden="true" d="M0,0h0v0h0Z" pointer-events="none"></path><g><g class="mark-rule role-axis-tick" pointer-events="none"><line transform="translate(10,0)" x2="0" y2="5" stroke="#888" stroke-width="1" opacity="1"></line><line transform="translate(30,0)" x2="0" y2="5" stroke="#888" stroke-width="1" opacity="1"></line><line transform="translate(50,0)" x2="0" y2="5" stroke="#888" stroke-width="1" opacity="1"></line><line transform="translate(70,0)" x2="0" y2="5" stroke="#888" stroke-width="1" opacity="1"></line><line transform="translate(90,0)" x2="0" y2="5" stroke="#888" stroke-width="1" opacity="1"></line><line transform="translate(110,0)" x2="0" y2="5" stroke="#888" stroke-width="1" opacity="1"></line></g><g class="mark-text role-axis-label" pointer-events="none"><text text-anchor="end" transform="translate(9.5,7) rotate(270) translate(0,3)" font-family="sans-serif" font-size="10px" fill="#000" opacity="1">0</text><text text-anchor="end" transform="translate(29.5,7) rotate(270) translate(0,3)" font-family="sans-serif" font-size="10px" fill="#000" opacity="1">1</text><text text-anchor="end" transform="translate(49.5,7) rotate(270) translate(0,3)" font-family="sans-serif" font-size="10px" fill="#000" opacity="1">2</text><text text-anchor="end" transform="translate(69.5,7) rotate(270) translate(0,3)" font-family="sans-serif" font-size="10px" fill="#000" opacity="1">3</text><text text-anchor="end" transform="translate(89.5,7) rotate(270) translate(0,3)" font-family="sans-serif" font-size="10px" fill="#000" opacity="1">4</text><text text-anchor="end" transform="translate(109.5,7) rotate(270) translate(0,3)" font-family="sans-serif" font-size="10px" fill="#000" opacity="1">5</text></g><g class="mark-rule role-axis-domain" pointer-events="none"><line transform="translate(0,0)" x2="120" y2="0" stroke="#888" stroke-width="1" opacity="1"></line></g><g class="mark-text role-axis-title" pointer-events="none"><text text-anchor="middle" transform="translate(60,25.5615234375)" font-family="sans-serif" font-size="11px" font-weight="bold" fill="#000" opacity="1">x</text></g></g><path class="foreground" aria-hidden="true" d="" pointer-events="none" display="none"></path></g></g><g class="mark-group role-axis" role="graphics-symbol" aria-roledescription="axis" aria-label="Y-axis titled 'Sum of y' for a linear scale with values from 0 to 5"><g transform="translate(0.5,0.5)"><path class="background" aria-hidden="true" d="M0,0h0v0h0Z" pointer-events="none"></path><g><g class="mark-rule role-axis-tick" pointer-events="none"><line transform="translate(0,200)" x2="-5" y2="0" stroke="#888" stroke-width="1" opacity="1"></line><line transform="translate(0,160)" x2="-5" y2="0" stroke="#888" stroke-width="1" opacity="1"></line><line transform="translate(0,120)" x2="-5" y2="0" stroke="#888" stroke-width="1" opacity="1"></line><line transform="translate(0,80)" x2="-5" y2="0" stroke="#888" stroke-width="1" opacity="1"></line><line transform="translate(0,40)" x2="-5" y2="0" stroke="#888" stroke-width="1" opacity="1"></line><line transform="translate(0,0)" x2="-5" y2="0" stroke="#888" stroke-width="1" opacity="1"></line></g><g class="mark-text role-axis-label" pointer-events="none"><text text-anchor="end" transform="translate(-7,203)" font-family="sans-serif" font-size="10px" fill="#000" opacity="1">0</text><text text-anchor="end" transform="translate(-7,163)" font-family="sans-serif" font-size="10px" fill="#000" opacity="1">1</text><text text-anchor="end" transform="translate(-7,123)" font-family="sans-serif" font-size="10px" fill="#000" opacity="1">2</text><text text-anchor="end" transform="translate(-7,83)" font-family="sans-serif" font-size="10px" fill="#000" opacity="1">3</text><text text-anchor="end" transform="translate(-7,42.99999999999999)" font-family="sans-serif" font-size="10px" fill="#000" opacity="1">4</text><text text-anchor="end" transform="translate(-7,3)" font-family="sans-serif" font-size="10px" fill="#000" opacity="1">5</text></g><g class="mark-rule role-axis-domain" pointer-events="none"><line transform="translate(0,200)" x2="0" y2="-200" stroke="#888" stroke-width="1" opacity="1"></line></g><g class="mark-text role-axis-title" pointer-events="none"><text text-anchor="middle" transform="translate(-16.5615234375,100) rotate(-90) translate(0,-2)" font-family="sans-serif" font-size="11px" font-weight="bold" fill="#000" opacity="1">Sum of y</text></g></g><path class="foreground" aria-hidden="true" d="" pointer-events="none" display="none"></path></g></g><g class="mark-rect role-mark marks" role="graphics-object" aria-roledescription="rect mark container"><path aria-label="x: 0; Sum of y: 3; c: green" role="graphics-symbol" aria-roledescription="bar" d="M1,80h18v120h-18Z" fill="green"></path><path aria-label="x: 0; Sum of y: 0; c: blue" role="graphics-symbol" aria-roledescription="bar" d="M1,80h18v0h-18Z" fill="blue"></path><path aria-label="x: 1; Sum of y: 1; c: green" role="graphics-symbol" aria-roledescription="bar" d="M21,160h18v40h-18Z" fill="green"></path><path aria-label="x: 1; Sum of y: 2; c: blue" role="graphics-symbol" aria-roledescription="bar" d="M21,80h18v80h-18Z" fill="blue"></path><path aria-label="x: 2; Sum of y: 3; c: green" role="graphics-symbol" aria-roledescription="bar" d="M41,80h18v120h-18Z" fill="green"></path><path aria-label="x: 2; Sum of y: 0; c: blue" role="graphics-symbol" aria-roledescription="bar" d="M41,80h18v0h-18Z" fill="blue"></path><path aria-label="x: 3; Sum of y: 1; c: green" role="graphics-symbol" aria-roledescription="bar" d="M61,160h18v40h-18Z" fill="green"></path><path aria-label="x: 3; Sum of y: 2; c: blue" role="graphics-symbol" aria-roledescription="bar" d="M61,80h18v80h-18Z" fill="blue"></path><path aria-label="x: 4; Sum of y: 1; c: green" role="graphics-symbol" aria-roledescription="bar" d="M81,160h18v40h-18Z" fill="green"></path><path aria-label="x: 4; Sum of y: 2; c: blue" role="graphics-symbol" aria-roledescription="bar" d="M81,80h18v80h-18Z" fill="blue"></path><path aria-label="x: 5; Sum of y: 5; c: green" role="graphics-symbol" aria-roledescription="bar" d="M101,0h18v200h-18Z" fill="green"></path><path aria-label="x: 5; Sum of y: 0; c: blue" role="graphics-symbol" aria-roledescription="bar" d="M101,0h18v0h-18Z" fill="blue"></path></g></g><path class="foreground" aria-hidden="true" d="" display="none"></path></g></g></g></svg>
\ No newline at end of file diff --git a/challenge-079/tyler-wardhaugh/clojure/resources/t2.test3.svg b/challenge-079/tyler-wardhaugh/clojure/resources/t2.test3.svg new file mode 100644 index 0000000000..0eab4070e1 --- /dev/null +++ b/challenge-079/tyler-wardhaugh/clojure/resources/t2.test3.svg @@ -0,0 +1 @@ +<svg class="marks" width="178" height="243" viewBox="0 0 178 243" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"><rect width="178" height="243" fill="white"></rect><g fill="none" stroke-miterlimit="10" transform="translate(33,10)"><g class="mark-group role-frame root" role="graphics-object" aria-roledescription="group mark container"><g transform="translate(0,0)"><path class="background" aria-hidden="true" d="M0.5,0.5h140v200h-140Z" stroke="#ddd"></path><g><g class="mark-group role-axis" aria-hidden="true"><g transform="translate(0.5,0.5)"><path class="background" aria-hidden="true" d="M0,0h0v0h0Z" pointer-events="none"></path><g><g class="mark-rule role-axis-grid" pointer-events="none"><line transform="translate(0,200)" x2="140" y2="0" stroke="#ddd" stroke-width="1" opacity="1"></line><line transform="translate(0,150)" x2="140" y2="0" stroke="#ddd" stroke-width="1" opacity="1"></line><line transform="translate(0,100)" x2="140" y2="0" stroke="#ddd" stroke-width="1" opacity="1"></line><line transform="translate(0,50)" x2="140" y2="0" stroke="#ddd" stroke-width="1" opacity="1"></line><line transform="translate(0,0)" x2="140" y2="0" stroke="#ddd" stroke-width="1" opacity="1"></line></g></g><path class="foreground" aria-hidden="true" d="" pointer-events="none" display="none"></path></g></g><g class="mark-group role-axis" role="graphics-symbol" aria-roledescription="axis" aria-label="X-axis titled 'x' for a discrete scale with 7 values: 0, 1, 2, 3, 4, 5, 6"><g transform="translate(0.5,200.5)"><path class="background" aria-hidden="true" d="M0,0h0v0h0Z" pointer-events="none"></path><g><g class="mark-rule role-axis-tick" pointer-events="none"><line transform="translate(10,0)" x2="0" y2="5" stroke="#888" stroke-width="1" opacity="1"></line><line transform="translate(30,0)" x2="0" y2="5" stroke="#888" stroke-width="1" opacity="1"></line><line transform="translate(50,0)" x2="0" y2="5" stroke="#888" stroke-width="1" opacity="1"></line><line transform="translate(70,0)" x2="0" y2="5" stroke="#888" stroke-width="1" opacity="1"></line><line transform="translate(90,0)" x2="0" y2="5" stroke="#888" stroke-width="1" opacity="1"></line><line transform="translate(110,0)" x2="0" y2="5" stroke="#888" stroke-width="1" opacity="1"></line><line transform="translate(130,0)" x2="0" y2="5" stroke="#888" stroke-width="1" opacity="1"></line></g><g class="mark-text role-axis-label" pointer-events="none"><text text-anchor="end" transform="translate(9.5,7) rotate(270) translate(0,3)" font-family="sans-serif" font-size="10px" fill="#000" opacity="1">0</text><text text-anchor="end" transform="translate(29.5,7) rotate(270) translate(0,3)" font-family="sans-serif" font-size="10px" fill="#000" opacity="1">1</text><text text-anchor="end" transform="translate(49.5,7) rotate(270) translate(0,3)" font-family="sans-serif" font-size="10px" fill="#000" opacity="1">2</text><text text-anchor="end" transform="translate(69.5,7) rotate(270) translate(0,3)" font-family="sans-serif" font-size="10px" fill="#000" opacity="1">3</text><text text-anchor="end" transform="translate(89.5,7) rotate(270) translate(0,3)" font-family="sans-serif" font-size="10px" fill="#000" opacity="1">4</text><text text-anchor="end" transform="translate(109.5,7) rotate(270) translate(0,3)" font-family="sans-serif" font-size="10px" fill="#000" opacity="1">5</text><text text-anchor="end" transform="translate(129.5,7) rotate(270) translate(0,3)" font-family="sans-serif" font-size="10px" fill="#000" opacity="1">6</text></g><g class="mark-rule role-axis-domain" pointer-events="none"><line transform="translate(0,0)" x2="140" y2="0" stroke="#888" stroke-width="1" opacity="1"></line></g><g class="mark-text role-axis-title" pointer-events="none"><text text-anchor="middle" transform="translate(70,25.5615234375)" font-family="sans-serif" font-size="11px" font-weight="bold" fill="#000" opacity="1">x</text></g></g><path class="foreground" aria-hidden="true" d="" pointer-events="none" display="none"></path></g></g><g class="mark-group role-axis" role="graphics-symbol" aria-roledescription="axis" aria-label="Y-axis titled 'Sum of y' for a linear scale with values from 0 to 4"><g transform="translate(0.5,0.5)"><path class="background" aria-hidden="true" d="M0,0h0v0h0Z" pointer-events="none"></path><g><g class="mark-rule role-axis-tick" pointer-events="none"><line transform="translate(0,200)" x2="-5" y2="0" stroke="#888" stroke-width="1" opacity="1"></line><line transform="translate(0,150)" x2="-5" y2="0" stroke="#888" stroke-width="1" opacity="1"></line><line transform="translate(0,100)" x2="-5" y2="0" stroke="#888" stroke-width="1" opacity="1"></line><line transform="translate(0,50)" x2="-5" y2="0" stroke="#888" stroke-width="1" opacity="1"></line><line transform="translate(0,0)" x2="-5" y2="0" stroke="#888" stroke-width="1" opacity="1"></line></g><g class="mark-text role-axis-label" pointer-events="none"><text text-anchor="end" transform="translate(-7,203)" font-family="sans-serif" font-size="10px" fill="#000" opacity="1">0</text><text text-anchor="end" transform="translate(-7,153)" font-family="sans-serif" font-size="10px" fill="#000" opacity="1">1</text><text text-anchor="end" transform="translate(-7,103)" font-family="sans-serif" font-size="10px" fill="#000" opacity="1">2</text><text text-anchor="end" transform="translate(-7,53)" font-family="sans-serif" font-size="10px" fill="#000" opacity="1">3</text><text text-anchor="end" transform="translate(-7,3)" font-family="sans-serif" font-size="10px" fill="#000" opacity="1">4</text></g><g class="mark-rule role-axis-domain" pointer-events="none"><line transform="translate(0,200)" x2="0" y2="-200" stroke="#888" stroke-width="1" opacity="1"></line></g><g class="mark-text role-axis-title" pointer-events="none"><text text-anchor="middle" transform="translate(-16.5615234375,100) rotate(-90) translate(0,-2)" font-family="sans-serif" font-size="11px" font-weight="bold" fill="#000" opacity="1">Sum of y</text></g></g><path class="foreground" aria-hidden="true" d="" pointer-events="none" display="none"></path></g></g><g class="mark-rect role-mark marks" role="graphics-object" aria-roledescription="rect mark container"><path aria-label="x: 0; Sum of y: 1; c: green" role="graphics-symbol" aria-roledescription="bar" d="M1,150h18v50h-18Z" fill="green"></path><path aria-label="x: 0; Sum of y: 0; c: blue" role="graphics-symbol" aria-roledescription="bar" d="M1,150h18v0h-18Z" fill="blue"></path><path aria-label="x: 1; Sum of y: 2; c: green" role="graphics-symbol" aria-roledescription="bar" d="M21,100h18v100h-18Z" fill="green"></path><path aria-label="x: 1; Sum of y: 0; c: blue" role="graphics-symbol" aria-roledescription="bar" d="M21,100h18v0h-18Z" fill="blue"></path><path aria-label="x: 2; Sum of y: 3; c: green" role="graphics-symbol" aria-roledescription="bar" d="M41,50h18v150h-18Z" fill="green"></path><path aria-label="x: 2; Sum of y: 0; c: blue" role="graphics-symbol" aria-roledescription="bar" d="M41,50h18v0h-18Z" fill="blue"></path><path aria-label="x: 3; Sum of y: 4; c: green" role="graphics-symbol" aria-roledescription="bar" d="M61,0h18v200h-18Z" fill="green"></path><path aria-label="x: 3; Sum of y: 0; c: blue" role="graphics-symbol" aria-roledescription="bar" d="M61,0h18v0h-18Z" fill="blue"></path><path aria-label="x: 4; Sum of y: 3; c: green" role="graphics-symbol" aria-roledescription="bar" d="M81,50h18v150h-18Z" fill="green"></path><path aria-label="x: 4; Sum of y: 0; c: blue" role="graphics-symbol" aria-roledescription="bar" d="M81,50h18v0h-18Z" fill="blue"></path><path aria-label="x: 5; Sum of y: 2; c: green" role="graphics-symbol" aria-roledescription="bar" d="M101,100h18v100h-18Z" fill="green"></path><path aria-label="x: 5; Sum of y: 0; c: blue" role="graphics-symbol" aria-roledescription="bar" d="M101,100h18v0h-18Z" fill="blue"></path><path aria-label="x: 6; Sum of y: 1; c: green" role="graphics-symbol" aria-roledescription="bar" d="M121,150h18v50h-18Z" fill="green"></path><path aria-label="x: 6; Sum of y: 0; c: blue" role="graphics-symbol" aria-roledescription="bar" d="M121,150h18v0h-18Z" fill="blue"></path></g></g><path class="foreground" aria-hidden="true" d="" display="none"></path></g></g></g></svg>
\ No newline at end of file diff --git a/challenge-079/tyler-wardhaugh/clojure/resources/t2.test4.svg b/challenge-079/tyler-wardhaugh/clojure/resources/t2.test4.svg new file mode 100644 index 0000000000..64d9cdd5e6 --- /dev/null +++ b/challenge-079/tyler-wardhaugh/clojure/resources/t2.test4.svg @@ -0,0 +1 @@ +<svg class="marks" width="224" height="243" viewBox="0 0 224 243" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"><rect width="224" height="243" fill="white"></rect><g fill="none" stroke-miterlimit="10" transform="translate(39,10)"><g class="mark-group role-frame root" role="graphics-object" aria-roledescription="group mark container"><g transform="translate(0,0)"><path class="background" aria-hidden="true" d="M0.5,0.5h180v200h-180Z" stroke="#ddd"></path><g><g class="mark-group role-axis" aria-hidden="true"><g transform="translate(0.5,0.5)"><path class="background" aria-hidden="true" d="M0,0h0v0h0Z" pointer-events="none"></path><g><g class="mark-rule role-axis-grid" pointer-events="none"><line transform="translate(0,200)" x2="180" y2="0" stroke="#ddd" stroke-width="1" opacity="1"></line><line transform="translate(0,160)" x2="180" y2="0" stroke="#ddd" stroke-width="1" opacity="1"></line><line transform="translate(0,120)" x2="180" y2="0" stroke="#ddd" stroke-width="1" opacity="1"></line><line transform="translate(0,80)" x2="180" y2="0" stroke="#ddd" stroke-width="1" opacity="1"></line><line transform="translate(0,40)" x2="180" y2="0" stroke="#ddd" stroke-width="1" opacity="1"></line><line transform="translate(0,0)" x2="180" y2="0" stroke="#ddd" stroke-width="1" opacity="1"></line></g></g><path class="foreground" aria-hidden="true" d="" pointer-events="none" display="none"></path></g></g><g class="mark-group role-axis" role="graphics-symbol" aria-roledescription="axis" aria-label="X-axis titled 'x' for a discrete scale with 9 values: 0, 1, 2, 3, 4, ending with 8"><g transform="translate(0.5,200.5)"><path class="background" aria-hidden="true" d="M0,0h0v0h0Z" pointer-events="none"></path><g><g class="mark-rule role-axis-tick" pointer-events="none"><line transform="translate(10,0)" x2="0" y2="5" stroke="#888" stroke-width="1" opacity="1"></line><line transform="translate(30,0)" x2="0" y2="5" stroke="#888" stroke-width="1" opacity="1"></line><line transform="translate(50,0)" x2="0" y2="5" stroke="#888" stroke-width="1" opacity="1"></line><line transform="translate(70,0)" x2="0" y2="5" stroke="#888" stroke-width="1" opacity="1"></line><line transform="translate(90,0)" x2="0" y2="5" stroke="#888" stroke-width="1" opacity="1"></line><line transform="translate(110,0)" x2="0" y2="5" stroke="#888" stroke-width="1" opacity="1"></line><line transform="translate(130,0)" x2="0" y2="5" stroke="#888" stroke-width="1" opacity="1"></line><line transform="translate(150,0)" x2="0" y2="5" stroke="#888" stroke-width="1" opacity="1"></line><line transform="translate(170,0)" x2="0" y2="5" stroke="#888" stroke-width="1" opacity="1"></line></g><g class="mark-text role-axis-label" pointer-events="none"><text text-anchor="end" transform="translate(9.5,7) rotate(270) translate(0,3)" font-family="sans-serif" font-size="10px" fill="#000" opacity="1">0</text><text text-anchor="end" transform="translate(29.5,7) rotate(270) translate(0,3)" font-family="sans-serif" font-size="10px" fill="#000" opacity="1">1</text><text text-anchor="end" transform="translate(49.5,7) rotate(270) translate(0,3)" font-family="sans-serif" font-size="10px" fill="#000" opacity="1">2</text><text text-anchor="end" transform="translate(69.5,7) rotate(270) translate(0,3)" font-family="sans-serif" font-size="10px" fill="#000" opacity="1">3</text><text text-anchor="end" transform="translate(89.5,7) rotate(270) translate(0,3)" font-family="sans-serif" font-size="10px" fill="#000" opacity="1">4</text><text text-anchor="end" transform="translate(109.5,7) rotate(270) translate(0,3)" font-family="sans-serif" font-size="10px" fill="#000" opacity="1">5</text><text text-anchor="end" transform="translate(129.5,7) rotate(270) translate(0,3)" font-family="sans-serif" font-size="10px" fill="#000" opacity="1">6</text><text text-anchor="end" transform="translate(149.5,7) rotate(270) translate(0,3)" font-family="sans-serif" font-size="10px" fill="#000" opacity="1">7</text><text text-anchor="end" transform="translate(169.5,7) rotate(270) translate(0,3)" font-family="sans-serif" font-size="10px" fill="#000" opacity="1">8</text></g><g class="mark-rule role-axis-domain" pointer-events="none"><line transform="translate(0,0)" x2="180" y2="0" stroke="#888" stroke-width="1" opacity="1"></line></g><g class="mark-text role-axis-title" pointer-events="none"><text text-anchor="middle" transform="translate(90,25.5615234375)" font-family="sans-serif" font-size="11px" font-weight="bold" fill="#000" opacity="1">x</text></g></g><path class="foreground" aria-hidden="true" d="" pointer-events="none" display="none"></path></g></g><g class="mark-group role-axis" role="graphics-symbol" aria-roledescription="axis" aria-label="Y-axis titled 'Sum of y' for a linear scale with values from 0 to 10"><g transform="translate(0.5,0.5)"><path class="background" aria-hidden="true" d="M0,0h0v0h0Z" pointer-events="none"></path><g><g class="mark-rule role-axis-tick" pointer-events="none"><line transform="translate(0,200)" x2="-5" y2="0" stroke="#888" stroke-width="1" opacity="1"></line><line transform="translate(0,160)" x2="-5" y2="0" stroke="#888" stroke-width="1" opacity="1"></line><line transform="translate(0,120)" x2="-5" y2="0" stroke="#888" stroke-width="1" opacity="1"></line><line transform="translate(0,80)" x2="-5" y2="0" stroke="#888" stroke-width="1" opacity="1"></line><line transform="translate(0,40)" x2="-5" y2="0" stroke="#888" stroke-width="1" opacity="1"></line><line transform="translate(0,0)" x2="-5" y2="0" stroke="#888" stroke-width="1" opacity="1"></line></g><g class="mark-text role-axis-label" pointer-events="none"><text text-anchor="end" transform="translate(-7,203)" font-family="sans-serif" font-size="10px" fill="#000" opacity="1">0</text><text text-anchor="end" transform="translate(-7,163)" font-family="sans-serif" font-size="10px" fill="#000" opacity="1">2</text><text text-anchor="end" transform="translate(-7,123)" font-family="sans-serif" font-size="10px" fill="#000" opacity="1">4</text><text text-anchor="end" transform="translate(-7,83)" font-family="sans-serif" font-size="10px" fill="#000" opacity="1">6</text><text text-anchor="end" transform="translate(-7,42.99999999999999)" font-family="sans-serif" font-size="10px" fill="#000" opacity="1">8</text><text text-anchor="end" transform="translate(-7,3)" font-family="sans-serif" font-size="10px" fill="#000" opacity="1">10</text></g><g class="mark-rule role-axis-domain" pointer-events="none"><line transform="translate(0,200)" x2="0" y2="-200" stroke="#888" stroke-width="1" opacity="1"></line></g><g class="mark-text role-axis-title" pointer-events="none"><text text-anchor="middle" transform="translate(-22.123046875,100) rotate(-90) translate(0,-2)" font-family="sans-serif" font-size="11px" font-weight="bold" fill="#000" opacity="1">Sum of y</text></g></g><path class="foreground" aria-hidden="true" d="" pointer-events="none" display="none"></path></g></g><g class="mark-rect role-mark marks" role="graphics-object" aria-roledescription="rect mark container"><path aria-label="x: 0; Sum of y: 4; c: green" role="graphics-symbol" aria-roledescription="bar" d="M1,120h18v80h-18Z" fill="green"></path><path aria-label="x: 0; Sum of y: 0; c: blue" role="graphics-symbol" aria-roledescription="bar" d="M1,120h18v0h-18Z" fill="blue"></path><path aria-label="x: 1; Sum of y: 1; c: green" role="graphics-symbol" aria-roledescription="bar" d="M21,180h18v20h-18Z" fill="green"></path><path aria-label="x: 1; Sum of y: 3; c: blue" role="graphics-symbol" aria-roledescription="bar" d="M21,120h18v60h-18Z" fill="blue"></path><path aria-label="x: 2; Sum of y: 3; c: green" role="graphics-symbol" aria-roledescription="bar" d="M41,140h18v60h-18Z" fill="green"></path><path aria-label="x: 2; Sum of y: 1; c: blue" role="graphics-symbol" aria-roledescription="bar" d="M41,120h18v20h-18Z" fill="blue"></path><path aria-label="x: 3; Sum of y: 1; c: green" role="graphics-symbol" aria-roledescription="bar" d="M61,180h18v20h-18Z" fill="green"></path><path aria-label="x: 3; Sum of y: 3; c: blue" role="graphics-symbol" aria-roledescription="bar" d="M61,120h18v60h-18Z" fill="blue"></path><path aria-label="x: 4; Sum of y: 2; c: green" role="graphics-symbol" aria-roledescription="bar" d="M81,160h18v40h-18Z" fill="green"></path><path aria-label="x: 4; Sum of y: 2; c: blue" role="graphics-symbol" aria-roledescription="bar" d="M81,120h18v40h-18Z" fill="blue"></path><path aria-label="x: 5; Sum of y: 5; c: green" role="graphics-symbol" aria-roledescription="bar" d="M101,100h18v100h-18Z" fill="green"></path><path aria-label="x: 5; Sum of y: 0; c: blue" role="graphics-symbol" aria-roledescription="bar" d="M101,100h18v0h-18Z" fill="blue"></path><path aria-label="x: 6; Sum of y: 10; c: green" role="graphics-symbol" aria-roledescription="bar" d="M121,0h18v200h-18Z" fill="green"></path><path aria-label="x: 6; Sum of y: 0; c: blue" role="graphics-symbol" aria-roledescription="bar" d="M121,0h18v0h-18Z" fill="blue"></path><path aria-label="x: 7; Sum of y: 5; c: green" role="graphics-symbol" aria-roledescription="bar" d="M141,100h18v100h-18Z" fill="green"></path><path aria-label="x: 7; Sum of y: 2; c: blue" role="graphics-symbol" aria-roledescription="bar" d="M141,60.00000000000001h18v39.99999999999999h-18Z" fill="blue"></path><path aria-label="x: 8; Sum of y: 7; c: green" role="graphics-symbol" aria-roledescription="bar" d="M161,60.00000000000001h18v140h-18Z" fill="green"></path><path aria-label="x: 8; Sum of y: 0; c: blue" role="graphics-symbol" aria-roledescription="bar" d="M161,60.00000000000001h18v0h-18Z" fill="blue"></path></g></g><path class="foreground" aria-hidden="true" d="" display="none"></path></g></g></g></svg>
\ No newline at end of file diff --git a/challenge-079/tyler-wardhaugh/clojure/src/tw/weekly/c79/t2.clj b/challenge-079/tyler-wardhaugh/clojure/src/tw/weekly/c79/t2.clj index dc08a1106c..45513901c1 100644 --- a/challenge-079/tyler-wardhaugh/clojure/src/tw/weekly/c79/t2.clj +++ b/challenge-079/tyler-wardhaugh/clojure/src/tw/weekly/c79/t2.clj @@ -1,10 +1,59 @@ (ns tw.weekly.c79.t2 - (:require [clojure.pprint :refer [cl-format]]) - (:require [clojure.edn :as edn])) + (:require [clojure.edn :as edn]) + (:require [oz.core :as oz])) -;;; Task description for TASK #2 › +;;; Task description for TASK #2 › Trapped Rain Water +; You are given an array of positive numbers @N. +; +; Write a script to represent it as Histogram Chart and find out how much water it can trap. +; +; Example 1: +; Input: @N = (2, 1, 4, 1, 2, 5) +; The histogram representation of the given array is as below. +; 5 # +; 4 # # +; 3 # # +; 2 # # # # +; 1 # # # # # # +; _ _ _ _ _ _ _ +; 2 1 4 1 2 5 ;;; +(defn splits + "Partition the input by splitting it at each index, ensuring partitions contain at least one element." + [coll] + (map #(split-at % coll) (range 1 (dec (count coll))))) + +(defn calculate-pools + "Returns a sequence of pools, which are the amount of water 'units' that can be held at the inner elements of the coll, when viewed as a histogram." + [coll] + (let [neighboring-maxes (fn [[l [c & r]]] [(apply max l) c (apply max r)]) + to-water (fn [[l c r]] (max (- (min l r) c) 0))] + (->> (splits coll) + (eduction (map neighboring-maxes) (map to-water))))) + +(defn capacity + "Calculates the total capacity of the pools" + [pools] + (reduce + 0 pools)) + +(defn draw-histogram + "Vizualize the histogram, using Oz (which uses Vega-Lite & Vega)" + ([coll] (draw-histogram coll (calculate-pools coll))) + ([coll pools] (let [make-hashes (fn [x land water] (list (hash-map :x x :y land :c "green") (hash-map :x x :y water :c "blue"))) + values (mapcat make-hashes (range) coll (concat [0] pools [0]))] + (oz/view! {:data {:values values} + :encoding {:x {:field :x :type "ordinal"} + :y {:field :y :type "quantitative" :aggregate "sum"} + :color {:field :c + :type "nominal" + :scale nil}} + :mark "bar"})))) + (defn -main [& args] - ) + (let [N (or (some->> args (map edn/read-string)) [2 1 4 1 2 5]) + pools (calculate-pools N)] + (println (capacity pools)) + (oz/start-server!) + (draw-histogram N pools))) diff --git a/challenge-079/tyler-wardhaugh/clojure/test/tw/weekly/c79_test.clj b/challenge-079/tyler-wardhaugh/clojure/test/tw/weekly/c79_test.clj index 30f26ba18c..2b0efafdfc 100644 --- a/challenge-079/tyler-wardhaugh/clojure/test/tw/weekly/c79_test.clj +++ b/challenge-079/tyler-wardhaugh/clojure/test/tw/weekly/c79_test.clj @@ -1,7 +1,7 @@ (ns tw.weekly.c79-test (:require [clojure.test :refer [deftest is testing]] - [tw.weekly.c79.t2 :refer []])) [tw.weekly.c79.t1 :refer [run]] + [tw.weekly.c79.t2 :refer [calculate-pools capacity]])) (deftest task-1 (testing "Task 1, Count Set Bits" @@ -9,5 +9,8 @@ (is (= (run 3) 4))))) (deftest task-2 - (testing "" - )) + (testing "Task 2, Trapped Rain Water" + (is (= (capacity (calculate-pools [2 1 4 1 2 5])) 6)) + (is (= (capacity (calculate-pools [3 1 3 1 1 5])) 6)) + (is (= (capacity (calculate-pools [1 2 3 4 5 4 3 2 1])) 0)) + (is (= (capacity (calculate-pools [4 1 3 1 2 5 10 5 7])) 11)))) |
