├── .circleci
└── config.yml
├── .gitignore
├── README.md
├── build.gradle
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
├── settings.gradle
└── src
├── main
└── java
│ ├── kata
│ ├── kyu4
│ │ ├── BattleShipsSunkDamagedOrNotTouched.java
│ │ ├── CodewarsStyleRankingSystem.java
│ │ ├── DecodeTheMorseCodeAdvanced.java
│ │ ├── HumanReadableDurationFormat.java
│ │ ├── LongestCommonSubsequencePerformanceVersion.java
│ │ ├── NumberOfProperFractionsWithDenominatorD.java
│ │ ├── RecoverASecretStringFromRandomTriplets.java
│ │ ├── ReversePolishNotationCalculator.java
│ │ ├── RomanNumeralsEncoder.java
│ │ ├── SquareIntoSquaresProtectTrees.java
│ │ ├── SumByFactors.java
│ │ └── TenPinBowling.java
│ ├── kyu5
│ │ ├── ConvertStringToCamelCase.java
│ │ └── Scramblies.java
│ ├── kyu6
│ │ ├── BouncingBalls.java
│ │ ├── BuildAPileOfCubes.java
│ │ ├── DecodeTheMorseCode.java
│ │ ├── Dubstep.java
│ │ ├── EqualSidesOfAnArray.java
│ │ ├── FindTheMissingLetter.java
│ │ ├── FindTheOddInt.java
│ │ ├── GiveMeADiamond.java
│ │ ├── SortTheOdd.java
│ │ ├── TripleTrouble.java
│ │ ├── VasyaClerk.java
│ │ └── YourOrderPlease.java
│ ├── kyu7
│ │ ├── DescendingOrder.java
│ │ ├── GrowthOfAPopulation.java
│ │ ├── JadenCasingStrings.java
│ │ ├── MoneyMoneyMoney.java
│ │ ├── OnesAndZeros.java
│ │ └── ShortestWord.java
│ └── kyu8
│ │ ├── Multiply.java
│ │ └── RemoveStringSpaces.java
│ └── utils
│ └── MorseCode.java
└── test
└── java
└── kata
├── kyu4
├── BattleShipsSunkDamagedOrNotTouchedTest.java
├── CodewarsStyleRankingSystemTest.java
├── DecodeTheMorseCodeAdvancedTest.java
├── HumanReadableDurationFormatTest.java
├── LongestCommonSubsequencePerformanceVersionTest.java
├── NumberOfProperFractionsWithDenominatorDTest.java
├── RecoverASecretStringFromRandomTripletsTest.java
├── ReversePolishNotationCalculatorTest.java
├── RomanNumeralsEncoderTest.java
├── SquareIntoSquaresProtectTreesTest.java
├── SumByFactorsTest.java
└── TenPinBowlingTest.java
├── kyu5
├── ConvertStringToCamelCaseTest.java
└── ScrambliesTest.java
├── kyu6
├── BouncingBallsTest.java
├── BuildAPileOfCubesTest.java
├── DecodeTheMorseCodeTest.java
├── DubstepTest.java
├── EqualSidesOfAnArrayTest.java
├── FindTheMissingLetterTest.java
├── FindTheOddIntTest.java
├── GiveMeADiamondTest.java
├── SortTheOddTest.java
├── TripleTroubleTest.java
├── VasyaClerkTest.java
└── YourOrderPleaseTest.java
├── kyu7
├── DescendingOrderTest.java
├── GrowthOfAPopulationTest.java
├── JadenCasingStringsTest.java
├── MoneyMoneyMoneyTest.java
├── OnesAndZerosTest.java
└── ShortestWordTest.java
└── kyu8
├── MultiplyTest.java
└── RemoveStringSpacesTest.java
/.circleci/config.yml:
--------------------------------------------------------------------------------
1 | version: 2
2 | jobs:
3 | build:
4 | docker:
5 | - image: circleci/openjdk:8-jdk
6 |
7 | working_directory: ~/repo
8 |
9 | environment:
10 | JVM_OPTS: -Xmx3200m
11 | TERM: dumb
12 |
13 | steps:
14 | - checkout
15 |
16 | - restore_cache:
17 | key: v1-dependencies-{{ checksum "build.gradle" }}
18 |
19 | - run: gradle dependencies
20 |
21 | - save_cache:
22 | paths:
23 | - ~/.gradle
24 | key: v1-dependencies-{{ checksum "build.gradle" }}
25 |
26 | - run: gradle clean test jacocoTestReport sonarqube
27 |
28 | - run:
29 | name: Save test results
30 | command: |
31 | mkdir -p ~/junit/kyu1/ ~/junit/kyu2/ ~/junit/kyu3/ ~/junit/kyu4/ ~/junit/kyu5/ ~/junit/kyu6/ ~/junit/kyu7/ ~/junit/kyu8/
32 | find . -type f -regex ".*/build/test-results/.*kyu1.*xml" -exec cp {} ~/junit/kyu1/ \;
33 | find . -type f -regex ".*/build/test-results/.*kyu2.*xml" -exec cp {} ~/junit/kyu2/ \;
34 | find . -type f -regex ".*/build/test-results/.*kyu3.*xml" -exec cp {} ~/junit/kyu3/ \;
35 | find . -type f -regex ".*/build/test-results/.*kyu4.*xml" -exec cp {} ~/junit/kyu4/ \;
36 | find . -type f -regex ".*/build/test-results/.*kyu5.*xml" -exec cp {} ~/junit/kyu5/ \;
37 | find . -type f -regex ".*/build/test-results/.*kyu6.*xml" -exec cp {} ~/junit/kyu6/ \;
38 | find . -type f -regex ".*/build/test-results/.*kyu7.*xml" -exec cp {} ~/junit/kyu7/ \;
39 | find . -type f -regex ".*/build/test-results/.*kyu8.*xml" -exec cp {} ~/junit/kyu8/ \;
40 | find . -type f -regex ".*/build/test-results/.*^kyu[1-8].*xml" -exec cp {} ~/junit/ \;
41 | when: always
42 |
43 | - store_test_results:
44 | path: ~/junit
45 |
46 | - store_artifacts:
47 | path: ~/junit
48 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # Created by .ignore support plugin (hsz.mobi)
2 | ### Java template
3 | # Compiled class file
4 | *.class
5 |
6 | # Log file
7 | *.log
8 |
9 | # BlueJ files
10 | *.ctxt
11 |
12 | # Mobile Tools for Java (J2ME)
13 | .mtj.tmp/
14 |
15 | # Package Files #
16 | *.jar
17 | *.war
18 | *.ear
19 | *.zip
20 | *.tar.gz
21 | *.rar
22 |
23 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
24 | hs_err_pid*
25 | ### Gradle template
26 | .gradle
27 | /build/
28 |
29 | # Ignore Gradle GUI config
30 | gradle-app.setting
31 |
32 | # Avoid ignoring Gradle wrapper jar file (.jar files are usually ignored)
33 | !gradle-wrapper.jar
34 |
35 | # Cache of project
36 | .gradletasknamecache
37 |
38 | # # Work around https://youtrack.jetbrains.com/issue/IDEA-116898
39 | # gradle/wrapper/gradle-wrapper.properties
40 | ### JetBrains template
41 | # Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and Webstorm
42 | # Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
43 |
44 | # User-specific stuff:
45 | .idea/**/workspace.xml
46 | .idea/**/tasks.xml
47 | .idea/dictionaries
48 |
49 | # Sensitive or high-churn files:
50 | .idea/**/dataSources/
51 | .idea/**/dataSources.ids
52 | .idea/**/dataSources.xml
53 | .idea/**/dataSources.local.xml
54 | .idea/**/sqlDataSources.xml
55 | .idea/**/dynamic.xml
56 | .idea/**/uiDesigner.xml
57 |
58 | # Gradle:
59 | .idea/**/gradle.xml
60 | .idea/**/libraries
61 |
62 | # CMake
63 | cmake-build-debug/
64 | cmake-build-release/
65 |
66 | # Mongo Explorer plugin:
67 | .idea/**/mongoSettings.xml
68 |
69 | ## File-based project format:
70 | *.iws
71 |
72 | ## Plugin-specific files:
73 |
74 | # IntelliJ
75 | out/
76 |
77 | # mpeltonen/sbt-idea plugin
78 | .idea_modules/
79 |
80 | # JIRA plugin
81 | atlassian-ide-plugin.xml
82 |
83 | # Cursive Clojure plugin
84 | .idea/replstate.xml
85 |
86 | # Crashlytics plugin (for Android Studio and IntelliJ)
87 | com_crashlytics_export_strings.xml
88 | crashlytics.properties
89 | crashlytics-build.properties
90 | fabric.properties
91 | ### Linux template
92 | *~
93 |
94 | # temporary files which can be created if a process still has a handle open of a deleted file
95 | .fuse_hidden*
96 |
97 | # KDE directory preferences
98 | .directory
99 |
100 | # Linux trash folder which might appear on any partition or disk
101 | .Trash-*
102 |
103 | # .nfs files are created when an open file is removed but is still being accessed
104 | .nfs*
105 | ### macOS template
106 | # General
107 | .DS_Store
108 | .AppleDouble
109 | .LSOverride
110 |
111 | # Icon must end with two \r
112 | Icon
113 |
114 | # Thumbnails
115 | ._*
116 |
117 | # Files that might appear in the root of a volume
118 | .DocumentRevisions-V100
119 | .fseventsd
120 | .Spotlight-V100
121 | .TemporaryItems
122 | .Trashes
123 | .VolumeIcon.icns
124 | .com.apple.timemachine.donotpresent
125 |
126 | # Directories potentially created on remote AFP share
127 | .AppleDB
128 | .AppleDesktop
129 | Network Trash Folder
130 | Temporary Items
131 | .apdisk
132 | ### Windows template
133 | # Windows thumbnail cache files
134 | Thumbs.db
135 | ehthumbs.db
136 | ehthumbs_vista.db
137 |
138 | # Dump file
139 | *.stackdump
140 |
141 | # Folder config file
142 | [Dd]esktop.ini
143 |
144 | # Recycle Bin used on file shares
145 | $RECYCLE.BIN/
146 |
147 | # Windows Installer files
148 | *.cab
149 | *.msi
150 | *.msm
151 | *.msp
152 |
153 | # Windows shortcuts
154 | *.lnk
155 |
156 | .idea
157 | sonar-project.properties
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # My Codewars Solutions (Java)
2 |
3 | ## Status
4 | | Ranking | Build | Quality |
5 | | --- | --- | --- |
6 | | [](https://www.codewars.com/users/jeppestaerk) | [](https://circleci.com/gh/jeppestaerk/My-CodeWars-Solutions-Java) | [](https://sonarcloud.io/dashboard?id=io.staerk%3Acodewars) [](https://sonarcloud.io/dashboard?id=io.staerk%3Acodewars) [](https://sonarcloud.io/dashboard?id=io.staerk%3Acodewars)
[](https://sonarcloud.io/dashboard?id=io.staerk%3Acodewars) [](https://sonarcloud.io/dashboard?id=io.staerk%3Acodewars) [](https://sonarcloud.io/dashboard?id=io.staerk%3Acodewars)
[](https://sonarcloud.io/dashboard?id=io.staerk%3Acodewars) [](https://sonarcloud.io/dashboard?id=io.staerk%3Acodewars) [](https://sonarcloud.io/dashboard?id=io.staerk%3Acodewars) |
7 |
8 | ## My Solutions
9 | | kyu | Codewars Kate | My Solutions |
10 | | --- | --- | --- |
11 | | 4 | [Battle ships: Sunk damaged or not touched?](https://www.codewars.com/kata/58d06bfbc43d20767e000074) | [BattleShipsSunkDamagedOrNotTouched.java](https://github.com/jeppestaerk/My-CodeWars-Solutions-Java/blob/master/src/main/java/kata/kyu4/BattleShipsSunkDamagedOrNotTouched.java) |
12 | | 4 | [Decode the Morse code, advanced](https://www.codewars.com/kata/54b72c16cd7f5154e9000457) | [DecodeTheMorseCodeAdvanced.java](https://github.com/jeppestaerk/My-CodeWars-Solutions-Java/blob/master/src/main/java/kata/kyu4/DecodeTheMorseCodeAdvanced.java) |
13 | | 4 | [Human readable duration format](https://www.codewars.com/kata/52742f58faf5485cae000b9a) | [HumanReadableDurationFormat.java](https://github.com/jeppestaerk/My-CodeWars-Solutions-Java/blob/master/src/main/java/kata/kyu4/HumanReadableDurationFormat.java) |
14 | | 4 | [Roman Numerals Encoder](https://www.codewars.com/kata/51b62bf6a9c58071c600001b) | [RomanNumeralsEncoder.java](https://github.com/jeppestaerk/My-CodeWars-Solutions-Java/blob/master/src/main/java/kata/kyu4/RomanNumeralsEncoder.java) |
15 | | 4 | [Ten-Pin Bowling](https://www.codewars.com/kata/5531abe4855bcc8d1f00004c) | [TenPinBowling.java](https://github.com/jeppestaerk/My-CodeWars-Solutions-Java/blob/master/src/main/java/kata/kyu4/TenPinBowling.java) |
16 | | 4 | [Reverse polish notation calculator](https://www.codewars.com/kata/52f78966747862fc9a0009ae) | [ReversePolishNotationCalculator.java](https://github.com/jeppestaerk/My-CodeWars-Solutions-Java/blob/master/src/main/java/kata/kyu4/ReversePolishNotationCalculator.java) |
17 | | 4 | [Longest Common Subsequence (Performance version)](https://www.codewars.com/kata/593ff8b39e1cc4bae9000070) | [LongestCommonSubsequencePerformanceVersion.java](https://github.com/jeppestaerk/My-CodeWars-Solutions-Java/blob/master/src/main/java/kata/kyu4/LongestCommonSubsequencePerformanceVersion.java) |
18 | | 4 | [Number of Proper Fractions with Denominator d](https://www.codewars.com/kata/55b7bb74a0256d4467000070) | [NumberOfProperFractionsWithDenominatorD.java](https://github.com/jeppestaerk/My-CodeWars-Solutions-Java/blob/master/src/main/java/kata/kyu4/NumberOfProperFractionsWithDenominatorD.java) |
19 | | 4 | [Square into Squares. Protect trees!](https://www.codewars.com/kata/54eb33e5bc1a25440d000891) | [SquareIntoSquaresProtectTrees.java](SquareIntoSquaresProtectTrees.java) |
20 | | 4 | [Recover a secret string from random triplets](https://www.codewars.com/kata/53f40dff5f9d31b813000774) | [RecoverASecretStringFromRandomTriplets.java](https://github.com/jeppestaerk/My-CodeWars-Solutions-Java/blob/master/src/main/java/kata/kyu4/RecoverASecretStringFromRandomTriplets.java) |
21 | | 4 | [Sum by Factors](https://www.codewars.com/kata/54d496788776e49e6b00052f) | [SumByFactors.java](https://github.com/jeppestaerk/My-CodeWars-Solutions-Java/blob/master/src/main/java/kata/kyu4/SumByFactors.java) |
22 | | 4 | [Codewars style ranking system](https://www.codewars.com/kata/51fda2d95d6efda45e00004e) | [CodewarsStyleRankingSystem.java](https://github.com/jeppestaerk/My-CodeWars-Solutions-Java/blob/master/src/main/java/kata/kyu4/CodewarsStyleRankingSystem.java) |
23 | | 5 | [Scramblies](https://www.codewars.com/kata/55c04b4cc56a697bb0000048) | [Scramblies.java](https://github.com/jeppestaerk/My-CodeWars-Solutions-Java/blob/master/src/main/java/kata/kyu5/Scramblies.java) |
24 | | 5 | [Convert string to camel case](https://www.codewars.com/kata/517abf86da9663f1d2000003) | [ConvertStringToCamelCase.java](https://github.com/jeppestaerk/My-CodeWars-Solutions-Java/blob/master/src/main/java/kata/kyu5/ConvertStringToCamelCase.java) |
25 | | 6 | [Decode the Morse code](https://www.codewars.com/kata/54b724efac3d5402db00065e) | [DecodeTheMorseCode.java](https://github.com/jeppestaerk/My-CodeWars-Solutions-Java/blob/master/src/main/java/kata/kyu6/DecodeTheMorseCode.java) |
26 | | 6 | [Sort the odd](https://www.codewars.com/kata/578aa45ee9fd15ff4600090d) | [SortTheOdd.java](https://github.com/jeppestaerk/My-CodeWars-Solutions-Java/blob/master/src/main/java/kata/kyu6/SortTheOdd.java) |
27 | | 6 | [Vasya - Clerk](https://www.codewars.com/kata/555615a77ebc7c2c8a0000b8) | [VasyaClerk.java](https://github.com/jeppestaerk/My-CodeWars-Solutions-Java/blob/master/src/main/java/kata/kyu6/VasyaClerk.java) |
28 | | 6 | [Dubstep](https://www.codewars.com/kata/551dc350bf4e526099000ae5) | [Dubstep.java](https://github.com/jeppestaerk/My-CodeWars-Solutions-Java/blob/master/src/main/java/kata/kyu6/Dubstep.java) |
29 | | 6 | [Triple trouble](https://www.codewars.com/kata/55d5434f269c0c3f1b000058) | [TripleTrouble.java](https://github.com/jeppestaerk/My-CodeWars-Solutions-Java/blob/master/src/main/java/kata/kyu6/TripleTrouble.java) |
30 | | 6 | [Give me a Diamond](https://www.codewars.com/kata/5503013e34137eeeaa001648) | [GiveMeADiamond.java](https://github.com/jeppestaerk/My-CodeWars-Solutions-Java/blob/master/src/main/java/kata/kyu6/GiveMeADiamond.java) |
31 | | 6 | [Bouncing Balls](https://www.codewars.com/kata/5544c7a5cb454edb3c000047) | [BouncingBalls.java](https://github.com/jeppestaerk/My-CodeWars-Solutions-Java/blob/master/src/main/java/kata/kyu6/BouncingBalls.java) |
32 | | 6 | [Your order, please](https://www.codewars.com/kata/55c45be3b2079eccff00010f) | [YourOrderPlease.java](https://github.com/jeppestaerk/My-CodeWars-Solutions-Java/blob/master/src/main/java/kata/kyu6/YourOrderPlease.java) |
33 | | 6 | [Equal Sides Of An Array](https://www.codewars.com/kata/5679aa472b8f57fb8c000047) | [EqualSidesOfAnArray.java](https://github.com/jeppestaerk/My-CodeWars-Solutions-Java/blob/master/src/main/java/kata/kyu6/EqualSidesOfAnArray.java) |
34 | | 6 | [Find the missing letter](https://www.codewars.com/kata/5839edaa6754d6fec10000a2) | [FindTheMissingLetter.java](https://github.com/jeppestaerk/My-CodeWars-Solutions-Java/blob/master/src/main/java/kata/kyu6/FindTheMissingLetter.java) |
35 | | 6 | [Build a pile of Cubes](https://www.codewars.com/kata/5592e3bd57b64d00f3000047) | [BuildAPileOfCubes.java](https://github.com/jeppestaerk/My-CodeWars-Solutions-Java/blob/master/src/main/java/kata/kyu6/BuildAPileOfCubes.java) |
36 | | 6 | [Find the odd int](https://www.codewars.com/kata/54da5a58ea159efa38000836) | [FindTheOddInt.java](https://github.com/jeppestaerk/My-CodeWars-Solutions-Java/blob/master/src/main/java/kata/kyu6/FindTheOddInt.java) |
37 | | 7 | [Shortest Word](https://www.codewars.com/kata/57cebe1dc6fdc20c57000ac9) | [ShortestWord.java](https://github.com/jeppestaerk/My-CodeWars-Solutions-Java/blob/master/src/main/java/kata/kyu7/ShortestWord.java) |
38 | | 7 | [Jaden Casing Strings](https://www.codewars.com/kata/5390bac347d09b7da40006f6) | [JadenCasingStrings.java](https://github.com/jeppestaerk/My-CodeWars-Solutions-Java/blob/master/src/main/java/kata/kyu7/JadenCasingStrings.java) |
39 | | 7 | [Ones and Zeros](https://www.codewars.com/kata/578553c3a1b8d5c40300037c) | [OnesAndZeros.java](https://github.com/jeppestaerk/My-CodeWars-Solutions-Java/blob/master/src/main/java/kata/kyu7/OnesAndZeros.java) |
40 | | 7 | [Money, Money, Money](https://www.codewars.com/kata/563f037412e5ada593000114) | [MoneyMoneyMoney.java](https://github.com/jeppestaerk/My-CodeWars-Solutions-Java/blob/master/src/main/java/kata/kyu7/MoneyMoneyMoney.java) |
41 | | 7 | [Descending Order](https://www.codewars.com/kata/5467e4d82edf8bbf40000155) | [DescendingOrder.java](https://github.com/jeppestaerk/My-CodeWars-Solutions-Java/blob/master/src/main/java/kata/kyu7/DescendingOrder.java) |
42 | | 7 | [Growth of a Population](https://www.codewars.com/kata/563b662a59afc2b5120000c6) | [GrowthOfAPopulation.java](https://github.com/jeppestaerk/My-CodeWars-Solutions-Java/blob/master/src/main/java/kata/kyu7/GrowthOfAPopulation.java) |
43 | | 8 | [Remove String Spaces](https://www.codewars.com/kata/57eae20f5500ad98e50002c5) | [RemoveStringSpaces.java](https://github.com/jeppestaerk/My-CodeWars-Solutions-Java/blob/master/src/main/java/kata/kyu8/RemoveStringSpaces.java) |
44 | | 8 | [Multiply](https://www.codewars.com/kata/50654ddff44f800200000004) | [Multiply.java](https://github.com/jeppestaerk/My-CodeWars-Solutions-Java/blob/master/src/main/java/kata/kyu8/Multiply.java) |
45 |
46 | ## Kata Ranking (kyu)
47 | *source: [Codewars Wiki Honor & Ranks](https://github.com/Codewars/codewars.com/wiki/Honor-&-Ranks) and [Codewars Wiki Kata Ranking](https://github.com/Codewars/codewars.com/wiki/Kata-Ranking)*
48 |
49 | Ranks are used to indicate progression and difficulty. Code Warriors complete Kata which are assigned a rank, which in turn earns them a higher rank once they complete enough of them. There are two classes of ranks, Kyu and Dan. You begin with Kyu at level 8 and work your way down to level 1. Then you progress to Dan, where you work your way up from level 1 to level 8.
50 |
51 |
59 |
68 |
77 | ### **4 kyu** kata represent a competent programming level.
78 |
79 | At this level the kata begin to take some serious thought to complete. They include tasks that may handle:
80 | * Computer science concepts utilizing complex algorithms
81 | * Advanced design patterns
82 | * Understanding intricate business requirements
83 | * Advanced concepts such as concurrency, parallelism, meta programming and cryptography
84 |
85 | ### **5 kyu** kata represent a novice programming level.
86 |
87 | At this level the kata are similar to 6 kyu but more challenging. It includes:
88 | * Complex language features that require mature OOP/Functional concepts
89 | * Advanced OOP/Functional concepts
90 | * Complex Design Patterns
91 | * Advanced regular expression usage
92 |
93 | ### **6 kyu** kata represent a novice programming level.
94 |
95 | At this level the kata will start to include more advanced algorithmic challenges and more complex language features. It includes:
96 | * Complex language features (closures, scopes, monads, etc)
97 | * Complex OOP/Functional concepts
98 | * Basic Design Patterns
99 | * Complex Regular Expressions
100 |
101 | ### **7 kyu** kata represent a beginner programming level.
102 |
103 | At this level the kata will generally challenge users on their core language and API reference knowledge. Tasks such as:
104 | * Iterating arrays and returning a subset of values
105 | * Basic data type manipulations
106 | * Basic functional or object-oriented concepts
107 | * Basic Regular Expressions
108 |
109 | ### **8 kyu** kata represent a beginner level.
110 |
111 | At this level the kata is only challenging for users new to programming. This includes programming tasks such as:
112 | * Defining a simple function (i.e. hello world)
113 | * Basic variable assignments
114 | * Fixing basic syntax issues
115 | * Trivial algorithms such as basic if/else statements
--------------------------------------------------------------------------------
/build.gradle:
--------------------------------------------------------------------------------
1 | plugins {
2 | id 'java'
3 | id 'jacoco'
4 | id "org.sonarqube" version "2.6.1"
5 | }
6 |
7 | group 'io.staerk'
8 | version '1.0'
9 |
10 | sourceCompatibility = 1.8
11 |
12 | repositories {
13 | mavenCentral()
14 | }
15 |
16 | dependencies {
17 | testCompile group: 'junit', name: 'junit', version: '4.12'
18 | }
19 |
20 | jacoco {
21 | toolVersion = "0.7.9"
22 | }
23 |
24 | jacocoTestReport {
25 | reports {
26 | xml.enabled true
27 | csv.enabled false
28 | html.enabled false
29 | }
30 | }
31 |
32 | sonarqube {
33 | properties {
34 | property "sonar.organization", System.getenv('SONARCLOUD_ORGANIZATION')
35 | property "sonar.host.url", System.getenv('SONARCLOUD_HOST')
36 | property "sonar.login", System.getenv('SONARCLOUD_TOKEN')
37 | }
38 | }
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jeppestaerk/My-CodeWars-Solutions-Java/e76b5238afd4e3f95a37dbae445a8ebaab66f555/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Thu Jan 18 20:05:18 CET 2018
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-4.4.1-bin.zip
7 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env sh
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Attempt to set APP_HOME
10 | # Resolve links: $0 may be a link
11 | PRG="$0"
12 | # Need this for relative symlinks.
13 | while [ -h "$PRG" ] ; do
14 | ls=`ls -ld "$PRG"`
15 | link=`expr "$ls" : '.*-> \(.*\)$'`
16 | if expr "$link" : '/.*' > /dev/null; then
17 | PRG="$link"
18 | else
19 | PRG=`dirname "$PRG"`"/$link"
20 | fi
21 | done
22 | SAVED="`pwd`"
23 | cd "`dirname \"$PRG\"`/" >/dev/null
24 | APP_HOME="`pwd -P`"
25 | cd "$SAVED" >/dev/null
26 |
27 | APP_NAME="Gradle"
28 | APP_BASE_NAME=`basename "$0"`
29 |
30 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
31 | DEFAULT_JVM_OPTS=""
32 |
33 | # Use the maximum available, or set MAX_FD != -1 to use that value.
34 | MAX_FD="maximum"
35 |
36 | warn () {
37 | echo "$*"
38 | }
39 |
40 | die () {
41 | echo
42 | echo "$*"
43 | echo
44 | exit 1
45 | }
46 |
47 | # OS specific support (must be 'true' or 'false').
48 | cygwin=false
49 | msys=false
50 | darwin=false
51 | nonstop=false
52 | case "`uname`" in
53 | CYGWIN* )
54 | cygwin=true
55 | ;;
56 | Darwin* )
57 | darwin=true
58 | ;;
59 | MINGW* )
60 | msys=true
61 | ;;
62 | NONSTOP* )
63 | nonstop=true
64 | ;;
65 | esac
66 |
67 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
68 |
69 | # Determine the Java command to use to start the JVM.
70 | if [ -n "$JAVA_HOME" ] ; then
71 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
72 | # IBM's JDK on AIX uses strange locations for the executables
73 | JAVACMD="$JAVA_HOME/jre/sh/java"
74 | else
75 | JAVACMD="$JAVA_HOME/bin/java"
76 | fi
77 | if [ ! -x "$JAVACMD" ] ; then
78 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
79 |
80 | Please set the JAVA_HOME variable in your environment to match the
81 | location of your Java installation."
82 | fi
83 | else
84 | JAVACMD="java"
85 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
86 |
87 | Please set the JAVA_HOME variable in your environment to match the
88 | location of your Java installation."
89 | fi
90 |
91 | # Increase the maximum file descriptors if we can.
92 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
93 | MAX_FD_LIMIT=`ulimit -H -n`
94 | if [ $? -eq 0 ] ; then
95 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
96 | MAX_FD="$MAX_FD_LIMIT"
97 | fi
98 | ulimit -n $MAX_FD
99 | if [ $? -ne 0 ] ; then
100 | warn "Could not set maximum file descriptor limit: $MAX_FD"
101 | fi
102 | else
103 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
104 | fi
105 | fi
106 |
107 | # For Darwin, add options to specify how the application appears in the dock
108 | if $darwin; then
109 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
110 | fi
111 |
112 | # For Cygwin, switch paths to Windows format before running java
113 | if $cygwin ; then
114 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
115 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
116 | JAVACMD=`cygpath --unix "$JAVACMD"`
117 |
118 | # We build the pattern for arguments to be converted via cygpath
119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
120 | SEP=""
121 | for dir in $ROOTDIRSRAW ; do
122 | ROOTDIRS="$ROOTDIRS$SEP$dir"
123 | SEP="|"
124 | done
125 | OURCYGPATTERN="(^($ROOTDIRS))"
126 | # Add a user-defined pattern to the cygpath arguments
127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
129 | fi
130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
131 | i=0
132 | for arg in "$@" ; do
133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
135 |
136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
138 | else
139 | eval `echo args$i`="\"$arg\""
140 | fi
141 | i=$((i+1))
142 | done
143 | case $i in
144 | (0) set -- ;;
145 | (1) set -- "$args0" ;;
146 | (2) set -- "$args0" "$args1" ;;
147 | (3) set -- "$args0" "$args1" "$args2" ;;
148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
154 | esac
155 | fi
156 |
157 | # Escape application args
158 | save () {
159 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
160 | echo " "
161 | }
162 | APP_ARGS=$(save "$@")
163 |
164 | # Collect all arguments for the java command, following the shell quoting and substitution rules
165 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
166 |
167 | # by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong
168 | if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then
169 | cd "$(dirname "$0")"
170 | fi
171 |
172 | exec "$JAVACMD" "$@"
173 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | set DIRNAME=%~dp0
12 | if "%DIRNAME%" == "" set DIRNAME=.
13 | set APP_BASE_NAME=%~n0
14 | set APP_HOME=%DIRNAME%
15 |
16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
17 | set DEFAULT_JVM_OPTS=
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windows variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 |
53 | :win9xME_args
54 | @rem Slurp the command line arguments.
55 | set CMD_LINE_ARGS=
56 | set _SKIP=2
57 |
58 | :win9xME_args_slurp
59 | if "x%~1" == "x" goto execute
60 |
61 | set CMD_LINE_ARGS=%*
62 |
63 | :execute
64 | @rem Setup the command line
65 |
66 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
67 |
68 | @rem Execute Gradle
69 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
70 |
71 | :end
72 | @rem End local scope for the variables with windows NT shell
73 | if "%ERRORLEVEL%"=="0" goto mainEnd
74 |
75 | :fail
76 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
77 | rem the _cmd.exe /c_ return code!
78 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
79 | exit /b 1
80 |
81 | :mainEnd
82 | if "%OS%"=="Windows_NT" endlocal
83 |
84 | :omega
85 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | rootProject.name = 'codewars'
2 |
3 |
--------------------------------------------------------------------------------
/src/main/java/kata/kyu4/BattleShipsSunkDamagedOrNotTouched.java:
--------------------------------------------------------------------------------
1 | package kata.kyu4;
2 |
3 | import java.util.HashMap;
4 | import java.util.Map;
5 |
6 | public class BattleShipsSunkDamagedOrNotTouched {
7 | private static final String SUNK = "sunk";
8 | private static final String DAMAGED = "damaged";
9 | private static final String NOT_TOUCHED = "notTouched";
10 | private static final String POINTS = "points";
11 |
12 | public static Map damagedOrSunk(final int[][] board, final int[][] attacks) {
13 |
14 | Map shipsPre = new HashMap<>();
15 | Map shipsPost = new HashMap<>();
16 | Map result = new HashMap<>();
17 |
18 | checkBoard(board, shipsPre);
19 | runAttacks(board, attacks);
20 | checkBoard(board, shipsPost);
21 | validateGame(shipsPre, shipsPost, result);
22 | calculatePoints(result);
23 |
24 | return result;
25 | }
26 |
27 | private static void calculatePoints(Map result) {
28 | result.put(SUNK, result.getOrDefault(SUNK, 0.0));
29 | result.put(DAMAGED, result.getOrDefault(DAMAGED, 0.0));
30 | result.put(NOT_TOUCHED, result.getOrDefault(NOT_TOUCHED, 0.0));
31 | result.put(POINTS, (result.getOrDefault(SUNK, 0.0) * 1.0) + (result.getOrDefault(DAMAGED, 0.0) * 0.5) + (result.getOrDefault(NOT_TOUCHED, 0.0) * -1.0));
32 | }
33 |
34 | private static void validateGame(Map shipsPre, Map shipsPost, Map result) {
35 | shipsPre.forEach((key, valPre) -> {
36 | Integer valPost = shipsPost.getOrDefault(key, 0);
37 | if (valPre == valPost) result.put(NOT_TOUCHED, 1 + result.getOrDefault(NOT_TOUCHED, 0.0));
38 | else if (valPost > 0) result.put(DAMAGED, 1 + result.getOrDefault(DAMAGED, 0.0));
39 | else if (valPost == 0) result.put(SUNK, 1 + result.getOrDefault(SUNK, 0.0));
40 | });
41 | }
42 |
43 | private static void runAttacks(int[][] board, int[][] attacks) {
44 | for (int[] attack : attacks) {
45 | board[board.length - attack[1]][attack[0] - 1] = 0;
46 | }
47 | }
48 |
49 | private static void checkBoard(int[][] board, Map shipsPre) {
50 | for (int[] row : board) {
51 | for (int val : row) {
52 | if (val > 0) shipsPre.put(val, 1 + shipsPre.getOrDefault(val, 0));
53 | }
54 | }
55 | }
56 | }
57 |
--------------------------------------------------------------------------------
/src/main/java/kata/kyu4/CodewarsStyleRankingSystem.java:
--------------------------------------------------------------------------------
1 | package kata.kyu4;
2 |
3 | public class CodewarsStyleRankingSystem {
4 |
5 | public static class User {
6 | int rank = -8;
7 | int progress = 0;
8 |
9 | public void incProgress(int aRank) {
10 | if (aRank < -8 || aRank > 8 || aRank == 0) throw new IllegalArgumentException();
11 | if (this.rank < 0 && aRank > 0) aRank--;
12 | if (this.rank > 0 && aRank < 0) aRank++;
13 | if (this.rank == aRank) this.progress += 3;
14 | if (this.rank - 1 == aRank) this.progress += 1;
15 | if (this.rank - 2 >= aRank) this.progress += 0;
16 | if (this.rank < aRank) {
17 | int d = aRank - this.rank;
18 | this.progress += (10 * d * d);
19 | }
20 | while (this.progress >= 100 && this.rank < 8) {
21 | if (++this.rank == 0) this.rank++;
22 | this.progress -= 100;
23 | }
24 | if (this.rank == 8) this.progress = 0;
25 | }
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/src/main/java/kata/kyu4/DecodeTheMorseCodeAdvanced.java:
--------------------------------------------------------------------------------
1 | package kata.kyu4;
2 |
3 | import utils.MorseCode;
4 |
5 | public class DecodeTheMorseCodeAdvanced {
6 | public static String decodeBits(String bits) {
7 | String digits = bits.replaceAll("^0*|0*$", "");
8 | int timeUnit = digits.length();
9 | int i = 0;
10 | while (i < digits.length()) {
11 | int tempUnit = 0;
12 | while (i < digits.length() && digits.charAt(i) == '1') {
13 | tempUnit++;
14 | i++;
15 | }
16 | if (tempUnit != 0 && tempUnit < timeUnit) timeUnit = tempUnit;
17 | i++;
18 | }
19 | int j = 0;
20 | while (j < digits.length()) {
21 | int tempUnit = 0;
22 | while (j < digits.length() && digits.charAt(j) == '0') {
23 | tempUnit++;
24 | j++;
25 | }
26 | if (tempUnit != 0 && tempUnit < timeUnit) timeUnit = tempUnit;
27 | j++;
28 | }
29 | return digits.replaceAll("^0*|0*$", "").replaceAll("1{" + timeUnit * 3 + "}", "-").replaceAll("1{" + timeUnit + "}", ".").replaceAll("0{" + timeUnit * 6 + "}", " ").replaceAll("0{" + timeUnit * 3 + "}", " ").replaceAll("0{" + timeUnit + "}", "");
30 | }
31 |
32 | public static String decodeMorse(String morseCode) {
33 | StringBuilder sb = new StringBuilder();
34 | for (String code : morseCode.trim().replaceAll(" ", " / ").split(" "))
35 | sb.append(code.equals("/") ? " " : MorseCode.get(code));
36 | return sb.toString();
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/src/main/java/kata/kyu4/HumanReadableDurationFormat.java:
--------------------------------------------------------------------------------
1 | package kata.kyu4;
2 |
3 | public class HumanReadableDurationFormat {
4 |
5 | public static String formatDuration(int s) {
6 |
7 | int time = s;
8 | int years = s / 31536000;
9 | s -= years * 31536000;
10 | int days = s / 86400;
11 | s -= days * 86400;
12 | int hours = s / 3600;
13 | s -= hours * 3600;
14 | int minutes = s / 60;
15 | s -= minutes * 60;
16 | int seconds = s;
17 |
18 | StringBuilder sb = new StringBuilder();
19 | if (time == 0) sb.append("now");
20 | time = processYears(time, years, sb);
21 | time = processDays(time, days, sb);
22 | time = processHours(time, hours, sb);
23 | processMinutes(time, minutes, sb);
24 | processSeconds(seconds, sb);
25 | if (sb.indexOf(",") > 0) sb.replace(sb.lastIndexOf(","), sb.lastIndexOf(",") + 1, " and");
26 |
27 | return sb.toString().trim();
28 | }
29 |
30 | private static void processSeconds(int seconds, StringBuilder sb) {
31 | if (seconds > 0) {
32 | sb.append(seconds).append(" second");
33 | appendS(seconds, sb);
34 | }
35 | }
36 |
37 | private static void processMinutes(int time, int minutes, StringBuilder sb) {
38 | if (minutes > 0) {
39 | sb.append(minutes).append(" minute");
40 | appendS(minutes, sb);
41 | time -= minutes * 60;
42 | postfix(time, sb);
43 | }
44 | }
45 |
46 | private static void appendS(int count, StringBuilder sb) {
47 | if (count > 1) sb.append("s");
48 | }
49 |
50 | private static void postfix(int time, StringBuilder sb) {
51 | if (time > 0) sb.append(", ");
52 | else sb.append(" ");
53 | }
54 |
55 | private static int processHours(int time, int hours, StringBuilder sb) {
56 | if (hours > 0) {
57 | sb.append(hours).append(" hour");
58 | appendS(hours, sb);
59 | time -= hours * 3600;
60 | postfix(time, sb);
61 | }
62 | return time;
63 | }
64 |
65 | private static int processDays(int time, int days, StringBuilder sb) {
66 | if (days > 0) {
67 | sb.append(days).append(" day");
68 | appendS(days, sb);
69 | time -= days * 86400;
70 | postfix(time, sb);
71 | }
72 | return time;
73 | }
74 |
75 | private static int processYears(int time, int years, StringBuilder sb) {
76 | if (years > 0) {
77 | sb.append(years).append(" year");
78 | appendS(years, sb);
79 | time -= years * 31536000;
80 | postfix(time, sb);
81 | }
82 | return time;
83 | }
84 | }
85 |
--------------------------------------------------------------------------------
/src/main/java/kata/kyu4/LongestCommonSubsequencePerformanceVersion.java:
--------------------------------------------------------------------------------
1 | package kata.kyu4;
2 |
3 | public class LongestCommonSubsequencePerformanceVersion {
4 |
5 | static String lcs(String a, String b) {
6 | int m = a.length();
7 | int n = b.length();
8 | return lcs(a, b, m, n);
9 | }
10 |
11 | static String lcs(String x, String y, int m, int n) {
12 | int[][] l = new int[m + 1][n + 1];
13 |
14 | for (int i = 0; i <= m; i++) {
15 | for (int j = 0; j <= n; j++) {
16 | if (i == 0 || j == 0)
17 | l[i][j] = 0;
18 | else if (x.charAt(i - 1) == y.charAt(j - 1))
19 | l[i][j] = l[i - 1][j - 1] + 1;
20 | else
21 | l[i][j] = Math.max(l[i - 1][j], l[i][j - 1]);
22 | }
23 | }
24 |
25 | int index = l[m][n];
26 | int temp = index;
27 |
28 | char[] lcs = new char[index + 1];
29 | lcs[index] = '\0';
30 |
31 | int i = m;
32 | int j = n;
33 | while (i > 0 && j > 0) {
34 | if (x.charAt(i - 1) == y.charAt(j - 1)) {
35 | lcs[index - 1] = x.charAt(i - 1);
36 | i--;
37 | j--;
38 | index--;
39 | } else if (l[i - 1][j] > l[i][j - 1])
40 | i--;
41 | else
42 | j--;
43 | }
44 |
45 | return getString(temp, lcs);
46 | }
47 |
48 | private static String getString(int temp, char[] lcs) {
49 | StringBuilder sb = new StringBuilder();
50 | for (int k = 0; k <= temp; k++) {
51 | sb.append(lcs[k]);
52 | }
53 | return sb.deleteCharAt(temp).toString();
54 | }
55 | }
56 |
--------------------------------------------------------------------------------
/src/main/java/kata/kyu4/NumberOfProperFractionsWithDenominatorD.java:
--------------------------------------------------------------------------------
1 | package kata.kyu4;
2 |
3 | import java.util.ArrayList;
4 | import java.util.List;
5 | import java.util.stream.Collectors;
6 |
7 | public class NumberOfProperFractionsWithDenominatorD {
8 |
9 | public static long properFractions(long n) {
10 | if (n == 1) return 0;
11 | long c = n;
12 | List pfs = primeFactors(n);
13 | for (long pf : pfs) c -= c / pf;
14 | return c;
15 | }
16 |
17 | private static List primeFactors(long numbers) {
18 | long n = numbers;
19 | List factors = new ArrayList<>();
20 | for (long i = 2; i <= n / i; i++)
21 | while (n % i == 0) {
22 | factors.add(i);
23 | n /= i;
24 | }
25 | if (n > 1) factors.add(n);
26 | return factors.stream().distinct().sorted().collect(Collectors.toList());
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/src/main/java/kata/kyu4/RecoverASecretStringFromRandomTriplets.java:
--------------------------------------------------------------------------------
1 | package kata.kyu4;
2 |
3 | import java.util.ArrayList;
4 | import java.util.List;
5 | import java.util.stream.Collectors;
6 |
7 |
8 | public class RecoverASecretStringFromRandomTriplets {
9 | public String recoverSecret(char[][] triplets) {
10 | List secret = new ArrayList<>();
11 | for (int i = 0; i < triplets.length; i++) {
12 | char[] triplet = triplets[i];
13 | handleTriplet(secret, triplet);
14 | }
15 | for (int i = triplets.length - 1; i >= 0; i--) {
16 | char[] triplet = triplets[i];
17 | handleTriplet(secret, triplet);
18 | }
19 | return secret.stream().map(Object::toString).collect(Collectors.joining());
20 | }
21 |
22 | private void handleTriplet(List secret, char[] triplet) {
23 | Boolean pristine = true;
24 | for (char ch : triplet) if (secret.contains(ch)) pristine = false;
25 | if (pristine) {
26 | handlePristineTriplet(secret, triplet);
27 | } else {
28 | handleDirtyTriplet(secret, triplet);
29 | }
30 | }
31 |
32 | private void handlePristineTriplet(List secret, char[] triplet) {
33 | for (char ch : triplet) {
34 | secret.add(ch);
35 | }
36 | }
37 |
38 | private void handleDirtyTriplet(List secret, char[] triplet) {
39 | for (int i = 0; i < triplet.length; i++) {
40 | if (secret.contains(triplet[i]) && i < triplet.length - 1) {
41 | if (!secret.contains(triplet[i + 1])) secret.add(secret.indexOf(triplet[i]), triplet[i + 1]);
42 | else if (secret.indexOf(triplet[i]) > secret.indexOf(triplet[i + 1])) {
43 | secret.remove(secret.indexOf(triplet[i]));
44 | secret.add(secret.indexOf(triplet[i + 1]), triplet[i]);
45 | }
46 | }
47 | if (secret.contains(triplet[i]) && i > 0) {
48 | if (!secret.contains(triplet[i - 1])) secret.add(secret.indexOf(triplet[i]), triplet[i - 1]);
49 | else if (secret.indexOf(triplet[i]) < secret.indexOf(triplet[i - 1])) {
50 | secret.remove(secret.indexOf(triplet[i]));
51 | secret.add(secret.indexOf(triplet[i - 1]) + 1, triplet[i]);
52 | }
53 | }
54 | }
55 | }
56 | }
57 |
--------------------------------------------------------------------------------
/src/main/java/kata/kyu4/ReversePolishNotationCalculator.java:
--------------------------------------------------------------------------------
1 | package kata.kyu4;
2 |
3 | import java.util.ArrayDeque;
4 | import java.util.Deque;
5 |
6 | public class ReversePolishNotationCalculator {
7 | public double evaluate(String expr) {
8 | if (expr.isEmpty()) return 0d;
9 | Deque stack = new ArrayDeque<>();
10 | String[] sArray = expr.split(" ");
11 | for (int i = 0; i < sArray.length; i++) {
12 | String ch = sArray[i];
13 | if (ch.matches("\\+")) {
14 | String b = stack.pop();
15 | String a = stack.pop();
16 | int s = Integer.valueOf(a) + Integer.valueOf(b);
17 | stack.push(String.valueOf(s));
18 | } else if (ch.matches("\\-")) {
19 | String b = stack.pop();
20 | String a = stack.pop();
21 | int s = Integer.valueOf(a) - Integer.valueOf(b);
22 | stack.push(String.valueOf(s));
23 | } else if (ch.matches("\\*")) {
24 | String b = stack.pop();
25 | String a = stack.pop();
26 | int s = Integer.valueOf(a) * Integer.valueOf(b);
27 | stack.push(String.valueOf(s));
28 | } else if (ch.matches("\\/")) {
29 | String b = stack.pop();
30 | String a = stack.pop();
31 | int s = Integer.valueOf(a) / Integer.valueOf(b);
32 | stack.push(String.valueOf(s));
33 | } else {
34 | stack.push(ch);
35 | }
36 | }
37 |
38 | return Double.valueOf(stack.pop());
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/src/main/java/kata/kyu4/RomanNumeralsEncoder.java:
--------------------------------------------------------------------------------
1 | package kata.kyu4;
2 |
3 | import java.util.TreeMap;
4 |
5 | public class RomanNumeralsEncoder {
6 |
7 | private static final TreeMap map = new TreeMap<>();
8 |
9 | static {
10 | map.put(1000, "M");
11 | map.put(900, "CM");
12 | map.put(500, "D");
13 | map.put(400, "CD");
14 | map.put(100, "C");
15 | map.put(90, "XC");
16 | map.put(50, "L");
17 | map.put(40, "XL");
18 | map.put(10, "X");
19 | map.put(9, "IX");
20 | map.put(5, "V");
21 | map.put(4, "IV");
22 | map.put(1, "I");
23 | }
24 |
25 | private static String toRoman(int number) {
26 | int l = map.floorKey(number);
27 | if (number == l) return map.get(number);
28 | return map.get(l) + toRoman(number - l);
29 | }
30 |
31 | public String solution(int n) {
32 | return toRoman(n);
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/src/main/java/kata/kyu4/SquareIntoSquaresProtectTrees.java:
--------------------------------------------------------------------------------
1 | package kata.kyu4;
2 |
3 | import java.util.ArrayList;
4 | import java.util.List;
5 | import java.util.stream.Collectors;
6 |
7 | public class SquareIntoSquaresProtectTrees {
8 |
9 | public String decompose(long n) {
10 |
11 | int index;
12 | List numbers = new ArrayList<>();
13 | long nSquare = (long) Math.pow(n, 2);
14 | long sum = fillList(n, nSquare, 0, numbers);
15 | index = numbers.size();
16 | while (sum != nSquare && index > 0) {
17 | n = numbers.get(--index);
18 | numbers = numbers.subList(0, index);
19 | sum = getSum(numbers);
20 | sum = fillList(n, nSquare, sum, numbers);
21 | if (index == 0) index = numbers.size();
22 | }
23 | return (getSum(numbers) == nSquare) ? numbers.stream().sorted().map(Object::toString).collect(Collectors.joining(" ")) : null;
24 | }
25 |
26 | private long fillList(long n, long nSquare, long sum, List numbers) {
27 | while (sum < nSquare && --n > 0) {
28 | long nextNum = nextNumber((nSquare - sum), n);
29 | numbers.add(nextNum);
30 | n = nextNum;
31 | sum += (long) Math.pow(nextNum, 2);
32 | }
33 | return sum;
34 | }
35 |
36 | private long getSum(List numbers) {
37 | long sum = 0;
38 | for (long num : numbers) sum += (long) Math.pow(num, 2);
39 | return sum;
40 | }
41 | private long nextNumber(long restSum, long n) {
42 | long tempSum = (long) Math.pow(n, 2);
43 | while (tempSum > restSum) tempSum = (long) Math.pow(--n, 2);
44 | return n;
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/src/main/java/kata/kyu4/SumByFactors.java:
--------------------------------------------------------------------------------
1 | package kata.kyu4;
2 |
3 | import java.util.ArrayList;
4 | import java.util.HashMap;
5 | import java.util.List;
6 | import java.util.Map;
7 | import java.util.stream.Collectors;
8 |
9 | public class SumByFactors {
10 | public static String sumOfDivided(int[] l) {
11 | HashMap results = new HashMap<>();
12 | StringBuilder sb = new StringBuilder();
13 | for (Integer num : l) {
14 | for (Integer primeNum : primeFactors(num)) {
15 | if (!results.containsKey(primeNum)) {
16 | results.put(primeNum, num);
17 | } else {
18 | results.put(primeNum, results.get(primeNum) + num);
19 | }
20 | }
21 | }
22 | results.entrySet().stream().sorted(Map.Entry.comparingByKey()).forEach(e -> sb.append("(" + e.getKey() + " " + e.getValue() + ")"));
23 | return sb.toString();
24 | }
25 |
26 | private static List primeFactors(int number) {
27 | int n = number;
28 | List factors = new ArrayList<>();
29 | while (n % 2 == 0) {
30 | factors.add(2);
31 | n /= 2;
32 | }
33 | for (int i = 3; i <= n / i; i++) {
34 | while (n % i == 0) {
35 | factors.add(i);
36 | n /= i;
37 | }
38 | }
39 | if (n > 2) {
40 | factors.add(n);
41 | }
42 | return factors.stream().distinct().collect(Collectors.toList());
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/src/main/java/kata/kyu4/TenPinBowling.java:
--------------------------------------------------------------------------------
1 | package kata.kyu4;
2 |
3 | import java.util.ArrayList;
4 | import java.util.List;
5 |
6 | public class TenPinBowling {
7 | public static int bowlingScore(String f) {
8 | Integer score = 0;
9 | List rolls = new ArrayList<>();
10 | String[] frames = f.split(" ");
11 | for (String frame : frames) {
12 | String[] balls = frame.split("");
13 | for (String ball : balls) {
14 | if (ball.matches("X")) rolls.add(10);
15 | else if (ball.matches("/")) rolls.add(10 - rolls.get(rolls.size() - 1));
16 | else rolls.add(Integer.valueOf(ball));
17 | }
18 | }
19 | rolls.add(0);
20 | rolls.add(0);
21 |
22 | Integer frame = 0;
23 | for (int i = 0; i < 10; i++) {
24 | Integer point = rolls.get(frame);
25 | Integer nPoint = rolls.get(frame + 1);
26 | Integer nnPoint = rolls.get(frame + 2);
27 | if (point == 10) {
28 | score += 10 + (nPoint + nnPoint);
29 | frame++;
30 | } else if ((point + nPoint) == 10) {
31 | score += 10 + (nnPoint);
32 | frame += 2;
33 | } else {
34 | score += point + nPoint;
35 | frame += 2;
36 | }
37 | }
38 |
39 | return score;
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/src/main/java/kata/kyu5/ConvertStringToCamelCase.java:
--------------------------------------------------------------------------------
1 | package kata.kyu5;
2 |
3 | public class ConvertStringToCamelCase {
4 | static String toCamelCase(String s) {
5 | String[] words = s.split("[-_]");
6 | StringBuilder sb = new StringBuilder(words[0]);
7 | for (int i = 1; i < words.length; i++)
8 | sb.append(words[i].substring(0, 1).toUpperCase()).append(words[i].substring(1));
9 | return sb.toString();
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/src/main/java/kata/kyu5/Scramblies.java:
--------------------------------------------------------------------------------
1 | package kata.kyu5;
2 |
3 | import java.util.HashMap;
4 |
5 | public class Scramblies {
6 | public static boolean scramble(String str1, String str2) {
7 | HashMap map = new HashMap<>();
8 | for (char ch : str1.toCharArray()) map.put(ch, 1 + map.getOrDefault(ch, 0));
9 | for (char ch : str2.toCharArray()) {
10 | Integer count = map.getOrDefault(ch, 0);
11 | if (count == 0) return false;
12 | map.put(ch, --count);
13 | }
14 | return true;
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/src/main/java/kata/kyu6/BouncingBalls.java:
--------------------------------------------------------------------------------
1 | package kata.kyu6;
2 |
3 | public class BouncingBalls {
4 | public static int bouncingBall(double h, double bounce, double window) {
5 | if (h <= 0 || bounce <= 0 || bounce >= 1 || window >= h) return -1;
6 | double bounceHight = h * bounce;
7 | int count = 1;
8 | while (bounceHight > window) {
9 | count += 2;
10 | bounceHight = bounceHight * bounce;
11 | }
12 | return count;
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/src/main/java/kata/kyu6/BuildAPileOfCubes.java:
--------------------------------------------------------------------------------
1 | package kata.kyu6;
2 |
3 | public class BuildAPileOfCubes {
4 | public static int findNb(long m) {
5 | int n = 0;
6 | do {
7 | m = m - (long) Math.pow(n++ + 1d, 3d);
8 | } while (m > 0);
9 | return (m == 0) ? n : -1;
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/src/main/java/kata/kyu6/DecodeTheMorseCode.java:
--------------------------------------------------------------------------------
1 | package kata.kyu6;
2 |
3 | import utils.MorseCode;
4 |
5 | public class DecodeTheMorseCode {
6 | public static String decode(String morseCode) {
7 | StringBuilder sb = new StringBuilder();
8 | for (String code : morseCode.trim().replace(" ", " / ").split(" "))
9 | sb.append(code.equals("/") ? " " : MorseCode.get(code));
10 | return sb.toString();
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/src/main/java/kata/kyu6/Dubstep.java:
--------------------------------------------------------------------------------
1 | package kata.kyu6;
2 |
3 | public class Dubstep {
4 | public static String songDecoder(String song) {
5 | return song.replaceAll("(WUB)+", " ").trim();
6 | }
7 | }
8 |
--------------------------------------------------------------------------------
/src/main/java/kata/kyu6/EqualSidesOfAnArray.java:
--------------------------------------------------------------------------------
1 | package kata.kyu6;
2 |
3 | public class EqualSidesOfAnArray {
4 | public static int findEvenIndex(int[] arr) {
5 | int index;
6 | int sumLeft;
7 | int sumRight;
8 | index = 0;
9 | while (index++ < arr.length - 1) {
10 | sumLeft = sumRight = 0;
11 | for (int i = 0; i < index; i++) sumLeft += arr[i];
12 | for (int j = arr.length - 1; j > index; j--) sumRight += arr[j];
13 | if (sumLeft == sumRight) return index;
14 | }
15 | return -1;
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/src/main/java/kata/kyu6/FindTheMissingLetter.java:
--------------------------------------------------------------------------------
1 | package kata.kyu6;
2 |
3 | public class FindTheMissingLetter {
4 | public static char findMissingLetter(char[] array) {
5 | String abc = "abcdefghijklmnopqrstuvwxyz";
6 | abc = abc + abc.toUpperCase();
7 | int i0 = abc.indexOf(array[0]);
8 | for (int i = 0; i < array.length; i++) {
9 | if (abc.charAt(i0 + i) != array[i])
10 | return (char) ((int) array[i] - 1);
11 | }
12 | return ' ';
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/src/main/java/kata/kyu6/FindTheOddInt.java:
--------------------------------------------------------------------------------
1 | package kata.kyu6;
2 |
3 | import java.util.HashMap;
4 | import java.util.Map;
5 |
6 | public class FindTheOddInt {
7 | public static int findIt(int[] a) {
8 | HashMap map = new HashMap<>();
9 | for (int number : a) {
10 | int count = map.getOrDefault(number, 0);
11 | map.put(number, count + 1);
12 | }
13 | for (Map.Entry entry : map.entrySet()) {
14 | if (entry.getValue() % 2 != 0) return entry.getKey();
15 | }
16 | return 0;
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/src/main/java/kata/kyu6/GiveMeADiamond.java:
--------------------------------------------------------------------------------
1 | package kata.kyu6;
2 |
3 | public class GiveMeADiamond {
4 | public static String print(int n) {
5 | if ((n % 2) == 0 || n <= 0) return null;
6 | StringBuilder diamond = new StringBuilder();
7 | for (int i = 1; i < n; i += 2) {
8 | for (int j = 0; j < (n - i) / 2; j++) diamond.append(" ");
9 | for (int k = 0; k < i; k++) diamond.append("*");
10 | diamond.append("\n");
11 | }
12 | for (int i = n; i > 0; i -= 2) {
13 | for (int j = 0; j < (n - i) / 2; j++) diamond.append(" ");
14 | for (int k = 0; k < i; k++) diamond.append("*");
15 | diamond.append("\n");
16 | }
17 | return diamond.toString();
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/src/main/java/kata/kyu6/SortTheOdd.java:
--------------------------------------------------------------------------------
1 | package kata.kyu6;
2 |
3 | public class SortTheOdd {
4 | public static int[] sortArray(int[] array) {
5 | int length = array.length;
6 | if (length <= 0) return array;
7 | int i = 0;
8 | while (i < length) {
9 | while (i < length && array[i] % 2 == 0) i++;
10 | int j = i + 1;
11 | while (j < length) {
12 | while (j < length && array[j] % 2 == 0) j++;
13 | if (j < length && array[i] % 2 != 0 && array[j] % 2 != 0 && array[i] > array[j]) {
14 | int temp = array[i];
15 | array[i] = array[j];
16 | array[j] = temp;
17 | }
18 | j++;
19 | }
20 | i++;
21 | }
22 | return array;
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/src/main/java/kata/kyu6/TripleTrouble.java:
--------------------------------------------------------------------------------
1 | package kata.kyu6;
2 |
3 | public class TripleTrouble {
4 |
5 | public static int tripleDouble(long num1, long num2) {
6 | String n1 = Long.toString(num1);
7 | String n2 = Long.toString(num2);
8 | for (int i = 2; i < n1.length(); i++) {
9 | if (n2.lastIndexOf(n1.charAt(i)) > 0 && (n1.charAt(i) == n1.charAt(i - 1) && n1.charAt(i) == n1.charAt(i - 2)) && n2.charAt(n2.lastIndexOf(n1.charAt(i))) == n2.charAt(n2.lastIndexOf(n1.charAt(i)) - 1))
10 | return 1;
11 | }
12 | return 0;
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/src/main/java/kata/kyu6/VasyaClerk.java:
--------------------------------------------------------------------------------
1 | package kata.kyu6;
2 |
3 | public class VasyaClerk {
4 | public static String tickets(int[] peopleInLine) {
5 | int d25 = 0;
6 | int d50 = 0;
7 | for (int i = 0; i < peopleInLine.length; i++) {
8 | if (peopleInLine[i] == 25) d25++;
9 | if (peopleInLine[i] == 50) {
10 | d25--;
11 | d50++;
12 | }
13 | if (peopleInLine[i] == 100) {
14 | if (d50 > 0) {
15 | d50--;
16 | d25--;
17 | } else {
18 | d25 -= 3;
19 | }
20 | }
21 | if (d25 < 0) return "NO";
22 | }
23 | return "YES";
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/src/main/java/kata/kyu6/YourOrderPlease.java:
--------------------------------------------------------------------------------
1 | package kata.kyu6;
2 |
3 | public class YourOrderPlease {
4 | public static String order(String words) {
5 | String[] strarr = words.split(" ");
6 | StringBuilder sb = new StringBuilder();
7 | for (int i = 1; i <= strarr.length; i++) {
8 | for (String str : strarr) {
9 | if (str.contains(Integer.toString(i))) sb.append(str).append(" ");
10 | }
11 | }
12 | return sb.toString().trim();
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/src/main/java/kata/kyu7/DescendingOrder.java:
--------------------------------------------------------------------------------
1 | package kata.kyu7;
2 |
3 | import java.util.Arrays;
4 |
5 | public class DescendingOrder {
6 | public static int sortDesc(final int num) {
7 | char[] tempArray = String.valueOf(num).toCharArray();
8 | Arrays.sort(tempArray);
9 | return Integer.parseInt(new StringBuilder(new String(tempArray)).reverse().toString());
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/src/main/java/kata/kyu7/GrowthOfAPopulation.java:
--------------------------------------------------------------------------------
1 | package kata.kyu7;
2 |
3 | public class GrowthOfAPopulation {
4 | public static int nbYear(int p0, double percent, int aug, int p) {
5 | int years = 0;
6 | int inhabitants = p0;
7 | while(inhabitants < p)
8 | {
9 | inhabitants = (int)(inhabitants + (inhabitants * (float)(percent/100)) + aug);
10 | years++;
11 | }
12 | return years;
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/src/main/java/kata/kyu7/JadenCasingStrings.java:
--------------------------------------------------------------------------------
1 | package kata.kyu7;
2 |
3 | public class JadenCasingStrings {
4 | public String toJadenCase(String phrase) {
5 | if (phrase == null || phrase.equals("")) return null;
6 | StringBuilder jadenCase = new StringBuilder();
7 | for (String word : phrase.split(" ")) {
8 | jadenCase.append(word.substring(0, 1).toUpperCase()).append(word.substring(1)).append(" ");
9 | }
10 | return jadenCase.toString().trim();
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/src/main/java/kata/kyu7/MoneyMoneyMoney.java:
--------------------------------------------------------------------------------
1 | package kata.kyu7;
2 |
3 | public class MoneyMoneyMoney {
4 | public static int calculateYears(double principal, double interest, double tax, double desired) {
5 | int years = 0;
6 | while (principal < desired) {
7 | principal += (principal * interest) * (1 - tax);
8 | years++;
9 | }
10 | return years;
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/src/main/java/kata/kyu7/OnesAndZeros.java:
--------------------------------------------------------------------------------
1 | package kata.kyu7;
2 |
3 | import java.util.List;
4 |
5 | public class OnesAndZeros {
6 | public static int convertBinaryArrayToInt(List binary) {
7 | return binary.get(0) * 8 + binary.get(1) * 4 + binary.get(2) * 2 + binary.get(3) * 1;
8 | }
9 | }
10 |
--------------------------------------------------------------------------------
/src/main/java/kata/kyu7/ShortestWord.java:
--------------------------------------------------------------------------------
1 | package kata.kyu7;
2 |
3 | import java.util.Arrays;
4 | import java.util.Comparator;
5 | import java.util.List;
6 | import java.util.stream.Collectors;
7 |
8 | public class ShortestWord {
9 | public static int findShort(String s) {
10 | List words = Arrays.asList(s.split(" "));
11 | words = words.stream().sorted(Comparator.comparingInt(String::length)).collect(Collectors.toList());
12 | return words.get(0).length();
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/src/main/java/kata/kyu8/Multiply.java:
--------------------------------------------------------------------------------
1 | package kata.kyu8;
2 |
3 | public class Multiply {
4 | public static Double multiply(Double a, Double b) {
5 | return a * b;
6 | }
7 | }
8 |
--------------------------------------------------------------------------------
/src/main/java/kata/kyu8/RemoveStringSpaces.java:
--------------------------------------------------------------------------------
1 | package kata.kyu8;
2 |
3 | public class RemoveStringSpaces {
4 | static String noSpace(final String x) {
5 | return x.replace(" ", "");
6 | }
7 | }
8 |
--------------------------------------------------------------------------------
/src/main/java/utils/MorseCode.java:
--------------------------------------------------------------------------------
1 | package utils;
2 |
3 | import java.util.HashMap;
4 | import java.util.Map;
5 |
6 | public class MorseCode {
7 |
8 | private static final Map map;
9 |
10 | static {
11 | map = new HashMap<>();
12 | map.put(".-", "A");
13 | map.put("-...", "B");
14 | map.put("-.-.", "C");
15 | map.put("-..", "D");
16 | map.put(".", "E");
17 | map.put("..-.", "F");
18 | map.put("--.", "G");
19 | map.put("....", "H");
20 | map.put("..", "I");
21 | map.put(".---", "J");
22 | map.put("-.-", "K");
23 | map.put(".-..", "L");
24 | map.put("--", "M");
25 | map.put("-.", "N");
26 | map.put("---", "O");
27 | map.put(".--.", "P");
28 | map.put("--.-", "Q");
29 | map.put(".-.", "R");
30 | map.put("...", "S");
31 | map.put("-", "T");
32 | map.put("..-", "U");
33 | map.put("...-", "V");
34 | map.put(".--", "W");
35 | map.put("-..-", "X");
36 | map.put("-.--", "Y");
37 | map.put("--..", "Z");
38 | map.put("/", " ");
39 | map.put(".----", "1");
40 | map.put("..---", "2");
41 | map.put("...--", "3");
42 | map.put("....-", "4");
43 | map.put(".....", "5");
44 | map.put("-....", "6");
45 | map.put("--...", "7");
46 | map.put("---..", "8");
47 | map.put("----.", "9");
48 | map.put("-----", "0");
49 | map.put(".-.-.-", ".");
50 | map.put("--..--", ",");
51 | map.put("---...", ":");
52 | map.put("..--..", "?");
53 | map.put(".----.", "\'");
54 | map.put("-....-", "-");
55 | map.put("-..-.", "/");
56 | map.put(".--.-.", "@");
57 | map.put("-...-", "=");
58 | map.put("...---...", "SOS");
59 | map.put("-.-.--", "!");
60 | }
61 |
62 | public static String get(String code) {
63 | return map.get(code);
64 | }
65 | }
66 |
--------------------------------------------------------------------------------
/src/test/java/kata/kyu4/BattleShipsSunkDamagedOrNotTouchedTest.java:
--------------------------------------------------------------------------------
1 | package kata.kyu4;
2 |
3 | import org.junit.Test;
4 |
5 | import java.util.HashMap;
6 | import java.util.Map;
7 |
8 | import static org.junit.Assert.assertEquals;
9 |
10 | public class BattleShipsSunkDamagedOrNotTouchedTest {
11 |
12 | @Test
13 | public void example1() {
14 | int[][] board = new int[][]{new int[]{0, 0, 1, 0},
15 | new int[]{0, 0, 1, 0},
16 | new int[]{0, 0, 1, 0}};
17 | int[][] attacks = new int[][]{new int[]{3, 1}, new int[]{3, 2}, new int[]{3, 3}};
18 |
19 | Map expected = new HashMap();
20 | expected.put("sunk", 1.0);
21 | expected.put("damaged", .0);
22 | expected.put("notTouched", .0);
23 | expected.put("points", 1.0);
24 |
25 | assertEquals(expected, new BattleShipsSunkDamagedOrNotTouched().damagedOrSunk(board, attacks));
26 | }
27 |
28 | @Test
29 | public void example2() {
30 | int[][] board = new int[][]{new int[]{3, 0, 1},
31 | new int[]{3, 0, 1},
32 | new int[]{0, 2, 1},
33 | new int[]{0, 2, 0}};
34 | int[][] attacks = new int[][]{new int[]{2, 1}, new int[]{2, 2}, new int[]{3, 2}, new int[]{3, 3}};
35 |
36 | Map expected = new HashMap();
37 | expected.put("sunk", 1.0);
38 | expected.put("damaged", 1.0);
39 | expected.put("notTouched", 1.0);
40 | expected.put("points", 0.5);
41 |
42 | assertEquals(expected, new BattleShipsSunkDamagedOrNotTouched().damagedOrSunk(board, attacks));
43 | }
44 |
45 | }
--------------------------------------------------------------------------------
/src/test/java/kata/kyu4/CodewarsStyleRankingSystemTest.java:
--------------------------------------------------------------------------------
1 | package kata.kyu4;
2 |
3 | import org.junit.Before;
4 | import org.junit.Test;
5 |
6 | import static org.junit.Assert.assertEquals;
7 |
8 | public class CodewarsStyleRankingSystemTest {
9 | CodewarsStyleRankingSystem.User user;
10 |
11 | @Before
12 | public void setup() {
13 | user = new CodewarsStyleRankingSystem.User();
14 | }
15 |
16 | @Test
17 | public void classTest() {
18 | CodewarsStyleRankingSystem codewarsStyleRankingSystem = new CodewarsStyleRankingSystem();
19 | }
20 |
21 | @Test(expected = IllegalArgumentException.class)
22 | public void invalidRangeNeg9() {
23 | new CodewarsStyleRankingSystem.User().incProgress(-9);
24 | }
25 |
26 | @Test(expected = IllegalArgumentException.class)
27 | public void invalidRange0() {
28 | new CodewarsStyleRankingSystem.User().incProgress(0);
29 | }
30 |
31 | @Test(expected = IllegalArgumentException.class)
32 | public void invalidRange9() {
33 | new CodewarsStyleRankingSystem.User().incProgress(9);
34 | }
35 |
36 | @Test
37 | public void progressAdd3() {
38 | user.incProgress(-8);
39 | assertEquals(3, user.progress);
40 | }
41 |
42 | @Test
43 | public void progressAdd1() {
44 | user.rank = 1;
45 | user.incProgress(-1);
46 | assertEquals(1, user.progress);
47 | }
48 |
49 | @Test
50 | public void progressAdd0() {
51 | user.rank = 1;
52 | user.incProgress(-2);
53 | assertEquals(0, user.progress);
54 | }
55 |
56 | @Test
57 | public void progressAdd10() {
58 | user.rank = -1;
59 | user.incProgress(1);
60 | assertEquals(10, user.progress);
61 | }
62 |
63 | @Test
64 | public void progressAdd40() {
65 | user.incProgress(-6);
66 | assertEquals(40, user.progress);
67 | }
68 |
69 | @Test
70 | public void progressAdd90() {
71 | user.rank = 1;
72 | user.incProgress(4);
73 | assertEquals(90, user.progress);
74 | }
75 |
76 | @Test
77 | public void progressAdd90AndRankUp() {
78 | user.incProgress(-4);
79 | assertEquals(60, user.progress);
80 | assertEquals(-7, user.rank);
81 | }
82 |
83 | @Test
84 | public void rankMinus1ToPlus1() {
85 | user.rank = -1;
86 | user.progress = 99;
87 | user.incProgress(1);
88 | assertEquals(1, user.rank);
89 | }
90 |
91 | @Test
92 | public void rank7progress0() {
93 | user.progress = 90;
94 | user.rank = 6;
95 | user.incProgress(7);
96 | assertEquals(0, user.progress);
97 | assertEquals(7, user.rank);
98 | }
99 |
100 | @Test
101 | public void rank8max() {
102 | user.rank = 8;
103 | user.progress = 110;
104 | user.incProgress(8);
105 | assertEquals(0, user.progress);
106 | assertEquals(8, user.rank);
107 | }
108 |
109 | @Test
110 | public void rank8min() {
111 | user.rank = 8;
112 | user.progress = 0;
113 | user.incProgress(8);
114 | assertEquals(0, user.progress);
115 | assertEquals(8, user.rank);
116 | }
117 | }
--------------------------------------------------------------------------------
/src/test/java/kata/kyu4/DecodeTheMorseCodeAdvancedTest.java:
--------------------------------------------------------------------------------
1 | package kata.kyu4;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.assertEquals;
6 |
7 | public class DecodeTheMorseCodeAdvancedTest {
8 |
9 | @Test
10 | public void testExampleFromDescription() {
11 | assertEquals("HEY JUDE", DecodeTheMorseCodeAdvanced.decodeMorse(DecodeTheMorseCodeAdvanced.decodeBits("1100110011001100000011000000111111001100111111001111110000000000000011001111110011111100111111000000110011001111110000001111110011001100000011")));
12 | assertEquals("E", DecodeTheMorseCodeAdvanced.decodeMorse(DecodeTheMorseCodeAdvanced.decodeBits("01110")));
13 | assertEquals("E", DecodeTheMorseCodeAdvanced.decodeMorse(DecodeTheMorseCodeAdvanced.decodeBits("1")));
14 | assertEquals("E", DecodeTheMorseCodeAdvanced.decodeMorse(DecodeTheMorseCodeAdvanced.decodeBits("111")));
15 | assertEquals("THE QUICK BROWN FOX JUMPS OVER THE LAZY DOG.", DecodeTheMorseCodeAdvanced.decodeMorse(DecodeTheMorseCodeAdvanced.decodeBits("00011100010101010001000000011101110101110001010111000101000111010111010001110101110000000111010101000101110100011101110111000101110111000111010000000101011101000111011101110001110101011100000001011101110111000101011100011101110001011101110100010101000000011101110111000101010111000100010111010000000111000101010100010000000101110101000101110001110111010100011101011101110000000111010100011101110111000111011101000101110101110101110")));
16 | }
17 |
18 | }
--------------------------------------------------------------------------------
/src/test/java/kata/kyu4/HumanReadableDurationFormatTest.java:
--------------------------------------------------------------------------------
1 | package kata.kyu4;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.assertEquals;
6 |
7 | public class HumanReadableDurationFormatTest {
8 | @Test
9 | public void testFormatDurationExamples() {
10 | assertEquals("1 second", new HumanReadableDurationFormat().formatDuration(1));
11 | assertEquals("1 minute and 2 seconds", new HumanReadableDurationFormat().formatDuration(62));
12 | assertEquals("2 minutes", new HumanReadableDurationFormat().formatDuration(120));
13 | assertEquals("1 hour", new HumanReadableDurationFormat().formatDuration(3600));
14 | assertEquals("1 hour, 1 minute and 2 seconds", new HumanReadableDurationFormat().formatDuration(3662));
15 | assertEquals("23 hours, 59 minutes and 2 seconds", new HumanReadableDurationFormat().formatDuration(86342));
16 | assertEquals("1 year, 11 days, 12 hours, 41 minutes and 34 seconds", new HumanReadableDurationFormat().formatDuration(32532094));
17 | assertEquals("2 years, 16 days, 1 hour, 31 minutes and 33 seconds", new HumanReadableDurationFormat().formatDuration(64459893));
18 | assertEquals("now", new HumanReadableDurationFormat().formatDuration(0));
19 | }
20 |
21 | }
--------------------------------------------------------------------------------
/src/test/java/kata/kyu4/LongestCommonSubsequencePerformanceVersionTest.java:
--------------------------------------------------------------------------------
1 | package kata.kyu4;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.assertEquals;
6 |
7 | public class LongestCommonSubsequencePerformanceVersionTest {
8 | @Test
9 | public void fixedTests() {
10 | assertEquals("", new LongestCommonSubsequencePerformanceVersion().lcs("", ""));
11 | assertEquals("", new LongestCommonSubsequencePerformanceVersion().lcs("abc", ""));
12 | assertEquals("", new LongestCommonSubsequencePerformanceVersion().lcs("", "abc"));
13 | assertEquals("", new LongestCommonSubsequencePerformanceVersion().lcs("a", "b"));
14 | assertEquals("a", new LongestCommonSubsequencePerformanceVersion().lcs("a", "a"));
15 | assertEquals("ac", new LongestCommonSubsequencePerformanceVersion().lcs("abc", "ac"));
16 | assertEquals("abc", new LongestCommonSubsequencePerformanceVersion().lcs("abcdef", "abc"));
17 | assertEquals("acf", new LongestCommonSubsequencePerformanceVersion().lcs("abcdef", "acf"));
18 | assertEquals("nottest", new LongestCommonSubsequencePerformanceVersion().lcs("anothertest", "notatest"));
19 | assertEquals("12356", new LongestCommonSubsequencePerformanceVersion().lcs("132535365", "123456789"));
20 | assertEquals("final", new LongestCommonSubsequencePerformanceVersion().lcs("nothardlythefinaltest", "zzzfinallyzzz"));
21 | assertEquals("acdefghijklmnoq", new LongestCommonSubsequencePerformanceVersion().lcs("abcdefghijklmnopq", "apcdefghijklmnobq"));
22 | }
23 |
24 | }
--------------------------------------------------------------------------------
/src/test/java/kata/kyu4/NumberOfProperFractionsWithDenominatorDTest.java:
--------------------------------------------------------------------------------
1 | package kata.kyu4;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.assertEquals;
6 |
7 | public class NumberOfProperFractionsWithDenominatorDTest {
8 | @Test
9 | public void Smaller_Numbers() {
10 | assertEquals(0, new NumberOfProperFractionsWithDenominatorD().properFractions(1));
11 | assertEquals(1, new NumberOfProperFractionsWithDenominatorD().properFractions(2));
12 | assertEquals(4, new NumberOfProperFractionsWithDenominatorD().properFractions(5));
13 | assertEquals(8, new NumberOfProperFractionsWithDenominatorD().properFractions(15));
14 | assertEquals(20, new NumberOfProperFractionsWithDenominatorD().properFractions(25));
15 | }
16 |
17 | @Test
18 | public void Larger_Numbers() {
19 | assertEquals(6637344, new NumberOfProperFractionsWithDenominatorD().properFractions(9999999));
20 | assertEquals(58752000, new NumberOfProperFractionsWithDenominatorD().properFractions(99999999));
21 | assertEquals(648646704, new NumberOfProperFractionsWithDenominatorD().properFractions(999999999));
22 | }
23 | }
--------------------------------------------------------------------------------
/src/test/java/kata/kyu4/RecoverASecretStringFromRandomTripletsTest.java:
--------------------------------------------------------------------------------
1 | package kata.kyu4;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.assertEquals;
6 |
7 | public class RecoverASecretStringFromRandomTripletsTest {
8 |
9 | @Test
10 | public void secret1() {
11 | char[][] triplets = {
12 | {'t', 'u', 'p'},
13 | {'w', 'h', 'i'},
14 | {'t', 's', 'u'},
15 | {'a', 't', 's'},
16 | {'h', 'a', 'p'},
17 | {'t', 'i', 's'},
18 | {'w', 'h', 's'}
19 | };
20 | assertEquals("whatisup", new RecoverASecretStringFromRandomTriplets().recoverSecret(triplets));
21 | }
22 |
23 | @Test
24 | public void secret2() {
25 | char[][] triplets = {
26 | {'t', 's', 'f'},
27 | {'a', 's', 'u'},
28 | {'m', 'a', 'f'},
29 | {'a', 'i', 'n'},
30 | {'s', 'u', 'n'},
31 | {'m', 'f', 'u'},
32 | {'a', 't', 'h'},
33 | {'t', 'h', 'i'},
34 | {'h', 'i', 'f'},
35 | {'m', 'h', 'f'},
36 | {'a', 'u', 'n'},
37 | {'m', 'a', 't'},
38 | {'f', 'u', 'n'},
39 | {'h', 's', 'n'},
40 | {'a', 'i', 's'},
41 | {'m', 's', 'n'},
42 | {'m', 's', 'u'}
43 | };
44 | assertEquals("mathisfun", new RecoverASecretStringFromRandomTriplets().recoverSecret(triplets));
45 | }
46 |
47 | @Test
48 | public void secret3() {
49 | char[][] triplets = {
50 | {'g', 'a', 's'},
51 | {'o', 'g', 's'},
52 | {'c', 'n', 't'},
53 | {'c', 'o', 'n'},
54 | {'a', 't', 's'},
55 | {'g', 'r', 't'},
56 | {'r', 't', 's'},
57 | {'c', 'r', 'a'},
58 | {'g', 'a', 't'},
59 | {'n', 'g', 's'},
60 | {'o', 'a', 's'}
61 | };
62 | assertEquals("congrats", new RecoverASecretStringFromRandomTriplets().recoverSecret(triplets));
63 | }
64 |
65 | @Test
66 | public void secret4() {
67 | char[][] triplets = {
68 | {'l', 'e', 'd'},
69 | {'o', 'e', 'd'},
70 | {'o', 'l', 'e'},
71 | {'o', 'v', 'e'},
72 | {'s', 'o', 'l'},
73 | {'s', 'e', 'd'},
74 | {'s', 'l', 'e'},
75 | {'v', 'e', 'd'},
76 | {'o', 'l', 'v'},
77 | {'l', 'v', 'd'}
78 | };
79 | assertEquals("solved", new RecoverASecretStringFromRandomTriplets().recoverSecret(triplets));
80 | }
81 |
82 | @Test
83 | public void secret5() {
84 | char[][] triplets = {
85 | {'o', 'x', 'y'},
86 | {'h', 'r', 'u'},
87 | {'b', 'x', 'z'},
88 | {'r', 'y', 'z'},
89 | {'v', 'y', 'z'},
90 | {'v', 'w', 'y'},
91 | {'o', 's', 'y'},
92 | {'i', 'u', 'z'},
93 | {'q', 'y', 'z'},
94 | {'k', 'p', 'v'},
95 | {'w', 'x', 'z'},
96 | {'k', 'x', 'y'},
97 | {'r', 'w', 'x'},
98 | {'a', 'n', 'w'},
99 | {'b', 'd', 't'},
100 | {'p', 'u', 'y'},
101 | {'n', 'v', 'z'},
102 | {'f', 'k', 'q'},
103 | {'i', 'm', 'z'},
104 | {'a', 'w', 'y'},
105 | {'b', 'k', 'n'},
106 | {'t', 'u', 'w'},
107 | {'x', 'y', 'z'},
108 | {'f', 'g', 'j'},
109 | {'n', 'y', 'z'},
110 | {'s', 'y', 'z'},
111 | {'k', 'w', 'x'},
112 | {'m', 's', 'u'},
113 | {'h', 'i', 's'},
114 | {'q', 'w', 'z'},
115 | {'w', 'y', 'z'},
116 | {'j', 'o', 'p'},
117 | {'r', 'v', 'y'},
118 | {'h', 'p', 'w'},
119 | {'s', 't', 'z'},
120 | {'j', 'k', 'r'},
121 | {'n', 'u', 'w'},
122 | {'h', 'v', 'w'},
123 | {'t', 'u', 'y'},
124 | {'l', 'q', 'y'},
125 | {'v', 'w', 'x'},
126 | {'r', 'w', 'z'},
127 | {'m', 'o', 'w'},
128 | {'k', 'q', 'x'},
129 | {'e', 'h', 'r'},
130 | {'e', 'k', 'l'},
131 | {'d', 'h', 'p'},
132 | {'r', 'u', 'w'},
133 | {'e', 'g', 'n'},
134 | {'m', 'o', 'y'},
135 | {'q', 'r', 's'},
136 | {'d', 'i', 'q'},
137 | {'u', 'w', 'z'},
138 | {'u', 'w', 'x'},
139 | {'u', 'x', 'z'},
140 | {'e', 'l', 'x'},
141 | {'p', 't', 'v'},
142 | {'k', 't', 'w'},
143 | {'v', 'x', 'y'},
144 | {'f', 'y', 'z'},
145 | {'v', 'w', 'z'},
146 | {'d', 'f', 'h'},
147 | {'h', 't', 'x'},
148 | {'c', 'w', 'x'},
149 | {'v', 'x', 'z'},
150 | {'f', 'p', 'x'},
151 | {'g', 'x', 'y'},
152 | {'g', 'v', 'w'},
153 | {'f', 'l', 's'},
154 | {'c', 'f', 'v'},
155 | {'g', 'q', 's'},
156 | {'d', 't', 'y'},
157 | {'j', 'p', 't'},
158 | {'d', 'k', 's'},
159 | {'s', 'w', 'x'},
160 | {'d', 'q', 'x'},
161 | {'o', 'r', 's'},
162 | {'l', 'v', 'y'},
163 | {'r', 't', 'y'},
164 | {'i', 'y', 'z'},
165 | {'g', 'r', 'w'},
166 | {'g', 'h', 'l'},
167 | {'c', 'x', 'z'},
168 | {'g', 't', 'v'},
169 | {'f', 'g', 'n'},
170 | {'l', 'r', 't'},
171 | {'r', 'u', 'x'},
172 | {'u', 'x', 'y'},
173 | {'s', 'x', 'y'},
174 | {'b', 'u', 'z'},
175 | {'l', 'w', 'y'},
176 | {'a', 'n', 'v'},
177 | {'k', 'l', 'z'},
178 | {'n', 'q', 'w'},
179 | {'m', 'u', 'z'},
180 | {'k', 'u', 'y'},
181 | {'t', 'v', 'z'},
182 | {'o', 'w', 'z'},
183 | {'c', 'h', 'y'},
184 | {'h', 's', 'y'},
185 | {'l', 'r', 'z'},
186 | {'a', 's', 'z'},
187 | {'f', 'r', 'v'},
188 | {'d', 'q', 'v'},
189 | {'u', 'v', 'y'},
190 | {'t', 'x', 'y'},
191 | {'b', 'w', 'y'},
192 | {'j', 'q', 'u'},
193 | {'o', 't', 'y'},
194 | {'p', 'y', 'z'},
195 | {'l', 'y', 'z'},
196 | {'n', 's', 'u'},
197 | {'m', 's', 'x'},
198 | {'b', 's', 'y'},
199 | {'l', 's', 'z'},
200 | {'d', 'm', 'u'},
201 | {'i', 'o', 'w'},
202 | {'c', 'v', 'w'},
203 | {'t', 'y', 'z'},
204 | {'l', 'n', 'y'},
205 | {'m', 'x', 'y'},
206 | {'n', 'v', 'x'},
207 | {'n', 'u', 'z'},
208 | {'g', 'h', 's'},
209 | {'r', 'v', 'w'},
210 | {'j', 'u', 'x'},
211 | {'m', 'v', 'z'},
212 | {'d', 'r', 'z'},
213 | {'o', 'v', 'x'},
214 | {'f', 'n', 'q'},
215 | {'a', 'b', 't'},
216 | {'h', 'v', 'x'},
217 | {'e', 'u', 'x'},
218 | {'o', 'w', 'y'},
219 | {'d', 'i', 'm'},
220 | {'a', 'f', 'w'},
221 | {'f', 'n', 'r'},
222 | {'d', 'm', 'x'},
223 | {'p', 'r', 'z'},
224 | {'p', 'u', 'v'},
225 | {'e', 'y', 'z'},
226 | {'c', 'o', 'x'},
227 | {'c', 'x', 'y'},
228 | {'a', 'i', 'w'},
229 | {'q', 'x', 'y'},
230 | {'c', 'i', 'n'},
231 | {'u', 'v', 'z'},
232 | {'u', 'w', 'y'},
233 | {'f', 'r', 'x'},
234 | {'t', 'w', 'z'},
235 | {'e', 'r', 'v'},
236 | {'o', 'q', 't'},
237 | {'m', 'w', 'x'},
238 | {'g', 'v', 'x'},
239 | {'c', 'j', 'k'},
240 | {'i', 's', 'y'},
241 | {'g', 's', 'u'},
242 | {'i', 'j', 's'},
243 | {'d', 'm', 'n'},
244 | {'l', 'n', 'v'},
245 | {'e', 's', 'w'},
246 | {'o', 'u', 'w'},
247 | {'b', 's', 'z'},
248 | {'a', 'd', 'g'},
249 | {'l', 'w', 'x'},
250 | {'m', 'r', 'x'},
251 | {'j', 'k', 'l'},
252 | {'f', 'p', 's'},
253 | {'p', 'r', 'v'},
254 | {'g', 'x', 'z'},
255 | {'o', 'u', 'z'},
256 | {'h', 'k', 's'},
257 | {'i', 'r', 'w'},
258 | {'n', 'q', 'y'},
259 | {'o', 'q', 'r'},
260 | {'f', 'q', 'y'},
261 | {'e', 'j', 'z'},
262 | {'e', 'o', 'u'},
263 | {'j', 'k', 'z'},
264 | {'b', 'g', 't'},
265 | {'f', 'v', 'w'},
266 | {'w', 'x', 'y'},
267 | {'t', 'v', 'w'},
268 | {'a', 'p', 'w'},
269 | {'c', 'l', 'x'},
270 | {'q', 's', 'y'},
271 | {'k', 'n', 'q'},
272 | {'d', 'y', 'z'},
273 | {'i', 'p', 'v'},
274 | {'e', 'k', 'y'},
275 | {'e', 'w', 'z'},
276 | {'i', 'm', 'v'},
277 | {'j', 's', 'v'},
278 | {'l', 'o', 'u'},
279 | {'e', 'o', 'q'},
280 | {'a', 'i', 's'},
281 | {'e', 'm', 'y'},
282 | {'b', 'y', 'z'},
283 | {'c', 'k', 'u'},
284 | {'a', 'k', 'p'},
285 | {'p', 'x', 'y'},
286 | {'h', 'p', 'q'},
287 | {'p', 't', 'w'},
288 | {'e', 'x', 'z'},
289 | {'l', 'p', 'y'},
290 | {'m', 'y', 'z'},
291 | {'l', 't', 'v'},
292 | {'d', 'g', 'n'},
293 | {'h', 'o', 't'},
294 | {'c', 't', 'x'},
295 | {'a', 'o', 'v'},
296 | {'m', 'v', 'x'},
297 | {'k', 'o', 'q'},
298 | {'i', 'v', 'y'},
299 | {'b', 'm', 's'},
300 | {'h', 'q', 'w'},
301 | {'f', 'h', 'x'},
302 | {'i', 'v', 'z'},
303 | {'f', 't', 'w'},
304 | {'l', 'v', 'z'},
305 | {'f', 'g', 'w'},
306 | {'s', 'w', 'z'},
307 | {'j', 'k', 'o'},
308 | {'d', 'j', 'm'},
309 | {'r', 't', 'u'},
310 | {'k', 'm', 'z'},
311 | {'q', 'w', 'y'},
312 | {'q', 'u', 'v'},
313 | {'g', 's', 'x'},
314 | {'p', 's', 't'},
315 | {'i', 'm', 't'},
316 | {'c', 'g', 'y'},
317 | {'n', 'w', 'z'},
318 | {'o', 'r', 'z'},
319 | {'h', 'i', 'm'},
320 | {'n', 't', 'w'},
321 | {'s', 'u', 'y'},
322 | {'s', 'x', 'z'},
323 | {'h', 'x', 'z'},
324 | {'e', 'f', 'x'},
325 | {'a', 'k', 'n'},
326 | {'h', 's', 'z'},
327 | {'j', 'o', 'w'},
328 | {'o', 't', 'x'},
329 | {'l', 'n', 'r'},
330 | {'m', 'x', 'z'},
331 | {'r', 'x', 'y'},
332 | {'b', 'w', 'z'},
333 | {'c', 'j', 'q'},
334 | {'b', 'f', 'o'},
335 | {'o', 'x', 'z'},
336 | {'i', 'j', 'r'},
337 | {'p', 'q', 'y'},
338 | {'j', 'p', 's'},
339 | {'m', 'r', 'w'},
340 | {'a', 'e', 'y'},
341 | {'u', 'y', 'z'},
342 | {'j', 'l', 'u'},
343 | {'j', 's', 'y'},
344 | {'k', 'x', 'z'},
345 | {'p', 'v', 'y'},
346 | {'j', 'l', 'p'},
347 | {'p', 'v', 'z'},
348 | {'f', 'h', 't'},
349 | {'k', 'n', 'x'},
350 | {'f', 'n', 'o'},
351 | {'p', 'v', 'w'},
352 | {'k', 'v', 'y'},
353 | {'j', 'w', 'y'},
354 | {'e', 'n', 's'},
355 | {'f', 'j', 'p'},
356 | {'f', 'u', 'w'},
357 | {'g', 'm', 'z'},
358 | {'n', 's', 'y'},
359 | {'m', 's', 'z'},
360 | {'c', 'd', 'x'},
361 | {'l', 'x', 'y'},
362 | {'g', 'y', 'z'},
363 | {'b', 't', 'w'},
364 | {'n', 'q', 'z'},
365 | {'r', 'w', 'y'},
366 | {'r', 't', 'w'},
367 | {'l', 't', 'x'},
368 | {'m', 'w', 'y'},
369 | {'h', 'm', 't'},
370 | {'k', 'n', 'v'},
371 | {'a', 'j', 'y'},
372 | {'f', 'q', 'w'},
373 | {'s', 'u', 'w'},
374 | {'p', 't', 'z'},
375 | {'j', 'l', 'r'},
376 | {'m', 'n', 'w'},
377 | {'n', 't', 'v'},
378 | {'n', 'p', 'r'},
379 | {'l', 'u', 'w'},
380 | {'g', 'j', 'o'},
381 | {'b', 'j', 'v'},
382 | {'m', 'o', 't'},
383 | {'k', 'w', 'z'},
384 | {'f', 'i', 'n'},
385 | {'i', 'u', 'y'},
386 | {'p', 'v', 'x'},
387 | {'k', 'l', 'u'},
388 | {'b', 'c', 'f'},
389 | {'f', 'q', 'v'},
390 | {'c', 'h', 'u'},
391 | {'i', 'n', 'w'},
392 | {'q', 's', 't'},
393 | {'k', 'q', 'w'},
394 | {'o', 'q', 's'},
395 | {'o', 'r', 'v'},
396 | {'m', 't', 'u'},
397 | {'n', 'u', 'y'},
398 | {'c', 's', 'z'},
399 | {'o', 'q', 'x'},
400 | {'r', 't', 'z'},
401 | {'a', 'g', 'q'},
402 | {'g', 's', 'z'},
403 | {'i', 'w', 'y'},
404 | {'j', 'l', 'y'},
405 | {'e', 'v', 'x'},
406 | {'e', 'n', 't'},
407 | {'f', 'g', 'v'},
408 | {'a', 'j', 'n'},
409 | {'d', 'h', 'r'},
410 | {'a', 'p', 'u'},
411 | {'l', 's', 'v'},
412 | {'l', 'q', 'z'},
413 | {'k', 'y', 'z'},
414 | {'r', 's', 'y'},
415 | {'n', 'x', 'y'},
416 | {'o', 'u', 'x'},
417 | {'n', 'q', 't'},
418 | {'c', 'f', 'h'},
419 | {'q', 's', 'x'},
420 | {'a', 'l', 'p'},
421 | {'l', 's', 'u'},
422 | {'e', 'r', 'y'},
423 | {'k', 'v', 'x'},
424 | {'j', 'o', 's'},
425 | {'o', 'p', 'q'},
426 | {'m', 'v', 'w'},
427 | {'o', 'q', 'v'},
428 | {'a', 'w', 'z'},
429 | {'l', 'u', 'x'},
430 | {'g', 's', 'v'},
431 | {'p', 'q', 'v'},
432 | {'b', 'o', 's'},
433 | {'o', 's', 'v'},
434 | {'f', 'h', 'y'},
435 | {'k', 's', 'w'},
436 | {'h', 't', 'u'},
437 | {'t', 'v', 'x'},
438 | {'q', 'v', 'w'},
439 | {'j', 'p', 'v'},
440 | {'c', 'l', 'u'},
441 | {'m', 's', 'w'},
442 | {'e', 'j', 'p'},
443 | {'e', 'f', 'h'},
444 | {'a', 's', 't'},
445 | {'i', 'k', 't'},
446 | {'j', 'l', 'm'},
447 | {'d', 'e', 'x'},
448 | {'j', 'x', 'y'},
449 | {'a', 'k', 'v'},
450 | {'j', 'q', 'v'},
451 | {'s', 'v', 'y'},
452 | {'d', 'k', 'q'},
453 | {'g', 'o', 's'},
454 | {'a', 'u', 'y'},
455 | {'h', 'u', 'x'},
456 | {'e', 'q', 's'},
457 | {'a', 'f', 'v'},
458 | {'i', 'r', 'x'},
459 | {'o', 'y', 'z'},
460 | {'h', 'v', 'z'},
461 | {'i', 'u', 'v'},
462 | {'h', 'p', 'x'},
463 | {'i', 't', 'z'},
464 | {'f', 'o', 'q'},
465 | {'a', 'x', 'y'},
466 | {'t', 'w', 'x'},
467 | {'c', 'u', 'w'},
468 | {'b', 'g', 'u'},
469 | {'q', 'v', 'y'},
470 | {'r', 'x', 'z'},
471 | {'s', 'u', 'x'},
472 | {'s', 'v', 'z'},
473 | {'e', 'h', 'l'},
474 | {'e', 'w', 'y'},
475 | {'j', 's', 'x'},
476 | {'q', 'w', 'x'},
477 | {'q', 'x', 'z'},
478 | {'f', 'l', 'n'},
479 | {'d', 'n', 'y'},
480 | {'j', 'r', 'u'},
481 | {'u', 'v', 'w'},
482 | {'t', 'x', 'z'},
483 | {'m', 'o', 'z'},
484 | {'f', 'm', 'q'},
485 | {'k', 'l', 'y'},
486 | {'f', 's', 'x'},
487 | {'m', 'w', 'z'},
488 | {'g', 'w', 'x'},
489 | {'m', 'u', 'y'},
490 | {'n', 'q', 'u'},
491 | {'l', 't', 'w'},
492 | {'r', 'u', 'z'},
493 | {'o', 's', 'w'},
494 | {'d', 's', 'y'},
495 | {'u', 'v', 'x'},
496 | {'h', 'y', 'z'},
497 | {'g', 'm', 'u'},
498 | {'a', 'c', 'l'},
499 | {'d', 'e', 'k'},
500 | {'p', 'q', 's'},
501 | {'g', 'j', 'l'},
502 | {'c', 'e', 'g'},
503 | {'b', 'l', 'v'},
504 | {'o', 'q', 'z'},
505 | {'p', 'q', 'u'},
506 | {'m', 'u', 'w'},
507 | {'j', 'n', 'y'},
508 | {'c', 'q', 'v'},
509 | {'p', 'u', 'w'},
510 | {'i', 'o', 'y'},
511 | {'f', 'm', 'x'},
512 | {'j', 't', 'x'},
513 | {'h', 'm', 'x'},
514 | {'c', 's', 'x'},
515 | {'i', 'q', 'v'},
516 | {'s', 'v', 'w'},
517 | {'i', 'w', 'x'},
518 | {'m', 'p', 't'},
519 | {'o', 'v', 'y'},
520 | {'p', 't', 'u'},
521 | {'e', 'w', 'x'},
522 | {'n', 'r', 's'},
523 | {'e', 'l', 'z'},
524 | {'s', 'u', 'z'},
525 | {'g', 'm', 't'},
526 | {'h', 'u', 'v'},
527 | {'r', 't', 'x'},
528 | {'l', 's', 'x'},
529 | {'o', 'p', 'v'},
530 | {'n', 'v', 'w'},
531 | {'p', 's', 'u'},
532 | {'e', 's', 'u'},
533 | {'j', 'y', 'z'},
534 | {'f', 'n', 'u'},
535 | {'h', 's', 'v'},
536 | {'f', 'm', 'n'},
537 | {'i', 'q', 'x'},
538 | {'d', 'j', 'l'},
539 | {'k', 't', 'v'},
540 | {'o', 'p', 'w'},
541 | {'e', 'k', 'm'},
542 | {'j', 'n', 'v'},
543 | {'h', 'j', 'p'},
544 | {'p', 'x', 'z'},
545 | {'c', 'g', 't'},
546 | {'i', 'n', 'r'},
547 | {'h', 'o', 'p'},
548 | {'c', 'h', 'v'},
549 | {'l', 'p', 'z'},
550 | {'q', 'v', 'z'},
551 | {'e', 't', 'w'},
552 | {'b', 't', 'x'},
553 | {'d', 'v', 'x'},
554 | {'l', 'r', 'u'},
555 | {'f', 'k', 'y'},
556 | {'f', 'x', 'y'},
557 | {'h', 'm', 'n'},
558 | {'s', 'v', 'x'}
559 | };
560 | assertEquals("abcdefghijklmnopqrstuvwxyz", new RecoverASecretStringFromRandomTriplets().recoverSecret(triplets));
561 | }
562 | }
--------------------------------------------------------------------------------
/src/test/java/kata/kyu4/ReversePolishNotationCalculatorTest.java:
--------------------------------------------------------------------------------
1 | package kata.kyu4;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.assertEquals;
6 |
7 | public class ReversePolishNotationCalculatorTest {
8 |
9 | @Test
10 | public void shouldWorkWithEmptyString() {
11 | assertEquals("Should work with empty string", 0, new ReversePolishNotationCalculator().evaluate(""), 0);
12 | }
13 |
14 | @Test
15 | public void shouldParseNumbers() {
16 | assertEquals("Should parse numbers", 3, new ReversePolishNotationCalculator().evaluate("1 2 3"), 0);
17 | }
18 |
19 | @Test
20 | public void shouldParseFloatNumbers() {
21 | assertEquals("Should parse float numbers", 3.5, new ReversePolishNotationCalculator().evaluate("1 2 3.5"), 0);
22 | }
23 |
24 | @Test
25 | public void shouldSupportAddition() {
26 | assertEquals("Should support addition", 4, new ReversePolishNotationCalculator().evaluate("1 3 +"), 0);
27 | }
28 |
29 | @Test
30 | public void shouldSupportMultiplication() {
31 | assertEquals("Should support multiplication", 3, new ReversePolishNotationCalculator().evaluate("1 3 *"), 0);
32 | }
33 |
34 | @Test
35 | public void shouldSupportSubstraction() {
36 | assertEquals("Should support substraction", -2, new ReversePolishNotationCalculator().evaluate("1 3 -"), 0);
37 | }
38 |
39 | @Test
40 | public void shouldSupportDivision() {
41 | assertEquals("Should support division", 2, new ReversePolishNotationCalculator().evaluate("4 2 /"), 0);
42 | }
43 |
44 | }
--------------------------------------------------------------------------------
/src/test/java/kata/kyu4/RomanNumeralsEncoderTest.java:
--------------------------------------------------------------------------------
1 | package kata.kyu4;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.assertEquals;
6 |
7 | public class RomanNumeralsEncoderTest {
8 | @Test
9 | public void shouldCovertToRoman() {
10 | assertEquals("solution(1) should equal to I", "I", new RomanNumeralsEncoder().solution(1));
11 | assertEquals("solution(4) should equal to IV", "IV", new RomanNumeralsEncoder().solution(4));
12 | assertEquals("solution(6) should equal to VI", "VI", new RomanNumeralsEncoder().solution(6));
13 | }
14 |
15 | }
--------------------------------------------------------------------------------
/src/test/java/kata/kyu4/SquareIntoSquaresProtectTreesTest.java:
--------------------------------------------------------------------------------
1 | package kata.kyu4;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.assertEquals;
6 |
7 | public class SquareIntoSquaresProtectTreesTest {
8 | @Test
9 | public void test1() {
10 | SquareIntoSquaresProtectTrees d = new SquareIntoSquaresProtectTrees();
11 | long n = 2;
12 | assertEquals(null, d.decompose(n));
13 | }
14 |
15 | @Test
16 | public void test2() {
17 | SquareIntoSquaresProtectTrees d = new SquareIntoSquaresProtectTrees();
18 | long n = 11;
19 | assertEquals("1 2 4 10", d.decompose(n));
20 | }
21 |
22 | @Test
23 | public void test3() {
24 | SquareIntoSquaresProtectTrees d = new SquareIntoSquaresProtectTrees();
25 | long n = 12;
26 | assertEquals("1 2 3 7 9", d.decompose(n));
27 | }
28 |
29 | @Test
30 | public void test4() {
31 | SquareIntoSquaresProtectTrees d = new SquareIntoSquaresProtectTrees();
32 | long n = 12551;
33 | assertEquals("4 11 158 12550", d.decompose(n));
34 | }
35 |
36 | @Test
37 | public void test5() {
38 | SquareIntoSquaresProtectTrees d = new SquareIntoSquaresProtectTrees();
39 | long n = 13365;
40 | assertEquals("4 12 163 13364", d.decompose(n));
41 | }
42 |
43 | @Test
44 | public void test6() {
45 | SquareIntoSquaresProtectTrees d = new SquareIntoSquaresProtectTrees();
46 | long n = 13705;
47 | assertEquals("2 6 12 165 13704", d.decompose(n));
48 | }
49 | }
--------------------------------------------------------------------------------
/src/test/java/kata/kyu4/SumByFactorsTest.java:
--------------------------------------------------------------------------------
1 | package kata.kyu4;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.assertEquals;
6 |
7 | public class SumByFactorsTest {
8 | @Test
9 | public void testOne() {
10 | int[] lst = new int[]{12, 15};
11 | assertEquals("(2 12)(3 27)(5 15)", new SumByFactors().sumOfDivided(lst));
12 | }
13 |
14 | @Test
15 | public void testTwo() {
16 | int[] lst = new int[]{15, 21, 24, 30, 45};
17 | assertEquals("(2 54)(3 135)(5 90)(7 21)", new SumByFactors().sumOfDivided(lst));
18 | }
19 |
20 | @Test
21 | public void testThree() {
22 | int[] lst = new int[]{107, 158, 204, 100, 118, 123, 126, 110, 116, 100};
23 | assertEquals("(2 1032)(3 453)(5 310)(7 126)(11 110)(17 204)(29 116)(41 123)(59 118)(79 158)(107 107)", new SumByFactors().sumOfDivided(lst));
24 | }
25 | }
--------------------------------------------------------------------------------
/src/test/java/kata/kyu4/TenPinBowlingTest.java:
--------------------------------------------------------------------------------
1 | package kata.kyu4;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.assertEquals;
6 |
7 | public class TenPinBowlingTest {
8 | @Test
9 | public void BasicTests() {
10 | assertEquals(20, new TenPinBowling().bowlingScore("11 11 11 11 11 11 11 11 11 11"));
11 | assertEquals(300, new TenPinBowling().bowlingScore("X X X X X X X X X XXX"));
12 | assertEquals(118, new TenPinBowling().bowlingScore("5/ 17 8/ 8/ 6/ 23 00 9/ 16 XXX"));
13 | }
14 |
15 | }
--------------------------------------------------------------------------------
/src/test/java/kata/kyu5/ConvertStringToCamelCaseTest.java:
--------------------------------------------------------------------------------
1 | package kata.kyu5;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.assertEquals;
6 |
7 | public class ConvertStringToCamelCaseTest {
8 | @Test
9 | public void testSomeUnderscoreLowerStart() {
10 | String input = "the_Stealth_Warrior";
11 | assertEquals("theStealthWarrior", new ConvertStringToCamelCase().toCamelCase(input));
12 | }
13 |
14 | @Test
15 | public void testSomeDashLowerStart() {
16 | String input = "the-Stealth-Warrior";
17 | assertEquals("theStealthWarrior", new ConvertStringToCamelCase().toCamelCase(input));
18 | }
19 |
20 | @Test
21 | public void testLongOne() {
22 | String input = "You_have_chosen_to_translate_this_kata_For_your_convenience_we_have_provided_the_existing_test_cases_used_for_the_language_that_you_have_already_completed_as_well_as_all_of_the_other_related_fields";
23 | assertEquals("YouHaveChosenToTranslateThisKataForYourConvenienceWeHaveProvidedTheExistingTestCasesUsedForTheLanguageThatYouHaveAlreadyCompletedAsWellAsAllOfTheOtherRelatedFields", new ConvertStringToCamelCase().toCamelCase(input));
24 | }
25 |
26 | @Test
27 | public void shouldWorkWithRandomValues() {
28 | String input = "bridge-Street-down-Wall-Green-down-river-Street-Street-Black";
29 | assertEquals("bridgeStreetDownWallGreenDownRiverStreetStreetBlack", new ConvertStringToCamelCase().toCamelCase(input));
30 | }
31 | }
--------------------------------------------------------------------------------
/src/test/java/kata/kyu5/ScrambliesTest.java:
--------------------------------------------------------------------------------
1 | package kata.kyu5;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.assertEquals;
6 |
7 | public class ScrambliesTest {
8 |
9 | private static void testing(boolean actual, boolean expected) {
10 | assertEquals(expected, actual);
11 | }
12 |
13 | @Test
14 | public void test() {
15 | System.out.println("Fixed Tests scramble");
16 | testing(new Scramblies().scramble("rkqodlw", "world"), true);
17 | testing(new Scramblies().scramble("cedewaraaossoqqyt", "codewars"), true);
18 | testing(new Scramblies().scramble("katas", "steak"), false);
19 | testing(new Scramblies().scramble("scriptjavx", "javascript"), false);
20 | testing(new Scramblies().scramble("scriptingjava", "javascript"), true);
21 | testing(new Scramblies().scramble("scriptsjava", "javascripts"), true);
22 | testing(new Scramblies().scramble("javscripts", "javascript"), false);
23 | testing(new Scramblies().scramble("aabbcamaomsccdd", "commas"), true);
24 | testing(new Scramblies().scramble("commas", "commas"), true);
25 | testing(new Scramblies().scramble("sammoc", "commas"), true);
26 | }
27 |
28 | }
--------------------------------------------------------------------------------
/src/test/java/kata/kyu6/BouncingBallsTest.java:
--------------------------------------------------------------------------------
1 | package kata.kyu6;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.assertEquals;
6 |
7 | public class BouncingBallsTest {
8 | @Test
9 | public void test1() {
10 | assertEquals(3, new BouncingBalls().bouncingBall(3.0, 0.66, 1.5));
11 | }
12 |
13 | @Test
14 | public void test2() {
15 | assertEquals(15, new BouncingBalls().bouncingBall(30.0, 0.66, 1.5));
16 | }
17 |
18 | @Test
19 | public void test3() {
20 | assertEquals(-1, new BouncingBalls().bouncingBall(0, 0.66, 1.5));
21 | }
22 |
23 | @Test
24 | public void test4() {
25 | assertEquals(-1, new BouncingBalls().bouncingBall(30.0, 0, 1.5));
26 | }
27 |
28 | @Test
29 | public void test5() {
30 | assertEquals(-1, new BouncingBalls().bouncingBall(30.0, 1, 1.5));
31 | }
32 |
33 | @Test
34 | public void test6() {
35 | assertEquals(-1, new BouncingBalls().bouncingBall(1, 0.66, 1.5));
36 | }
37 | }
--------------------------------------------------------------------------------
/src/test/java/kata/kyu6/BuildAPileOfCubesTest.java:
--------------------------------------------------------------------------------
1 | package kata.kyu6;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.assertEquals;
6 |
7 | public class BuildAPileOfCubesTest {
8 | @Test
9 | public void test1() {
10 | assertEquals(2022, new BuildAPileOfCubes().findNb(4183059834009L));
11 | }
12 |
13 | @Test
14 | public void test2() {
15 | assertEquals(-1, new BuildAPileOfCubes().findNb(24723578342962L));
16 | }
17 |
18 | @Test
19 | public void test3() {
20 | assertEquals(4824, new BuildAPileOfCubes().findNb(135440716410000L));
21 | }
22 |
23 | @Test
24 | public void test4() {
25 | assertEquals(3568, new BuildAPileOfCubes().findNb(40539911473216L));
26 | }
27 | }
--------------------------------------------------------------------------------
/src/test/java/kata/kyu6/DecodeTheMorseCodeTest.java:
--------------------------------------------------------------------------------
1 | package kata.kyu6;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.assertEquals;
6 |
7 | public class DecodeTheMorseCodeTest {
8 | @Test
9 | public void testExampleFromDescription() {
10 | assertEquals("HEY JUDE", new DecodeTheMorseCode().decode(".... . -.-- .--- ..- -.. ."));
11 | }
12 |
13 | }
--------------------------------------------------------------------------------
/src/test/java/kata/kyu6/DubstepTest.java:
--------------------------------------------------------------------------------
1 | package kata.kyu6;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.assertEquals;
6 |
7 | public class DubstepTest {
8 | @Test
9 | public void Test1() {
10 | assertEquals("ABC", new Dubstep().songDecoder("WUBWUBABCWUB"));
11 | }
12 |
13 | @Test
14 | public void Test2() {
15 | assertEquals("R L", new Dubstep().songDecoder("RWUBWUBWUBLWUB"));
16 | }
17 | }
--------------------------------------------------------------------------------
/src/test/java/kata/kyu6/EqualSidesOfAnArrayTest.java:
--------------------------------------------------------------------------------
1 | package kata.kyu6;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.assertEquals;
6 |
7 | public class EqualSidesOfAnArrayTest {
8 | @Test
9 | public void test() {
10 | assertEquals(3, new EqualSidesOfAnArray().findEvenIndex(new int[]{1, 2, 3, 4, 3, 2, 1}));
11 | assertEquals(1, new EqualSidesOfAnArray().findEvenIndex(new int[]{1, 100, 50, -51, 1, 1}));
12 | assertEquals(-1, new EqualSidesOfAnArray().findEvenIndex(new int[]{1, 2, 3, 4, 5, 6}));
13 | assertEquals(3, new EqualSidesOfAnArray().findEvenIndex(new int[]{20, 10, 30, 10, 10, 15, 35}));
14 | assertEquals(-1, new EqualSidesOfAnArray().findEvenIndex(new int[]{-8505, -5130, 1926, -9026}));
15 | assertEquals(1, new EqualSidesOfAnArray().findEvenIndex(new int[]{2824, 1774, -1490, -9084, -9696, 23094}));
16 | assertEquals(6, new EqualSidesOfAnArray().findEvenIndex(new int[]{4, 5, 6, 7, 8, 9, 10, 9, 8, 7, 6, 5, 4}));
17 | }
18 | }
--------------------------------------------------------------------------------
/src/test/java/kata/kyu6/FindTheMissingLetterTest.java:
--------------------------------------------------------------------------------
1 | package kata.kyu6;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.assertEquals;
6 |
7 | public class FindTheMissingLetterTest {
8 | @Test
9 | public void exampleTests() {
10 | assertEquals('e', new FindTheMissingLetter().findMissingLetter(new char[]{'a', 'b', 'c', 'd', 'f'}));
11 | assertEquals('P', new FindTheMissingLetter().findMissingLetter(new char[]{'O', 'Q', 'R', 'S'}));
12 | assertEquals(' ', new FindTheMissingLetter().findMissingLetter(new char[]{'a', 'b', 'c', 'd', 'e'}));
13 | }
14 | }
--------------------------------------------------------------------------------
/src/test/java/kata/kyu6/FindTheOddIntTest.java:
--------------------------------------------------------------------------------
1 | package kata.kyu6;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.assertEquals;
6 |
7 | public class FindTheOddIntTest {
8 | @Test
9 | public void findTest() {
10 | assertEquals(5, new FindTheOddInt().findIt(new int[]{20, 1, -1, 2, -2, 3, 3, 5, 5, 1, 2, 4, 20, 4, -1, -2, 5}));
11 | assertEquals(-1, new FindTheOddInt().findIt(new int[]{1, 1, 2, -2, 5, 2, 4, 4, -1, -2, 5}));
12 | assertEquals(5, new FindTheOddInt().findIt(new int[]{20, 1, 1, 2, 2, 3, 3, 5, 5, 4, 20, 4, 5}));
13 | assertEquals(10, new FindTheOddInt().findIt(new int[]{10}));
14 | assertEquals(10, new FindTheOddInt().findIt(new int[]{1, 1, 1, 1, 1, 1, 10, 1, 1, 1, 1}));
15 | assertEquals(1, new FindTheOddInt().findIt(new int[]{5, 4, 3, 2, 1, 5, 4, 3, 2, 10, 10}));
16 | assertEquals(0, new FindTheOddInt().findIt(new int[]{5, 4, 3, 2, 1, 5, 4, 3, 2, 10, 10, 1}));
17 | }
18 | }
--------------------------------------------------------------------------------
/src/test/java/kata/kyu6/GiveMeADiamondTest.java:
--------------------------------------------------------------------------------
1 | package kata.kyu6;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.assertEquals;
6 |
7 | public class GiveMeADiamondTest {
8 |
9 | @Test
10 | public void testDiamondNull1() {
11 | assertEquals(null, new GiveMeADiamond().print(2));
12 | }
13 |
14 | @Test
15 | public void testDiamondNull2() {
16 | assertEquals(null, new GiveMeADiamond().print(-1));
17 | }
18 |
19 | @Test
20 | public void testDiamond3() {
21 | StringBuffer expected = new StringBuffer();
22 | expected.append(" *\n");
23 | expected.append("***\n");
24 | expected.append(" *\n");
25 |
26 | assertEquals(expected.toString(), new GiveMeADiamond().print(3));
27 | }
28 |
29 | @Test
30 | public void testDiamond5() {
31 | StringBuffer expected = new StringBuffer();
32 | expected.append(" *\n");
33 | expected.append(" ***\n");
34 | expected.append("*****\n");
35 | expected.append(" ***\n");
36 | expected.append(" *\n");
37 |
38 | assertEquals(expected.toString(), new GiveMeADiamond().print(5));
39 | }
40 | }
--------------------------------------------------------------------------------
/src/test/java/kata/kyu6/SortTheOddTest.java:
--------------------------------------------------------------------------------
1 | package kata.kyu6;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.assertArrayEquals;
6 |
7 | public class SortTheOddTest {
8 |
9 | @Test
10 | public void exampleTest1() {
11 | assertArrayEquals(new int[]{1, 3, 2, 8, 5, 4}, new SortTheOdd().sortArray(new int[]{5, 3, 2, 8, 1, 4}));
12 | }
13 |
14 | @Test
15 | public void exampleTest2() {
16 | assertArrayEquals(new int[]{1, 3, 5, 8, 0}, new SortTheOdd().sortArray(new int[]{5, 3, 1, 8, 0}));
17 | }
18 |
19 | @Test
20 | public void exampleTest3() {
21 | assertArrayEquals(new int[]{}, new SortTheOdd().sortArray(new int[]{}));
22 | }
23 |
24 | }
--------------------------------------------------------------------------------
/src/test/java/kata/kyu6/TripleTroubleTest.java:
--------------------------------------------------------------------------------
1 | package kata.kyu6;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.assertEquals;
6 |
7 | public class TripleTroubleTest {
8 |
9 | @Test
10 | public void test1() {
11 | assertEquals(1, new TripleTrouble().tripleDouble(451999277L, 41177722899L));
12 | }
13 |
14 | @Test
15 | public void test2() {
16 | assertEquals(0, new TripleTrouble().tripleDouble(1222345L, 12345L));
17 | }
18 |
19 | @Test
20 | public void test3() {
21 | assertEquals(0, new TripleTrouble().tripleDouble(12345L, 12345L));
22 | }
23 |
24 | @Test
25 | public void test4() {
26 | assertEquals(1, new TripleTrouble().tripleDouble(666789L, 12345667L));
27 | }
28 |
29 | @Test
30 | public void test5() {
31 | assertEquals(0, new TripleTrouble().tripleDouble(451999277L, 411777228L));
32 | }
33 | }
--------------------------------------------------------------------------------
/src/test/java/kata/kyu6/VasyaClerkTest.java:
--------------------------------------------------------------------------------
1 | package kata.kyu6;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.assertEquals;
6 |
7 | public class VasyaClerkTest {
8 | @Test
9 | public void test1() {
10 | assertEquals("YES", new VasyaClerk().tickets(new int[]{25, 25, 50}));
11 | }
12 |
13 | @Test
14 | public void test2() {
15 | assertEquals("NO", new VasyaClerk().tickets(new int[]{25, 100}));
16 | }
17 |
18 | @Test
19 | public void test3() {
20 | assertEquals("YES", new VasyaClerk().tickets(new int[]{25, 25, 50, 100}));
21 | }
22 |
23 | @Test
24 | public void test4() {
25 | assertEquals("NO", new VasyaClerk().tickets(new int[]{25, 50, 100}));
26 | }
27 | }
--------------------------------------------------------------------------------
/src/test/java/kata/kyu6/YourOrderPleaseTest.java:
--------------------------------------------------------------------------------
1 | package kata.kyu6;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.hamcrest.CoreMatchers.equalTo;
6 | import static org.junit.Assert.assertThat;
7 |
8 | public class YourOrderPleaseTest {
9 | @Test
10 | public void test1() {
11 | assertThat(new YourOrderPlease().order("is2 Thi1s T4est 3a"), equalTo("Thi1s is2 3a T4est"));
12 | }
13 |
14 | @Test
15 | public void test2() {
16 | assertThat(new YourOrderPlease().order("4of Fo1r pe6ople g3ood th5e the2"), equalTo("Fo1r the2 g3ood 4of th5e pe6ople"));
17 | }
18 |
19 | @Test
20 | public void test3() {
21 | assertThat("Empty input should return empty string", new YourOrderPlease().order(""), equalTo(""));
22 | }
23 | }
--------------------------------------------------------------------------------
/src/test/java/kata/kyu7/DescendingOrderTest.java:
--------------------------------------------------------------------------------
1 | package kata.kyu7;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.assertEquals;
6 |
7 | public class DescendingOrderTest {
8 | @Test
9 | public void test_01() {
10 | assertEquals(0, new DescendingOrder().sortDesc(0));
11 | }
12 |
13 | @Test
14 | public void test_02() {
15 | assertEquals(51, new DescendingOrder().sortDesc(15));
16 | }
17 |
18 | @Test
19 | public void test_03() {
20 | assertEquals(987654321, new DescendingOrder().sortDesc(123456789));
21 | }
22 | }
--------------------------------------------------------------------------------
/src/test/java/kata/kyu7/GrowthOfAPopulationTest.java:
--------------------------------------------------------------------------------
1 | package kata.kyu7;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.assertEquals;
6 |
7 | public class GrowthOfAPopulationTest {
8 | private static void testing(int actual, int expected) {
9 | assertEquals(expected, actual);
10 | }
11 | @Test
12 | public void test1() {
13 | testing(new GrowthOfAPopulation().nbYear(1500, 5, 100, 5000), 15);
14 | testing(new GrowthOfAPopulation().nbYear(1500000, 2.5, 10000, 2000000), 10);
15 | testing(new GrowthOfAPopulation().nbYear(1500000, 0.25, 1000, 2000000), 94);
16 | }
17 | }
--------------------------------------------------------------------------------
/src/test/java/kata/kyu7/JadenCasingStringsTest.java:
--------------------------------------------------------------------------------
1 | package kata.kyu7;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.assertEquals;
6 | import static org.junit.Assert.assertNull;
7 |
8 | public class JadenCasingStringsTest {
9 |
10 | @Test
11 | public void test() {
12 | assertEquals("toJadenCase doesn't return a valide JadenCase String! try again please :)", "Most Trees Are Blue", new JadenCasingStrings().toJadenCase("most trees are blue"));
13 | }
14 |
15 | @Test
16 | public void testNullArg() {
17 | assertNull("Must return null when the arg is null", new JadenCasingStrings().toJadenCase(null));
18 | }
19 |
20 | @Test
21 | public void testEmptyArg() {
22 | assertNull("Must return null when the arg is null", new JadenCasingStrings().toJadenCase(""));
23 | }
24 | }
--------------------------------------------------------------------------------
/src/test/java/kata/kyu7/MoneyMoneyMoneyTest.java:
--------------------------------------------------------------------------------
1 | package kata.kyu7;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.assertEquals;
6 |
7 | public class MoneyMoneyMoneyTest {
8 | @Test
9 | public void test() {
10 | System.out.println("Fixed Tests calculateYears");
11 | assertEquals(3, new MoneyMoneyMoney().calculateYears(1000, 0.05, 0.18, 1100));
12 | assertEquals(14, new MoneyMoneyMoney().calculateYears(1000, 0.01625, 0.18, 1200));
13 | assertEquals(0, new MoneyMoneyMoney().calculateYears(1000, 0.05, 0.18, 1000));
14 | }
15 |
16 | }
--------------------------------------------------------------------------------
/src/test/java/kata/kyu7/OnesAndZerosTest.java:
--------------------------------------------------------------------------------
1 | package kata.kyu7;
2 |
3 | import org.junit.Test;
4 |
5 | import java.util.ArrayList;
6 | import java.util.Arrays;
7 |
8 | import static org.junit.Assert.assertEquals;
9 |
10 | public class OnesAndZerosTest {
11 | @Test
12 | public void convertBinaryArrayToInt() {
13 | assertEquals(1, new OnesAndZeros().convertBinaryArrayToInt(new ArrayList<>(Arrays.asList(0, 0, 0, 1))));
14 | assertEquals(15, new OnesAndZeros().convertBinaryArrayToInt(new ArrayList<>(Arrays.asList(1, 1, 1, 1))));
15 | assertEquals(6, new OnesAndZeros().convertBinaryArrayToInt(new ArrayList<>(Arrays.asList(0, 1, 1, 0))));
16 | assertEquals(9, new OnesAndZeros().convertBinaryArrayToInt(new ArrayList<>(Arrays.asList(1, 0, 0, 1))));
17 | }
18 | }
--------------------------------------------------------------------------------
/src/test/java/kata/kyu7/ShortestWordTest.java:
--------------------------------------------------------------------------------
1 | package kata.kyu7;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.assertEquals;
6 |
7 | public class ShortestWordTest {
8 | @Test
9 | public void findShort() {
10 | assertEquals(3, new ShortestWord().findShort("bitcoin take over the world maybe who knows perhaps"));
11 | assertEquals(3, new ShortestWord().findShort("turns out random test cases are easier than writing out basic ones"));
12 | }
13 | }
--------------------------------------------------------------------------------
/src/test/java/kata/kyu8/MultiplyTest.java:
--------------------------------------------------------------------------------
1 | package kata.kyu8;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.assertEquals;
6 |
7 | public class MultiplyTest {
8 | @Test
9 | public void testSomething() {
10 | assertEquals((Double) 4d, new Multiply().multiply(2d, 2d));
11 | }
12 | }
--------------------------------------------------------------------------------
/src/test/java/kata/kyu8/RemoveStringSpacesTest.java:
--------------------------------------------------------------------------------
1 | package kata.kyu8;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.assertEquals;
6 |
7 | public class RemoveStringSpacesTest {
8 | @Test
9 | public void testSomething() {
10 | assertEquals("8j8mBliB8gimjB8B8jlB", new RemoveStringSpaces().noSpace("8 j 8 mBliB8g imjB8B8 jl B"));
11 | assertEquals("88Bifk8hB8BB8BBBB888chl8BhBfd", new RemoveStringSpaces().noSpace("8 8 Bi fk8h B 8 BB8B B B B888 c hl8 BhB fd"));
12 | assertEquals("8aaaaaddddr", new RemoveStringSpaces().noSpace("8aaaaa dddd r "));
13 | assertEquals("jfBmgklf8hg88lbe8", new RemoveStringSpaces().noSpace("jfBm gk lf8hg 88lbe8 "));
14 | assertEquals("8jaam", new RemoveStringSpaces().noSpace("8j aam"));
15 | }
16 | }
--------------------------------------------------------------------------------