trackler 2.2.0.4 → 2.2.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/trackler/version.rb +1 -1
- data/tracks/bash/config.json +10 -2
- data/tracks/bash/exercises/word-count/example.awk +12 -0
- data/tracks/bash/exercises/word-count/example.sh +21 -0
- data/tracks/c/config.json +0 -2
- data/tracks/ceylon/config.json +0 -2
- data/tracks/{erlang/exercises/all-your-base/.meta/readme.go.tmpl → clojure/config/exercise_readme.go.tmpl} +0 -1
- data/tracks/clojure/exercises/accumulate/README.md +35 -0
- data/tracks/clojure/exercises/acronym/README.md +15 -0
- data/tracks/clojure/exercises/all-your-base/README.md +35 -0
- data/tracks/clojure/exercises/allergies/README.md +37 -0
- data/tracks/clojure/exercises/anagram/README.md +13 -0
- data/tracks/clojure/exercises/atbash-cipher/README.md +34 -0
- data/tracks/clojure/exercises/bank-account/README.md +30 -0
- data/tracks/clojure/exercises/beer-song/README.md +327 -0
- data/tracks/clojure/exercises/binary/README.md +35 -0
- data/tracks/clojure/exercises/binary-search/README.md +41 -0
- data/tracks/clojure/exercises/binary-search-tree/README.md +60 -0
- data/tracks/clojure/exercises/bob/README.md +18 -0
- data/tracks/clojure/exercises/bracket-push/README.md +10 -0
- data/tracks/clojure/exercises/change/README.md +23 -0
- data/tracks/clojure/exercises/clock/README.md +13 -0
- data/tracks/clojure/exercises/crypto-square/README.md +74 -0
- data/tracks/clojure/exercises/difference-of-squares/README.md +19 -0
- data/tracks/clojure/exercises/etl/README.md +51 -0
- data/tracks/clojure/exercises/flatten-array/README.md +18 -0
- data/tracks/clojure/exercises/gigasecond/README.md +11 -0
- data/tracks/clojure/exercises/grade-school/README.md +42 -0
- data/tracks/clojure/exercises/grains/README.md +34 -0
- data/tracks/clojure/exercises/hamming/README.md +42 -0
- data/tracks/clojure/exercises/hello-world/README.md +51 -0
- data/tracks/clojure/exercises/hexadecimal/README.md +14 -0
- data/tracks/clojure/exercises/isogram/README.md +19 -0
- data/tracks/clojure/exercises/kindergarten-garden/README.md +66 -0
- data/tracks/clojure/exercises/largest-series-product/README.md +20 -0
- data/tracks/clojure/exercises/leap/README.md +33 -0
- data/tracks/clojure/exercises/luhn/README.md +71 -0
- data/tracks/clojure/exercises/meetup/README.md +30 -0
- data/tracks/clojure/exercises/minesweeper/README.md +30 -0
- data/tracks/clojure/exercises/nth-prime/README.md +15 -0
- data/tracks/clojure/exercises/nucleotide-count/README.md +33 -0
- data/tracks/clojure/exercises/octal/README.md +49 -0
- data/tracks/clojure/exercises/pangram/README.md +15 -0
- data/tracks/clojure/exercises/pascals-triangle/README.md +21 -0
- data/tracks/clojure/exercises/perfect-numbers/README.md +24 -0
- data/tracks/clojure/exercises/phone-number/README.md +34 -0
- data/tracks/clojure/exercises/pig-latin/README.md +24 -0
- data/tracks/clojure/exercises/pov/README.md +46 -0
- data/tracks/clojure/exercises/prime-factors/README.md +36 -0
- data/tracks/clojure/exercises/queen-attack/README.md +33 -0
- data/tracks/clojure/exercises/raindrops/README.md +24 -0
- data/tracks/clojure/exercises/rna-transcription/README.md +25 -0
- data/tracks/clojure/exercises/robot-name/README.md +22 -0
- data/tracks/clojure/exercises/robot-simulator/README.md +34 -0
- data/tracks/clojure/exercises/roman-numerals/README.md +49 -0
- data/tracks/clojure/exercises/rotational-cipher/README.md +36 -0
- data/tracks/clojure/exercises/scrabble-score/README.md +44 -0
- data/tracks/clojure/exercises/secret-handshake/README.md +35 -0
- data/tracks/clojure/exercises/sieve/README.md +34 -0
- data/tracks/clojure/exercises/space-age/README.md +24 -0
- data/tracks/clojure/exercises/strain/README.md +40 -0
- data/tracks/clojure/exercises/sublist/README.md +21 -0
- data/tracks/clojure/exercises/sum-of-multiples/README.md +18 -0
- data/tracks/clojure/exercises/triangle/README.md +26 -0
- data/tracks/clojure/exercises/trinary/README.md +28 -0
- data/tracks/clojure/exercises/word-count/README.md +19 -0
- data/tracks/clojure/exercises/wordy/README.md +63 -0
- data/tracks/{erlang/exercises/allergies/.meta/readme.go.tmpl → crystal/config/exercise_readme.go.tmpl} +0 -1
- data/tracks/crystal/config.json +0 -2
- data/tracks/crystal/exercises/acronym/README.md +38 -0
- data/tracks/crystal/exercises/anagram/README.md +36 -0
- data/tracks/crystal/exercises/atbash-cipher/README.md +57 -0
- data/tracks/crystal/exercises/binary/README.md +58 -0
- data/tracks/crystal/exercises/binary-search-tree/README.md +83 -0
- data/tracks/crystal/exercises/bob/README.md +41 -0
- data/tracks/crystal/exercises/bracket-push/README.md +33 -0
- data/tracks/crystal/exercises/difference-of-squares/README.md +42 -0
- data/tracks/crystal/exercises/flatten-array/README.md +41 -0
- data/tracks/crystal/exercises/forth/README.md +52 -0
- data/tracks/crystal/exercises/gigasecond/README.md +34 -0
- data/tracks/crystal/exercises/hamming/README.md +65 -0
- data/tracks/crystal/exercises/hello-world/README.md +78 -0
- data/tracks/crystal/exercises/largest-series-product/README.md +43 -0
- data/tracks/crystal/exercises/leap/README.md +56 -0
- data/tracks/crystal/exercises/pangram/README.md +38 -0
- data/tracks/crystal/exercises/pascals-triangle/README.md +44 -0
- data/tracks/crystal/exercises/raindrops/README.md +47 -0
- data/tracks/crystal/exercises/react/README.md +42 -0
- data/tracks/crystal/exercises/rna-transcription/README.md +48 -0
- data/tracks/crystal/exercises/roman-numerals/README.md +72 -0
- data/tracks/crystal/exercises/run-length-encoding/README.md +53 -0
- data/tracks/crystal/exercises/sieve/README.md +57 -0
- data/tracks/csharp/config.json +0 -2
- data/tracks/delphi/config.json +0 -2
- data/tracks/ecmascript/config.json +63 -2
- data/tracks/erlang/{exercises/anagram/.meta/readme.go.tmpl → config/exercise_readme.go.tmpl} +0 -1
- data/tracks/erlang/config.json +0 -2
- data/tracks/erlang/exercises/accumulate/README.md +0 -1
- data/tracks/erlang/exercises/all-your-base/README.md +0 -1
- data/tracks/erlang/exercises/allergies/README.md +0 -1
- data/tracks/erlang/exercises/anagram/README.md +0 -1
- data/tracks/erlang/exercises/atbash-cipher/README.md +0 -1
- data/tracks/erlang/exercises/bank-account/README.md +0 -1
- data/tracks/erlang/exercises/beer-song/README.md +0 -1
- data/tracks/erlang/exercises/bob/README.md +0 -1
- data/tracks/erlang/exercises/circular-buffer/README.md +0 -1
- data/tracks/erlang/exercises/clock/README.md +0 -1
- data/tracks/erlang/exercises/collatz-conjecture/README.md +0 -1
- data/tracks/erlang/exercises/difference-of-squares/README.md +0 -1
- data/tracks/erlang/exercises/etl/README.md +0 -1
- data/tracks/erlang/exercises/gigasecond/README.md +0 -1
- data/tracks/erlang/exercises/grade-school/README.md +0 -1
- data/tracks/erlang/exercises/grains/README.md +0 -1
- data/tracks/erlang/exercises/hamming/README.md +0 -1
- data/tracks/erlang/exercises/hello-world/README.md +0 -1
- data/tracks/erlang/exercises/largest-series-product/README.md +0 -1
- data/tracks/erlang/exercises/leap/README.md +0 -1
- data/tracks/erlang/exercises/luhn/README.md +0 -1
- data/tracks/erlang/exercises/meetup/README.md +0 -1
- data/tracks/erlang/exercises/nucleotide-count/README.md +0 -1
- data/tracks/erlang/exercises/parallel-letter-frequency/README.md +0 -1
- data/tracks/erlang/exercises/phone-number/README.md +0 -1
- data/tracks/erlang/exercises/rna-transcription/README.md +0 -1
- data/tracks/erlang/exercises/robot-simulator/README.md +0 -1
- data/tracks/erlang/exercises/roman-numerals/README.md +0 -1
- data/tracks/erlang/exercises/rotational-cipher/README.md +0 -1
- data/tracks/erlang/exercises/scrabble-score/README.md +0 -1
- data/tracks/erlang/exercises/series/README.md +0 -1
- data/tracks/erlang/exercises/space-age/README.md +0 -1
- data/tracks/erlang/exercises/spiral-matrix/README.md +0 -1
- data/tracks/erlang/exercises/strain/README.md +0 -1
- data/tracks/erlang/exercises/sum-of-multiples/README.md +0 -1
- data/tracks/erlang/exercises/triangle/README.md +0 -1
- data/tracks/erlang/exercises/word-count/README.md +0 -1
- data/tracks/erlang/exercises/zipper/README.md +0 -1
- data/tracks/factor/config.json +0 -2
- data/tracks/fsharp/config.json +0 -2
- data/tracks/go/config.json +12 -6
- data/tracks/go/exercises/bank-account/bank_account_test.go +60 -1
- data/tracks/go/exercises/error-handling/common.go +17 -0
- data/tracks/go/exercises/error-handling/error_handling_test.go +37 -4
- data/tracks/haskell/config.json +0 -2
- data/tracks/java/config.json +10 -2
- data/tracks/{erlang/exercises/accumulate → java/exercises/forth}/.meta/readme.go.tmpl +0 -0
- data/tracks/java/exercises/forth/README.md +41 -0
- data/tracks/java/exercises/forth/build.gradle +18 -0
- data/tracks/java/exercises/forth/src/example/java/ForthEvaluator.java +154 -0
- data/tracks/java/exercises/forth/src/example/java/Token.java +90 -0
- data/tracks/java/exercises/forth/src/main/java/.keep +0 -0
- data/tracks/java/exercises/forth/src/test/java/ForthEvaluatorTest.java +355 -0
- data/tracks/java/exercises/settings.gradle +1 -0
- data/tracks/javascript/config.json +0 -2
- data/tracks/kotlin/config.json +30 -2
- data/tracks/kotlin/exercises/forth/README.md +32 -0
- data/tracks/kotlin/exercises/forth/build.gradle +28 -0
- data/tracks/kotlin/exercises/forth/src/example/kotlin/ForthEvaluator.kt +138 -0
- data/tracks/kotlin/exercises/forth/src/main/kotlin/.keep +0 -0
- data/tracks/kotlin/exercises/forth/src/test/kotlin/ForthEvaluatorTest.kt +352 -0
- data/tracks/kotlin/exercises/meetup/README.md +33 -0
- data/tracks/kotlin/exercises/meetup/build.gradle +28 -0
- data/tracks/kotlin/exercises/meetup/src/example/kotlin/Meetup.kt +45 -0
- data/tracks/kotlin/exercises/meetup/src/example/kotlin/MeetupSchedule.kt +1 -0
- data/tracks/kotlin/exercises/meetup/src/main/kotlin/MeetupSchedule.kt +5 -0
- data/tracks/kotlin/exercises/meetup/src/test/kotlin/MeetupTest.kt +771 -0
- data/tracks/kotlin/exercises/say/README.md +72 -0
- data/tracks/kotlin/exercises/say/build.gradle +28 -0
- data/tracks/kotlin/exercises/say/src/example/kotlin/NumberSpeller.kt +88 -0
- data/tracks/kotlin/exercises/say/src/main/kotlin/.keep +0 -0
- data/tracks/kotlin/exercises/say/src/test/kotlin/NumberSpellerTest.kt +138 -0
- data/tracks/kotlin/exercises/settings.gradle +3 -0
- data/tracks/lua/config.json +0 -2
- data/tracks/mips/config.json +0 -2
- data/tracks/ocaml/config.json +0 -2
- data/tracks/perl5/config.json +262 -67
- data/tracks/perl6/config.json +98 -26
- data/tracks/php/docs/INSTALLATION.md +1 -1
- data/tracks/powershell/config.json +0 -2
- data/tracks/purescript/config.json +0 -2
- data/tracks/python/README.md +2 -2
- data/tracks/python/config/exercise_readme.go.tmpl +16 -0
- data/tracks/python/config.json +280 -15
- data/tracks/python/exercises/accumulate/README.md +46 -0
- data/tracks/python/exercises/acronym/README.md +26 -0
- data/tracks/python/exercises/all-your-base/README.md +46 -0
- data/tracks/python/exercises/allergies/README.md +48 -0
- data/tracks/python/exercises/alphametics/README.md +46 -0
- data/tracks/python/exercises/anagram/README.md +24 -0
- data/tracks/python/exercises/atbash-cipher/README.md +45 -0
- data/tracks/python/exercises/beer-song/README.md +338 -0
- data/tracks/python/exercises/binary/README.md +46 -0
- data/tracks/python/exercises/binary-search/README.md +52 -0
- data/tracks/python/exercises/bob/README.md +29 -0
- data/tracks/python/exercises/book-store/README.md +85 -0
- data/tracks/python/exercises/bracket-push/README.md +21 -0
- data/tracks/python/exercises/circular-buffer/README.md +61 -0
- data/tracks/python/exercises/clock/README.md +24 -0
- data/tracks/python/exercises/crypto-square/README.md +85 -0
- data/tracks/python/exercises/diamond/README.md +70 -0
- data/tracks/python/exercises/difference-of-squares/README.md +30 -0
- data/tracks/python/exercises/etl/README.md +62 -0
- data/tracks/python/exercises/flatten-array/README.md +29 -0
- data/tracks/python/exercises/gigasecond/README.md +22 -0
- data/tracks/python/exercises/grade-school/README.md +53 -0
- data/tracks/python/exercises/grains/README.md +45 -0
- data/tracks/python/exercises/grep/README.md +82 -0
- data/tracks/python/exercises/hamming/README.md +53 -0
- data/tracks/python/exercises/hello-world/README.md +32 -0
- data/tracks/python/exercises/hexadecimal/README.md +25 -0
- data/tracks/python/exercises/house/README.md +124 -0
- data/tracks/python/exercises/isogram/README.md +30 -0
- data/tracks/python/exercises/kindergarten-garden/README.md +77 -0
- data/tracks/python/exercises/largest-series-product/README.md +31 -0
- data/tracks/python/exercises/leap/README.md +44 -0
- data/tracks/python/exercises/linked-list/README.md +45 -0
- data/tracks/python/exercises/list-ops/README.md +21 -0
- data/tracks/python/exercises/luhn/README.md +82 -0
- data/tracks/python/exercises/matrix/README.md +56 -0
- data/tracks/python/exercises/meetup/README.md +41 -0
- data/tracks/python/exercises/minesweeper/README.md +41 -0
- data/tracks/python/exercises/nth-prime/README.md +26 -0
- data/tracks/python/exercises/nucleotide-count/README.md +44 -0
- data/tracks/python/exercises/ocr-numbers/README.md +96 -0
- data/tracks/python/exercises/octal/README.md +60 -0
- data/tracks/python/exercises/palindrome-products/README.md +51 -0
- data/tracks/python/exercises/pangram/README.md +26 -0
- data/tracks/python/exercises/pascals-triangle/README.md +32 -0
- data/tracks/python/exercises/perfect-numbers/README.md +35 -0
- data/tracks/python/exercises/phone-number/README.md +45 -0
- data/tracks/python/exercises/pig-latin/README.md +35 -0
- data/tracks/python/exercises/point-mutations/README.md +52 -0
- data/tracks/python/exercises/poker/README.md +23 -0
- data/tracks/python/exercises/prime-factors/README.md +47 -0
- data/tracks/python/exercises/protein-translation/README.md +60 -0
- data/tracks/python/exercises/proverb/README.md +29 -0
- data/tracks/python/exercises/pythagorean-triplet/README.md +35 -0
- data/tracks/python/exercises/queen-attack/README.md +44 -0
- data/tracks/python/exercises/rail-fence-cipher/README.md +71 -0
- data/tracks/python/exercises/raindrops/README.md +35 -0
- data/tracks/python/exercises/rectangles/README.md +78 -0
- data/tracks/python/exercises/rna-transcription/README.md +36 -0
- data/tracks/python/exercises/robot-name/README.md +33 -0
- data/tracks/python/exercises/robot-simulator/README.md +45 -0
- data/tracks/python/exercises/roman-numerals/README.md +60 -0
- data/tracks/python/exercises/rotational-cipher/README.md +47 -0
- data/tracks/python/exercises/run-length-encoding/README.md +41 -0
- data/tracks/python/exercises/saddle-points/README.md +44 -0
- data/tracks/python/exercises/say/README.md +80 -0
- data/tracks/python/exercises/scale-generator/README.md +71 -0
- data/tracks/python/exercises/scrabble-score/README.md +55 -0
- data/tracks/python/exercises/secret-handshake/README.md +46 -0
- data/tracks/python/exercises/series/README.md +38 -0
- data/tracks/python/exercises/sieve/README.md +45 -0
- data/tracks/python/exercises/simple-cipher/README.md +101 -0
- data/tracks/python/exercises/space-age/README.md +35 -0
- data/tracks/python/exercises/strain/README.md +51 -0
- data/tracks/python/exercises/sublist/README.md +32 -0
- data/tracks/python/exercises/sum-of-multiples/README.md +29 -0
- data/tracks/python/exercises/tournament/README.md +79 -0
- data/tracks/python/exercises/transpose/README.md +76 -0
- data/tracks/python/exercises/triangle/README.md +37 -0
- data/tracks/python/exercises/trinary/README.md +39 -0
- data/tracks/python/exercises/twelve-days/README.md +46 -0
- data/tracks/python/exercises/variable-length-quantity/README.md +50 -0
- data/tracks/python/exercises/word-count/README.md +30 -0
- data/tracks/python/exercises/word-search/README.md +41 -0
- data/tracks/python/exercises/wordy/README.md +74 -0
- data/tracks/python/exercises/zebra-puzzle/README.md +43 -0
- data/tracks/python/test/check-exercises.py +2 -3
- data/tracks/r/config.json +0 -2
- data/tracks/ruby/.travis.yml +1 -1
- data/tracks/ruby/config/exercise_readme.go.tmpl +16 -0
- data/tracks/ruby/config.json +265 -4
- data/tracks/ruby/exercises/accumulate/README.md +76 -0
- data/tracks/ruby/exercises/acronym/README.md +41 -0
- data/tracks/ruby/exercises/all-your-base/README.md +61 -0
- data/tracks/ruby/exercises/allergies/README.md +63 -0
- data/tracks/ruby/exercises/alphametics/README.md +61 -0
- data/tracks/ruby/exercises/anagram/README.md +39 -0
- data/tracks/ruby/exercises/atbash-cipher/README.md +60 -0
- data/tracks/ruby/exercises/beer-song/README.md +353 -0
- data/tracks/ruby/exercises/binary/README.md +61 -0
- data/tracks/ruby/exercises/binary-search/README.md +67 -0
- data/tracks/ruby/exercises/binary-search-tree/README.md +86 -0
- data/tracks/ruby/exercises/bob/README.md +44 -0
- data/tracks/ruby/exercises/bowling/README.md +79 -0
- data/tracks/ruby/exercises/bracket-push/README.md +36 -0
- data/tracks/ruby/exercises/circular-buffer/README.md +76 -0
- data/tracks/ruby/exercises/clock/README.md +39 -0
- data/tracks/ruby/exercises/collatz-conjecture/README.md +59 -0
- data/tracks/ruby/exercises/connect/README.md +60 -0
- data/tracks/ruby/exercises/crypto-square/README.md +100 -0
- data/tracks/ruby/exercises/custom-set/README.md +37 -0
- data/tracks/ruby/exercises/diamond/README.md +85 -0
- data/tracks/ruby/exercises/difference-of-squares/README.md +45 -0
- data/tracks/ruby/exercises/dominoes/README.md +44 -0
- data/tracks/ruby/exercises/etl/README.md +77 -0
- data/tracks/ruby/exercises/flatten-array/README.md +44 -0
- data/tracks/ruby/exercises/food-chain/README.md +96 -0
- data/tracks/ruby/exercises/gigasecond/README.md +37 -0
- data/tracks/ruby/exercises/grade-school/README.md +68 -0
- data/tracks/ruby/exercises/grains/README.md +60 -0
- data/tracks/ruby/exercises/hamming/README.md +68 -0
- data/tracks/ruby/exercises/hello-world/README.md +47 -0
- data/tracks/ruby/exercises/hexadecimal/README.md +40 -0
- data/tracks/ruby/exercises/house/README.md +139 -0
- data/tracks/ruby/exercises/isogram/README.md +45 -0
- data/tracks/ruby/exercises/kindergarten-garden/README.md +92 -0
- data/tracks/ruby/exercises/largest-series-product/README.md +46 -0
- data/tracks/ruby/exercises/leap/README.md +59 -0
- data/tracks/ruby/exercises/linked-list/README.md +60 -0
- data/tracks/ruby/exercises/list-ops/README.md +36 -0
- data/tracks/ruby/exercises/luhn/README.md +97 -0
- data/tracks/ruby/exercises/matrix/README.md +71 -0
- data/tracks/ruby/exercises/meetup/README.md +56 -0
- data/tracks/ruby/exercises/minesweeper/README.md +56 -0
- data/tracks/ruby/exercises/nth-prime/README.md +41 -0
- data/tracks/ruby/exercises/nucleotide-count/README.md +59 -0
- data/tracks/ruby/exercises/ocr-numbers/README.md +111 -0
- data/tracks/ruby/exercises/octal/README.md +75 -0
- data/tracks/ruby/exercises/palindrome-products/README.md +66 -0
- data/tracks/ruby/exercises/pangram/README.md +41 -0
- data/tracks/ruby/exercises/pascals-triangle/README.md +47 -0
- data/tracks/ruby/exercises/perfect-numbers/README.md +50 -0
- data/tracks/ruby/exercises/phone-number/README.md +60 -0
- data/tracks/ruby/exercises/pig-latin/README.md +50 -0
- data/tracks/ruby/exercises/point-mutations/README.md +67 -0
- data/tracks/ruby/exercises/poker/README.md +38 -0
- data/tracks/ruby/exercises/prime-factors/README.md +62 -0
- data/tracks/ruby/exercises/protein-translation/README.md +75 -0
- data/tracks/ruby/exercises/proverb/README.md +44 -0
- data/tracks/ruby/exercises/pythagorean-triplet/README.md +50 -0
- data/tracks/ruby/exercises/queen-attack/README.md +59 -0
- data/tracks/ruby/exercises/rail-fence-cipher/README.md +86 -0
- data/tracks/ruby/exercises/raindrops/README.md +50 -0
- data/tracks/ruby/exercises/rna-transcription/README.md +51 -0
- data/tracks/ruby/exercises/robot-name/README.md +57 -0
- data/tracks/ruby/exercises/robot-simulator/README.md +60 -0
- data/tracks/ruby/exercises/roman-numerals/README.md +75 -0
- data/tracks/ruby/exercises/run-length-encoding/README.md +56 -0
- data/tracks/ruby/exercises/saddle-points/README.md +59 -0
- data/tracks/ruby/exercises/say/README.md +95 -0
- data/tracks/ruby/exercises/scale-generator/README.md +86 -0
- data/tracks/ruby/exercises/scrabble-score/README.md +70 -0
- data/tracks/ruby/exercises/secret-handshake/README.md +61 -0
- data/tracks/ruby/exercises/series/README.md +53 -0
- data/tracks/ruby/exercises/sieve/README.md +60 -0
- data/tracks/ruby/exercises/simple-cipher/README.md +116 -0
- data/tracks/ruby/exercises/simple-linked-list/README.md +54 -0
- data/tracks/ruby/exercises/space-age/README.md +50 -0
- data/tracks/ruby/exercises/strain/README.md +66 -0
- data/tracks/ruby/exercises/sum-of-multiples/README.md +44 -0
- data/tracks/ruby/exercises/tournament/README.md +94 -0
- data/tracks/ruby/exercises/transpose/README.md +91 -0
- data/tracks/ruby/exercises/triangle/README.md +52 -0
- data/tracks/ruby/exercises/trinary/README.md +54 -0
- data/tracks/ruby/exercises/twelve-days/README.md +61 -0
- data/tracks/ruby/exercises/two-bucket/README.md +62 -0
- data/tracks/ruby/exercises/word-count/README.md +45 -0
- data/tracks/ruby/exercises/wordy/README.md +89 -0
- data/tracks/rust/README.md +3 -3
- data/tracks/rust/_test/WINDOWS_README.md +44 -0
- data/tracks/rust/config.json +9 -2
- data/tracks/rust/exercises/pig-latin/Cargo-example.toml +8 -0
- data/tracks/rust/exercises/pig-latin/Cargo.lock +4 -0
- data/tracks/rust/exercises/pig-latin/Cargo.toml +6 -0
- data/tracks/rust/exercises/pig-latin/README.md +56 -0
- data/tracks/rust/exercises/pig-latin/example.rs +28 -0
- data/tracks/rust/exercises/pig-latin/tests/pig-latin.rs +120 -0
- data/tracks/rust/problem_ordering.md +2 -2
- data/tracks/sml/config.json +0 -2
- data/tracks/swift/config/exercise_readme.go.tmpl +16 -0
- data/tracks/swift/config.json +304 -79
- data/tracks/swift/exercises/accumulate/README.md +43 -0
- data/tracks/swift/exercises/acronym/README.md +23 -0
- data/tracks/swift/exercises/all-your-base/README.md +43 -0
- data/tracks/swift/exercises/allergies/README.md +45 -0
- data/tracks/swift/exercises/anagram/README.md +21 -0
- data/tracks/swift/exercises/atbash-cipher/README.md +42 -0
- data/tracks/swift/exercises/beer-song/README.md +335 -0
- data/tracks/swift/exercises/binary/README.md +43 -0
- data/tracks/swift/exercises/binary-search/README.md +49 -0
- data/tracks/swift/exercises/binary-search-tree/README.md +68 -0
- data/tracks/swift/exercises/bob/README.md +26 -0
- data/tracks/swift/exercises/bowling/README.md +61 -0
- data/tracks/swift/exercises/bracket-push/README.md +18 -0
- data/tracks/swift/exercises/clock/README.md +21 -0
- data/tracks/swift/exercises/crypto-square/README.md +82 -0
- data/tracks/swift/exercises/custom-set/README.md +19 -0
- data/tracks/swift/exercises/difference-of-squares/README.md +27 -0
- data/tracks/swift/exercises/dominoes/README.md +26 -0
- data/tracks/swift/exercises/etl/README.md +59 -0
- data/tracks/swift/exercises/flatten-array/README.md +26 -0
- data/tracks/swift/exercises/food-chain/README.md +78 -0
- data/tracks/swift/exercises/gigasecond/README.md +19 -0
- data/tracks/swift/exercises/grade-school/README.md +50 -0
- data/tracks/swift/exercises/grains/README.md +42 -0
- data/tracks/swift/exercises/hamming/README.md +50 -0
- data/tracks/swift/exercises/hello-world/README.md +29 -0
- data/tracks/swift/exercises/hexadecimal/README.md +22 -0
- data/tracks/swift/exercises/house/README.md +121 -0
- data/tracks/swift/exercises/isogram/README.md +27 -0
- data/tracks/swift/exercises/kindergarten-garden/README.md +74 -0
- data/tracks/swift/exercises/largest-series-product/README.md +28 -0
- data/tracks/swift/exercises/leap/README.md +41 -0
- data/tracks/swift/exercises/linked-list/README.md +42 -0
- data/tracks/swift/exercises/luhn/README.md +79 -0
- data/tracks/swift/exercises/matrix/README.md +53 -0
- data/tracks/swift/exercises/meetup/README.md +38 -0
- data/tracks/swift/exercises/minesweeper/README.md +38 -0
- data/tracks/swift/exercises/nth-prime/README.md +23 -0
- data/tracks/swift/exercises/nucleotide-count/README.md +41 -0
- data/tracks/swift/exercises/ocr-numbers/README.md +93 -0
- data/tracks/swift/exercises/octal/README.md +57 -0
- data/tracks/swift/exercises/palindrome-products/README.md +48 -0
- data/tracks/swift/exercises/pangram/README.md +23 -0
- data/tracks/swift/exercises/pascals-triangle/README.md +29 -0
- data/tracks/swift/exercises/perfect-numbers/README.md +32 -0
- data/tracks/swift/exercises/phone-number/README.md +42 -0
- data/tracks/swift/exercises/pig-latin/README.md +32 -0
- data/tracks/swift/exercises/poker/README.md +20 -0
- data/tracks/swift/exercises/prime-factors/README.md +44 -0
- data/tracks/swift/exercises/pythagorean-triplet/README.md +32 -0
- data/tracks/swift/exercises/queen-attack/README.md +41 -0
- data/tracks/swift/exercises/raindrops/README.md +32 -0
- data/tracks/swift/exercises/rna-transcription/README.md +33 -0
- data/tracks/swift/exercises/robot-name/README.md +30 -0
- data/tracks/swift/exercises/robot-simulator/README.md +42 -0
- data/tracks/swift/exercises/roman-numerals/README.md +57 -0
- data/tracks/swift/exercises/run-length-encoding/README.md +38 -0
- data/tracks/swift/exercises/saddle-points/README.md +41 -0
- data/tracks/swift/exercises/scrabble-score/README.md +52 -0
- data/tracks/swift/exercises/secret-handshake/README.md +43 -0
- data/tracks/swift/exercises/series/README.md +35 -0
- data/tracks/swift/exercises/sieve/README.md +42 -0
- data/tracks/swift/exercises/simple-cipher/README.md +98 -0
- data/tracks/swift/exercises/simple-linked-list/README.md +36 -0
- data/tracks/swift/exercises/space-age/README.md +32 -0
- data/tracks/swift/exercises/strain/README.md +48 -0
- data/tracks/swift/exercises/sublist/README.md +29 -0
- data/tracks/swift/exercises/sum-of-multiples/README.md +26 -0
- data/tracks/swift/exercises/tournament/README.md +76 -0
- data/tracks/swift/exercises/transpose/README.md +73 -0
- data/tracks/swift/exercises/triangle/README.md +34 -0
- data/tracks/swift/exercises/trinary/README.md +36 -0
- data/tracks/swift/exercises/twelve-days/README.md +43 -0
- data/tracks/swift/exercises/word-count/README.md +27 -0
- data/tracks/swift/exercises/wordy/README.md +71 -0
- data/tracks/typescript/README.md +1 -1
- data/tracks/typescript/config.json +63 -3
- data/tracks/vimscript/config.json +0 -2
- metadata +371 -40
- data/tracks/erlang/exercises/atbash-cipher/.meta/readme.go.tmpl +0 -17
- data/tracks/erlang/exercises/bank-account/.meta/readme.go.tmpl +0 -17
- data/tracks/erlang/exercises/beer-song/.meta/readme.go.tmpl +0 -17
- data/tracks/erlang/exercises/bob/.meta/readme.go.tmpl +0 -17
- data/tracks/erlang/exercises/circular-buffer/.meta/readme.go.tmpl +0 -17
- data/tracks/erlang/exercises/clock/.meta/readme.go.tmpl +0 -17
- data/tracks/erlang/exercises/collatz-conjecture/.meta/readme.go.tmpl +0 -17
- data/tracks/erlang/exercises/difference-of-squares/.meta/readme.go.tmpl +0 -17
- data/tracks/erlang/exercises/etl/.meta/readme.go.tmpl +0 -17
- data/tracks/erlang/exercises/gigasecond/.meta/readme.go.tmpl +0 -17
- data/tracks/erlang/exercises/grade-school/.meta/readme.go.tmpl +0 -17
- data/tracks/erlang/exercises/grains/.meta/readme.go.tmpl +0 -17
- data/tracks/erlang/exercises/hamming/.meta/readme.go.tmpl +0 -17
- data/tracks/erlang/exercises/hello-world/.meta/readme.go.tmpl +0 -17
- data/tracks/erlang/exercises/largest-series-product/.meta/readme.go.tmpl +0 -17
- data/tracks/erlang/exercises/leap/.meta/readme.go.tmpl +0 -17
- data/tracks/erlang/exercises/luhn/.meta/readme.go.tmpl +0 -17
- data/tracks/erlang/exercises/meetup/.meta/readme.go.tmpl +0 -17
- data/tracks/erlang/exercises/nucleotide-count/.meta/readme.go.tmpl +0 -17
- data/tracks/erlang/exercises/parallel-letter-frequency/.meta/readme.go.tmpl +0 -17
- data/tracks/erlang/exercises/phone-number/.meta/readme.go.tmpl +0 -17
- data/tracks/erlang/exercises/rna-transcription/.meta/readme.go.tmpl +0 -17
- data/tracks/erlang/exercises/robot-simulator/.meta/readme.go.tmpl +0 -17
- data/tracks/erlang/exercises/roman-numerals/.meta/readme.go.tmpl +0 -17
- data/tracks/erlang/exercises/rotational-cipher/.meta/readme.go.tmpl +0 -17
- data/tracks/erlang/exercises/scrabble-score/.meta/readme.go.tmpl +0 -17
- data/tracks/erlang/exercises/series/.meta/readme.go.tmpl +0 -17
- data/tracks/erlang/exercises/space-age/.meta/readme.go.tmpl +0 -17
- data/tracks/erlang/exercises/spiral-matrix/.meta/readme.go.tmpl +0 -17
- data/tracks/erlang/exercises/strain/.meta/readme.go.tmpl +0 -17
- data/tracks/erlang/exercises/sum-of-multiples/.meta/readme.go.tmpl +0 -17
- data/tracks/erlang/exercises/triangle/.meta/readme.go.tmpl +0 -17
- data/tracks/erlang/exercises/word-count/.meta/readme.go.tmpl +0 -17
- data/tracks/erlang/exercises/zipper/.meta/readme.go.tmpl +0 -17
data/tracks/factor/config.json
CHANGED
data/tracks/fsharp/config.json
CHANGED
data/tracks/go/config.json
CHANGED
@@ -320,9 +320,10 @@
|
|
320
320
|
"slug": "bank-account",
|
321
321
|
"core": false,
|
322
322
|
"unlocked_by": null,
|
323
|
-
"difficulty":
|
323
|
+
"difficulty": 4,
|
324
324
|
"topics": [
|
325
|
-
|
325
|
+
"Concurrency",
|
326
|
+
"Integers"
|
326
327
|
]
|
327
328
|
},
|
328
329
|
{
|
@@ -330,9 +331,12 @@
|
|
330
331
|
"slug": "crypto-square",
|
331
332
|
"core": false,
|
332
333
|
"unlocked_by": null,
|
333
|
-
"difficulty":
|
334
|
+
"difficulty": 3,
|
334
335
|
"topics": [
|
335
|
-
|
336
|
+
"Filtering",
|
337
|
+
"Strings",
|
338
|
+
"Text Formatting",
|
339
|
+
"Transforming"
|
336
340
|
]
|
337
341
|
},
|
338
342
|
{
|
@@ -340,9 +344,11 @@
|
|
340
344
|
"slug": "luhn",
|
341
345
|
"core": false,
|
342
346
|
"unlocked_by": null,
|
343
|
-
"difficulty":
|
347
|
+
"difficulty": 2,
|
344
348
|
"topics": [
|
345
|
-
|
349
|
+
"Algorithms",
|
350
|
+
"Integers",
|
351
|
+
"Strings"
|
346
352
|
]
|
347
353
|
},
|
348
354
|
{
|
@@ -6,10 +6,24 @@
|
|
6
6
|
// (Account) Deposit(amount int64) (newBalance int64, ok bool)
|
7
7
|
//
|
8
8
|
// If Open is given a negative initial deposit, it must return nil.
|
9
|
-
// Deposit must handle a negative amount as a withdrawal.
|
9
|
+
// Deposit must handle a negative amount as a withdrawal. Withdrawals must
|
10
|
+
// not succeed if they result in a negative balance.
|
10
11
|
// If any Account method is called on an closed account, it must not modify
|
11
12
|
// the account and must return ok = false.
|
12
13
|
|
14
|
+
// The tests will execute some operations concurrently. You should strive
|
15
|
+
// to ensure that operations on the Account leave it in a consistent state.
|
16
|
+
// For example: multiple goroutines may be depositing and withdrawing money
|
17
|
+
// simultaneously, two withdrawals occurring concurrently should not be able
|
18
|
+
// to bring the balance into the negative.
|
19
|
+
|
20
|
+
// If you are new to concurrent operations in Go it will be worth looking
|
21
|
+
// at the sync package, specifically Mutexes:
|
22
|
+
//
|
23
|
+
// https://golang.org/pkg/sync/
|
24
|
+
// https://tour.golang.org/concurrency/9
|
25
|
+
// https://gobyexample.com/mutexes
|
26
|
+
|
13
27
|
package account
|
14
28
|
|
15
29
|
import (
|
@@ -295,3 +309,48 @@ func TestConcDeposit(t *testing.T) {
|
|
295
309
|
"a.Balance = %d, %t. Want 0, true", p, ok)
|
296
310
|
}
|
297
311
|
}
|
312
|
+
|
313
|
+
// The benchmark operations are here to encourage you to try different
|
314
|
+
// implementations to see which ones perform better. These are worth
|
315
|
+
// exploring after the tests pass.
|
316
|
+
//
|
317
|
+
// There is a basic benchmark and a parallelized version of the same
|
318
|
+
// benchmark. You run the benchmark using:
|
319
|
+
// go test --bench=.
|
320
|
+
//
|
321
|
+
// The output will look something like this:
|
322
|
+
// goos: linux
|
323
|
+
// goarch: amd64
|
324
|
+
// BenchmarkAccountOperations-8 10000000 130 ns/op
|
325
|
+
// BenchmarkAccountOperationsParallel-8 3000000 488 ns/op
|
326
|
+
// PASS
|
327
|
+
//
|
328
|
+
// You will notice that parallelism does not increase speed in this case, in
|
329
|
+
// fact it makes things slower! This is because none of the operations in our
|
330
|
+
// Account benefit from parallel processing. We are specifically protecting
|
331
|
+
// the account balance internals from being accessed by multiple processes
|
332
|
+
// simultaneously. Your protections will make the parallel processing slower
|
333
|
+
// because there is some overhead in managing the processes and protections.
|
334
|
+
//
|
335
|
+
// The interesting thing to try here is to experiment with the protections
|
336
|
+
// and see how their implementation changes the results of the parallel
|
337
|
+
// benchmark.
|
338
|
+
func BenchmarkAccountOperations(b *testing.B) {
|
339
|
+
a := Open(0)
|
340
|
+
defer a.Close()
|
341
|
+
for n := 0; n < b.N; n++ {
|
342
|
+
a.Deposit(10)
|
343
|
+
a.Deposit(-10)
|
344
|
+
}
|
345
|
+
}
|
346
|
+
|
347
|
+
func BenchmarkAccountOperationsParallel(b *testing.B) {
|
348
|
+
a := Open(0)
|
349
|
+
defer a.Close()
|
350
|
+
b.RunParallel(func(pb *testing.PB) {
|
351
|
+
for pb.Next() {
|
352
|
+
a.Deposit(10)
|
353
|
+
a.Deposit(-10)
|
354
|
+
}
|
355
|
+
})
|
356
|
+
}
|
@@ -2,6 +2,16 @@ package erratum
|
|
2
2
|
|
3
3
|
import "io"
|
4
4
|
|
5
|
+
// These are the support types and interface definitions used in the
|
6
|
+
// implementation if your Use function. See the test suite file at
|
7
|
+
// for information on the expected implementation.
|
8
|
+
//
|
9
|
+
// Because this is part of the package "erratum", if your solution file
|
10
|
+
// is also declared in the package you will automatically have access to
|
11
|
+
// these definitions (you do not have to re-declare them).
|
12
|
+
|
13
|
+
// TransientError is an error that may occur while opening a resource via
|
14
|
+
// ResourceOpener.
|
5
15
|
type TransientError struct {
|
6
16
|
err error
|
7
17
|
}
|
@@ -10,6 +20,10 @@ func (e TransientError) Error() string {
|
|
10
20
|
return e.err.Error()
|
11
21
|
}
|
12
22
|
|
23
|
+
// FrobError is a possible error from doing some frobbing, your implementation
|
24
|
+
// will require calling your Resource's Defrob(string) method.
|
25
|
+
// When this error occurs, the FrobError's defrobTag string will contain the
|
26
|
+
// string you must pass into Defrob.
|
13
27
|
type FrobError struct {
|
14
28
|
defrobTag string
|
15
29
|
inner error
|
@@ -20,6 +34,9 @@ func (e FrobError) Error() string {
|
|
20
34
|
}
|
21
35
|
|
22
36
|
type Resource interface {
|
37
|
+
|
38
|
+
// Resource is using composition to inherit the requirements of the io.Closer
|
39
|
+
// interface. What this means is that a Resource will have a .Close() method.
|
23
40
|
io.Closer
|
24
41
|
|
25
42
|
// Frob does something with the input string.
|
@@ -5,10 +5,43 @@ import (
|
|
5
5
|
"testing"
|
6
6
|
)
|
7
7
|
|
8
|
-
//
|
9
|
-
//
|
10
|
-
//
|
11
|
-
//
|
8
|
+
// Because this exercise is generally unique to each language and how it
|
9
|
+
// handles errors, most of the definition of your expected solution is provided
|
10
|
+
// here instead of the README.
|
11
|
+
// You should read this carefully (more than once) before implementation.
|
12
|
+
|
13
|
+
// Define a function `Use(o ResourceOpener, input string) error` that opens a
|
14
|
+
// resource, calls Frob(input) and closes the resource (in all cases). Your
|
15
|
+
// function should properly handle errors, as defined by the expectations of
|
16
|
+
// this test suite. ResourceOpener will be a function you may invoke directly
|
17
|
+
// `o()` in an attempt to "open" the resource. It returns a Resource and error
|
18
|
+
// value in the idiomatic Go fashion:
|
19
|
+
// https://blog.golang.org/error-handling-and-go
|
20
|
+
//
|
21
|
+
// See the ./common.go file for the definitions of Resource, ResourceOpener,
|
22
|
+
// FrobError and TransientError.
|
23
|
+
//
|
24
|
+
// There will be a few places in your Use function where errors may occur:
|
25
|
+
//
|
26
|
+
// - Invoking the ResourceOpener function passed into Use as the first
|
27
|
+
// parameter, it may fail with a TransientError, if so keep trying to open it.
|
28
|
+
// If it is some other sort of error, return it.
|
29
|
+
//
|
30
|
+
// - Calling the Frob function on the Resource returned from the ResourceOpener
|
31
|
+
// function, it may panic with a FrobError (or another type of error). If
|
32
|
+
// it is indeed a FrobError you will have to call the Resource's Defrob
|
33
|
+
// function using the FrobError's defrobTag variable as input. Either way
|
34
|
+
// return the error.
|
35
|
+
//
|
36
|
+
// Also note: if the Resource was opened successfully make sure to call its
|
37
|
+
// Close function no matter what (even if errors occur).
|
38
|
+
//
|
39
|
+
// If you are new to Go errors or panics here is a good place to start:
|
40
|
+
// https://blog.golang.org/defer-panic-and-recover
|
41
|
+
//
|
42
|
+
// You may also need to look at named return values as a helpful way to
|
43
|
+
// return error information from panic recovery:
|
44
|
+
// https://tour.golang.org/basics/7
|
12
45
|
|
13
46
|
const targetTestVersion = 2
|
14
47
|
|
data/tracks/haskell/config.json
CHANGED
data/tracks/java/config.json
CHANGED
@@ -1,7 +1,5 @@
|
|
1
1
|
{
|
2
|
-
"slug": "java",
|
3
2
|
"language": "Java",
|
4
|
-
"repository": "https://github.com/exercism/java",
|
5
3
|
"active": true,
|
6
4
|
"exercises": [
|
7
5
|
{
|
@@ -768,6 +766,16 @@
|
|
768
766
|
|
769
767
|
]
|
770
768
|
},
|
769
|
+
{
|
770
|
+
"uuid": "f0c0316d-3fb5-455e-952a-91161e7fb298",
|
771
|
+
"slug": "forth",
|
772
|
+
"core": false,
|
773
|
+
"unlocked_by": null,
|
774
|
+
"difficulty": 9,
|
775
|
+
"topics": [
|
776
|
+
|
777
|
+
]
|
778
|
+
},
|
771
779
|
{
|
772
780
|
"uuid": "377fe38b-08ad-4f3a-8118-a43c10f7b9b2",
|
773
781
|
"slug": "custom-set",
|
File without changes
|
@@ -0,0 +1,41 @@
|
|
1
|
+
# Forth
|
2
|
+
|
3
|
+
Implement an evaluator for a very simple subset of Forth.
|
4
|
+
|
5
|
+
[Forth](https://en.wikipedia.org/wiki/Forth_%28programming_language%29)
|
6
|
+
is a stack-based programming language. Implement a very basic evaluator
|
7
|
+
for a small subset of Forth.
|
8
|
+
|
9
|
+
Your evaluator has to support the following words:
|
10
|
+
|
11
|
+
- `+`, `-`, `*`, `/` (integer arithmetic)
|
12
|
+
- `DUP`, `DROP`, `SWAP`, `OVER` (stack manipulation)
|
13
|
+
|
14
|
+
Your evaluator also has to support defining new words using the
|
15
|
+
customary syntax: `: word-name definition ;`.
|
16
|
+
|
17
|
+
To keep things simple the only data type you need to support is signed
|
18
|
+
integers of at least 16 bits size.
|
19
|
+
|
20
|
+
You should use the following rules for the syntax: a number is a
|
21
|
+
sequence of one or more (ASCII) digits, a word is a sequence of one or
|
22
|
+
more letters, digits, symbols or punctuation that is not a number.
|
23
|
+
(Forth probably uses slightly different rules, but this is close
|
24
|
+
enough.)
|
25
|
+
|
26
|
+
Words are case-insensitive.
|
27
|
+
|
28
|
+
|
29
|
+
To run the tests:
|
30
|
+
|
31
|
+
```sh
|
32
|
+
$ gradle test
|
33
|
+
```
|
34
|
+
|
35
|
+
For more detailed info about the Java track see the [help page](http://exercism.io/languages/java).
|
36
|
+
|
37
|
+
|
38
|
+
|
39
|
+
## Submitting Incomplete Solutions
|
40
|
+
It's possible to submit an incomplete solution so you can see how others have completed the exercise.
|
41
|
+
|
@@ -0,0 +1,18 @@
|
|
1
|
+
apply plugin: "java"
|
2
|
+
apply plugin: "eclipse"
|
3
|
+
apply plugin: "idea"
|
4
|
+
|
5
|
+
repositories {
|
6
|
+
mavenCentral()
|
7
|
+
}
|
8
|
+
|
9
|
+
dependencies {
|
10
|
+
testCompile "junit:junit:4.12"
|
11
|
+
}
|
12
|
+
|
13
|
+
test {
|
14
|
+
testLogging {
|
15
|
+
exceptionFormat = 'full'
|
16
|
+
events = ["passed", "failed", "skipped"]
|
17
|
+
}
|
18
|
+
}
|
@@ -0,0 +1,154 @@
|
|
1
|
+
import java.util.*;
|
2
|
+
import java.util.function.UnaryOperator;
|
3
|
+
|
4
|
+
class ForthEvaluator {
|
5
|
+
|
6
|
+
private static final Map<String, UnaryOperator<Deque<Integer>>> BUILT_IN_OPS
|
7
|
+
= new HashMap<String, UnaryOperator<Deque<Integer>>>() {{
|
8
|
+
|
9
|
+
put("+", values -> {
|
10
|
+
if (values.size() < 2) {
|
11
|
+
throw new IllegalArgumentException(
|
12
|
+
"Addition requires that the stack contain at least 2 values");
|
13
|
+
}
|
14
|
+
|
15
|
+
values.push(values.pop() + values.pop());
|
16
|
+
return values;
|
17
|
+
});
|
18
|
+
|
19
|
+
put("-", values -> {
|
20
|
+
if (values.size() < 2) {
|
21
|
+
throw new IllegalArgumentException(
|
22
|
+
"Subtraction requires that the stack contain at least 2 values");
|
23
|
+
}
|
24
|
+
|
25
|
+
int topValue = values.pop();
|
26
|
+
int secondValue = values.pop();
|
27
|
+
|
28
|
+
values.push(secondValue - topValue);
|
29
|
+
return values;
|
30
|
+
});
|
31
|
+
|
32
|
+
put("*", values -> {
|
33
|
+
if (values.size() < 2) {
|
34
|
+
throw new IllegalArgumentException(
|
35
|
+
"Multiplication requires that the stack contain at least 2 values");
|
36
|
+
}
|
37
|
+
|
38
|
+
values.push(values.pop() * values.pop());
|
39
|
+
return values;
|
40
|
+
});
|
41
|
+
|
42
|
+
put("/", values -> {
|
43
|
+
if (values.size() < 2) {
|
44
|
+
throw new IllegalArgumentException(
|
45
|
+
"Division requires that the stack contain at least 2 values");
|
46
|
+
}
|
47
|
+
|
48
|
+
int topValue = values.pop();
|
49
|
+
int secondValue = values.pop();
|
50
|
+
|
51
|
+
if (topValue == 0) {
|
52
|
+
throw new IllegalArgumentException("Division by 0 is not allowed");
|
53
|
+
}
|
54
|
+
|
55
|
+
values.push(secondValue / topValue);
|
56
|
+
return values;
|
57
|
+
});
|
58
|
+
|
59
|
+
put("dup", values -> {
|
60
|
+
if (values.isEmpty()) {
|
61
|
+
throw new IllegalArgumentException(
|
62
|
+
"Duplicating requires that the stack contain at least 1 value");
|
63
|
+
}
|
64
|
+
|
65
|
+
values.push(values.peek());
|
66
|
+
return values;
|
67
|
+
});
|
68
|
+
|
69
|
+
put("drop", values -> {
|
70
|
+
if (values.isEmpty()) {
|
71
|
+
throw new IllegalArgumentException(
|
72
|
+
"Dropping requires that the stack contain at least 1 value");
|
73
|
+
}
|
74
|
+
|
75
|
+
values.pop();
|
76
|
+
return values;
|
77
|
+
});
|
78
|
+
|
79
|
+
put("swap", values -> {
|
80
|
+
if (values.size() < 2) {
|
81
|
+
throw new IllegalArgumentException(
|
82
|
+
"Swapping requires that the stack contain at least 2 values");
|
83
|
+
}
|
84
|
+
|
85
|
+
int topValue = values.pop();
|
86
|
+
int secondValue = values.pop();
|
87
|
+
values.push(topValue);
|
88
|
+
values.push(secondValue);
|
89
|
+
return values;
|
90
|
+
});
|
91
|
+
|
92
|
+
put("over", values -> {
|
93
|
+
if (values.size() < 2) {
|
94
|
+
throw new IllegalArgumentException(
|
95
|
+
"Overing requires that the stack contain at least 2 values");
|
96
|
+
}
|
97
|
+
|
98
|
+
int topValue = values.pop();
|
99
|
+
int secondValue = values.peek();
|
100
|
+
values.push(topValue);
|
101
|
+
values.push(secondValue);
|
102
|
+
return values;
|
103
|
+
});
|
104
|
+
}};
|
105
|
+
|
106
|
+
private Deque<Integer> values = new ArrayDeque<>();
|
107
|
+
|
108
|
+
private List<Token> tokens = new ArrayList<>();
|
109
|
+
|
110
|
+
private Map<String, List<Token>> userOps = new HashMap<>();
|
111
|
+
|
112
|
+
List<Integer> evaluateProgram(final List<String> program) {
|
113
|
+
parse(program);
|
114
|
+
evaluate();
|
115
|
+
|
116
|
+
final List<Integer> result = new ArrayList<>(values);
|
117
|
+
Collections.reverse(result);
|
118
|
+
return result;
|
119
|
+
}
|
120
|
+
|
121
|
+
private void parse(final List<String> program) {
|
122
|
+
program.forEach(string -> tokens.addAll(Token.fromString(string)));
|
123
|
+
}
|
124
|
+
|
125
|
+
private void evaluate() {
|
126
|
+
while (!tokens.isEmpty()) {
|
127
|
+
final Token token = tokens.remove(0);
|
128
|
+
|
129
|
+
if (token instanceof Token.OpDefToken) {
|
130
|
+
final Token.OpDefToken opDefToken = (Token.OpDefToken) token;
|
131
|
+
userOps.put(opDefToken.getNewOp().toLowerCase(), opDefToken.getNewOpDefTokens());
|
132
|
+
} else if (token instanceof Token.OpToken) {
|
133
|
+
evaluateOpToken((Token.OpToken) token);
|
134
|
+
} else if (token instanceof Token.IntToken) {
|
135
|
+
values.push(((Token.IntToken) token).getRawValue());
|
136
|
+
}
|
137
|
+
}
|
138
|
+
}
|
139
|
+
|
140
|
+
private void evaluateOpToken(final Token.OpToken opToken) {
|
141
|
+
final String op = opToken.getOp();
|
142
|
+
|
143
|
+
if (userOps.containsKey(op)) {
|
144
|
+
final List<Token> replacementOps = userOps.get(op);
|
145
|
+
Collections.reverse(replacementOps);
|
146
|
+
replacementOps.forEach(token -> tokens.add(0, token));
|
147
|
+
} else if (BUILT_IN_OPS.containsKey(op)) {
|
148
|
+
values = BUILT_IN_OPS.get(op).apply(values);
|
149
|
+
} else {
|
150
|
+
throw new IllegalArgumentException("No definition available for operator \"" + op + "\"");
|
151
|
+
}
|
152
|
+
}
|
153
|
+
|
154
|
+
}
|
@@ -0,0 +1,90 @@
|
|
1
|
+
import java.util.Arrays;
|
2
|
+
import java.util.Collections;
|
3
|
+
import java.util.List;
|
4
|
+
import java.util.stream.Collectors;
|
5
|
+
|
6
|
+
class Token {
|
7
|
+
|
8
|
+
static class OpDefToken extends Token {
|
9
|
+
|
10
|
+
static OpDefToken opDefTokenFromString(final String string) {
|
11
|
+
final String trimmedLine = string.substring(2, string.length() - 2);
|
12
|
+
final int newOpEnd = trimmedLine.indexOf(" ");
|
13
|
+
|
14
|
+
if (newOpEnd == -1) {
|
15
|
+
throw new IllegalArgumentException("Incomplete operation definition");
|
16
|
+
}
|
17
|
+
|
18
|
+
final Token newOpToken = Token.fromString(trimmedLine.substring(0, newOpEnd)).get(0);
|
19
|
+
|
20
|
+
if (!(newOpToken instanceof OpToken)) {
|
21
|
+
throw new IllegalArgumentException("Cannot redefine numbers");
|
22
|
+
}
|
23
|
+
|
24
|
+
final List<Token> newOpDefTokens = Token.fromString(trimmedLine.substring(newOpEnd + 1));
|
25
|
+
return new OpDefToken(((OpToken) newOpToken).getOp(), newOpDefTokens);
|
26
|
+
}
|
27
|
+
|
28
|
+
private final String newOp;
|
29
|
+
|
30
|
+
private final List<Token> newOpDefTokens;
|
31
|
+
|
32
|
+
private OpDefToken(final String newOp, final List<Token> newOpDefTokens) {
|
33
|
+
this.newOp = newOp;
|
34
|
+
this.newOpDefTokens = newOpDefTokens;
|
35
|
+
}
|
36
|
+
|
37
|
+
String getNewOp() {
|
38
|
+
return newOp;
|
39
|
+
}
|
40
|
+
|
41
|
+
List<Token> getNewOpDefTokens() {
|
42
|
+
return newOpDefTokens;
|
43
|
+
}
|
44
|
+
|
45
|
+
}
|
46
|
+
|
47
|
+
static class OpToken extends Token {
|
48
|
+
|
49
|
+
private final String op;
|
50
|
+
|
51
|
+
OpToken(final String op) {
|
52
|
+
this.op = op;
|
53
|
+
}
|
54
|
+
|
55
|
+
String getOp() {
|
56
|
+
return op;
|
57
|
+
}
|
58
|
+
|
59
|
+
}
|
60
|
+
|
61
|
+
static class IntToken extends Token {
|
62
|
+
|
63
|
+
private final int rawValue;
|
64
|
+
|
65
|
+
IntToken(final int rawValue) {
|
66
|
+
this.rawValue = rawValue;
|
67
|
+
}
|
68
|
+
|
69
|
+
int getRawValue() {
|
70
|
+
return rawValue;
|
71
|
+
}
|
72
|
+
|
73
|
+
}
|
74
|
+
|
75
|
+
static List<Token> fromString(final String string) {
|
76
|
+
if (string.startsWith(":")) {
|
77
|
+
return Collections.singletonList(OpDefToken.opDefTokenFromString(string));
|
78
|
+
} else if (string.matches("[A-z+/*\\-]+(?:-[A-z+/*\\-]+)*")) {
|
79
|
+
return Collections.singletonList(new OpToken(string.toLowerCase()));
|
80
|
+
} else if (string.matches("\\d+")) {
|
81
|
+
return Collections.singletonList(new IntToken(Integer.parseInt(string)));
|
82
|
+
} else {
|
83
|
+
return Arrays.stream(string.split(" "))
|
84
|
+
.map(Token::fromString)
|
85
|
+
.flatMap(List::stream)
|
86
|
+
.collect(Collectors.toList());
|
87
|
+
}
|
88
|
+
}
|
89
|
+
|
90
|
+
}
|
File without changes
|