diff --git a/kotlin/acronym/.idea/workspace.xml b/kotlin/acronym/.idea/workspace.xml index 690e077..3879510 100644 --- a/kotlin/acronym/.idea/workspace.xml +++ b/kotlin/acronym/.idea/workspace.xml @@ -485,7 +485,7 @@ - + @@ -908,7 +908,7 @@ - @@ -921,7 +921,7 @@ - + diff --git a/kotlin/scrabble-score/.gradle/3.5/file-changes/last-build.bin b/kotlin/scrabble-score/.gradle/3.5/file-changes/last-build.bin new file mode 100644 index 0000000..f76dd23 Binary files /dev/null and b/kotlin/scrabble-score/.gradle/3.5/file-changes/last-build.bin differ diff --git a/kotlin/scrabble-score/.gradle/3.5/taskHistory/taskHistory.lock b/kotlin/scrabble-score/.gradle/3.5/taskHistory/taskHistory.lock new file mode 100644 index 0000000..aeec3d7 Binary files /dev/null and b/kotlin/scrabble-score/.gradle/3.5/taskHistory/taskHistory.lock differ diff --git a/kotlin/scrabble-score/.gradle/buildOutputCleanup/built.bin b/kotlin/scrabble-score/.gradle/buildOutputCleanup/built.bin new file mode 100644 index 0000000..e69de29 diff --git a/kotlin/scrabble-score/.gradle/buildOutputCleanup/cache.properties b/kotlin/scrabble-score/.gradle/buildOutputCleanup/cache.properties new file mode 100644 index 0000000..96f4527 --- /dev/null +++ b/kotlin/scrabble-score/.gradle/buildOutputCleanup/cache.properties @@ -0,0 +1,2 @@ +#Mon Jun 05 18:06:30 EDT 2017 +gradle.version=3.5 diff --git a/kotlin/scrabble-score/.gradle/buildOutputCleanup/cache.properties.lock b/kotlin/scrabble-score/.gradle/buildOutputCleanup/cache.properties.lock new file mode 100644 index 0000000..40fdece --- /dev/null +++ b/kotlin/scrabble-score/.gradle/buildOutputCleanup/cache.properties.lock @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/kotlin/scrabble-score/.idea/compiler.xml b/kotlin/scrabble-score/.idea/compiler.xml new file mode 100644 index 0000000..80ed0bd --- /dev/null +++ b/kotlin/scrabble-score/.idea/compiler.xml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/kotlin/scrabble-score/.idea/gradle.xml b/kotlin/scrabble-score/.idea/gradle.xml new file mode 100644 index 0000000..20d2df6 --- /dev/null +++ b/kotlin/scrabble-score/.idea/gradle.xml @@ -0,0 +1,19 @@ + + + + + + \ No newline at end of file diff --git a/kotlin/scrabble-score/.idea/libraries/Gradle__junit_junit_4_12.xml b/kotlin/scrabble-score/.idea/libraries/Gradle__junit_junit_4_12.xml new file mode 100644 index 0000000..04c10dd --- /dev/null +++ b/kotlin/scrabble-score/.idea/libraries/Gradle__junit_junit_4_12.xml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/kotlin/scrabble-score/.idea/libraries/Gradle__org_hamcrest_hamcrest_core_1_3.xml b/kotlin/scrabble-score/.idea/libraries/Gradle__org_hamcrest_hamcrest_core_1_3.xml new file mode 100644 index 0000000..8262f72 --- /dev/null +++ b/kotlin/scrabble-score/.idea/libraries/Gradle__org_hamcrest_hamcrest_core_1_3.xml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/kotlin/scrabble-score/.idea/libraries/Gradle__org_jetbrains_annotations_13_0.xml b/kotlin/scrabble-score/.idea/libraries/Gradle__org_jetbrains_annotations_13_0.xml new file mode 100644 index 0000000..4f32fde --- /dev/null +++ b/kotlin/scrabble-score/.idea/libraries/Gradle__org_jetbrains_annotations_13_0.xml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/kotlin/scrabble-score/.idea/libraries/Gradle__org_jetbrains_kotlin_kotlin_stdlib_1_1_1.xml b/kotlin/scrabble-score/.idea/libraries/Gradle__org_jetbrains_kotlin_kotlin_stdlib_1_1_1.xml new file mode 100644 index 0000000..7b6f562 --- /dev/null +++ b/kotlin/scrabble-score/.idea/libraries/Gradle__org_jetbrains_kotlin_kotlin_stdlib_1_1_1.xml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/kotlin/scrabble-score/.idea/libraries/Gradle__org_jetbrains_kotlin_kotlin_test_1_1_1.xml b/kotlin/scrabble-score/.idea/libraries/Gradle__org_jetbrains_kotlin_kotlin_test_1_1_1.xml new file mode 100644 index 0000000..1720158 --- /dev/null +++ b/kotlin/scrabble-score/.idea/libraries/Gradle__org_jetbrains_kotlin_kotlin_test_1_1_1.xml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/kotlin/scrabble-score/.idea/libraries/Gradle__org_jetbrains_kotlin_kotlin_test_junit_1_1_1.xml b/kotlin/scrabble-score/.idea/libraries/Gradle__org_jetbrains_kotlin_kotlin_test_junit_1_1_1.xml new file mode 100644 index 0000000..21c5d19 --- /dev/null +++ b/kotlin/scrabble-score/.idea/libraries/Gradle__org_jetbrains_kotlin_kotlin_test_junit_1_1_1.xml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/kotlin/scrabble-score/.idea/misc.xml b/kotlin/scrabble-score/.idea/misc.xml new file mode 100644 index 0000000..84da703 --- /dev/null +++ b/kotlin/scrabble-score/.idea/misc.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/kotlin/scrabble-score/.idea/modules.xml b/kotlin/scrabble-score/.idea/modules.xml new file mode 100644 index 0000000..d6c2387 --- /dev/null +++ b/kotlin/scrabble-score/.idea/modules.xml @@ -0,0 +1,10 @@ + + + + + + + + + + \ No newline at end of file diff --git a/kotlin/scrabble-score/.idea/modules/scrabble-score_main.iml b/kotlin/scrabble-score/.idea/modules/scrabble-score_main.iml new file mode 100644 index 0000000..4dec876 --- /dev/null +++ b/kotlin/scrabble-score/.idea/modules/scrabble-score_main.iml @@ -0,0 +1,40 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/kotlin/scrabble-score/.idea/modules/scrabble-score_test.iml b/kotlin/scrabble-score/.idea/modules/scrabble-score_test.iml new file mode 100644 index 0000000..00c0a58 --- /dev/null +++ b/kotlin/scrabble-score/.idea/modules/scrabble-score_test.iml @@ -0,0 +1,46 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/kotlin/scrabble-score/.idea/workspace.xml b/kotlin/scrabble-score/.idea/workspace.xml new file mode 100644 index 0000000..9c9cd52 --- /dev/null +++ b/kotlin/scrabble-score/.idea/workspace.xml @@ -0,0 +1,864 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 1496700387322 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/kotlin/scrabble-score/README.md b/kotlin/scrabble-score/README.md new file mode 100644 index 0000000..dd1890f --- /dev/null +++ b/kotlin/scrabble-score/README.md @@ -0,0 +1,46 @@ +# Scrabble Score + +Given a word, compute the scrabble score for that word. + +## Letter Values + +You'll need these: + +```plain +Letter Value +A, E, I, O, U, L, N, R, S, T 1 +D, G 2 +B, C, M, P 3 +F, H, V, W, Y 4 +K 5 +J, X 8 +Q, Z 10 +``` + +## Examples +"cabbage" should be scored as worth 14 points: + +- 3 points for C +- 1 point for A, twice +- 3 points for B, twice +- 2 points for G +- 1 point for E + +And to total: + +- `3 + 2*1 + 2*3 + 2 + 1` +- = `3 + 2 + 6 + 3` +- = `5 + 9` +- = 14 + +## Extensions +- You can play a double or a triple letter. +- You can play a double or a triple word. + +## Source + +Inspired by the Extreme Startup game [https://github.com/rchatley/extreme_startup](https://github.com/rchatley/extreme_startup) + +## Submitting Incomplete Solutions +It's possible to submit an incomplete solution so you can see how others have completed the exercise. + diff --git a/kotlin/scrabble-score/build.gradle b/kotlin/scrabble-score/build.gradle new file mode 100644 index 0000000..16c36c0 --- /dev/null +++ b/kotlin/scrabble-score/build.gradle @@ -0,0 +1,28 @@ +buildscript { + ext.kotlin_version = '1.1.1' + repositories { + mavenCentral() + } + dependencies { + classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" + } +} + +apply plugin: 'kotlin' + +repositories { + mavenCentral() +} + +dependencies { + compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version" + + testCompile 'junit:junit:4.12' + testCompile "org.jetbrains.kotlin:kotlin-test-junit:$kotlin_version" +} +test { + testLogging { + exceptionFormat = 'full' + events = ["passed", "failed", "skipped"] + } +} diff --git a/kotlin/scrabble-score/build/classes/main/Scrabble$scoreMap$2.class b/kotlin/scrabble-score/build/classes/main/Scrabble$scoreMap$2.class new file mode 100644 index 0000000..7b2bab0 Binary files /dev/null and b/kotlin/scrabble-score/build/classes/main/Scrabble$scoreMap$2.class differ diff --git a/kotlin/scrabble-score/build/classes/main/Scrabble.class b/kotlin/scrabble-score/build/classes/main/Scrabble.class new file mode 100644 index 0000000..54661be Binary files /dev/null and b/kotlin/scrabble-score/build/classes/main/Scrabble.class differ diff --git a/kotlin/scrabble-score/build/classes/test/ScrabbleScoreTest$Companion.class b/kotlin/scrabble-score/build/classes/test/ScrabbleScoreTest$Companion.class new file mode 100644 index 0000000..3f84d9e Binary files /dev/null and b/kotlin/scrabble-score/build/classes/test/ScrabbleScoreTest$Companion.class differ diff --git a/kotlin/scrabble-score/build/classes/test/ScrabbleScoreTest.class b/kotlin/scrabble-score/build/classes/test/ScrabbleScoreTest.class new file mode 100644 index 0000000..e2084b9 Binary files /dev/null and b/kotlin/scrabble-score/build/classes/test/ScrabbleScoreTest.class differ diff --git a/kotlin/scrabble-score/build/kotlin-build/caches/version.txt b/kotlin/scrabble-score/build/kotlin-build/caches/version.txt new file mode 100644 index 0000000..01aabac --- /dev/null +++ b/kotlin/scrabble-score/build/kotlin-build/caches/version.txt @@ -0,0 +1 @@ +11001 \ No newline at end of file diff --git a/kotlin/scrabble-score/scrabble-score.iml b/kotlin/scrabble-score/scrabble-score.iml new file mode 100644 index 0000000..2b7ff7d --- /dev/null +++ b/kotlin/scrabble-score/scrabble-score.iml @@ -0,0 +1,12 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/kotlin/scrabble-score/src/main/kotlin/.keep b/kotlin/scrabble-score/src/main/kotlin/.keep new file mode 100644 index 0000000..e69de29 diff --git a/kotlin/scrabble-score/src/main/kotlin/Scrabble.kt b/kotlin/scrabble-score/src/main/kotlin/Scrabble.kt new file mode 100644 index 0000000..85aae73 --- /dev/null +++ b/kotlin/scrabble-score/src/main/kotlin/Scrabble.kt @@ -0,0 +1,35 @@ +object Scrabble { + private val scoreMap: Map by lazy { + var tempMap = emptyMap().toMutableMap() + tempMap.put('A', 1) + tempMap.put('B', 3) + tempMap.put('C', 3) + tempMap.put('D', 2) + tempMap.put('E', 1) + tempMap.put('F', 4) + tempMap.put('G', 2) + tempMap.put('H', 4) + tempMap.put('I', 1) + tempMap.put('J', 8) + tempMap.put('K', 5) + tempMap.put('L', 1) + tempMap.put('M', 3) + tempMap.put('N', 1) + tempMap.put('O', 1) + tempMap.put('P', 3) + tempMap.put('Q', 10) + tempMap.put('R', 1) + tempMap.put('S', 1) + tempMap.put('T', 1) + tempMap.put('U', 1) + tempMap.put('V', 4) + tempMap.put('W', 4) + tempMap.put('X', 8) + tempMap.put('Y', 4) + tempMap.put('Z', 10) + tempMap + } + fun scoreWord(inpString: String): Int{ + return inpString.map { it.toUpperCase() }.fold(0, {acc, c -> acc + scoreMap.getOrDefault(c, 0) }) + } +} \ No newline at end of file diff --git a/kotlin/scrabble-score/src/test/kotlin/ScrabbleScoreTest.kt b/kotlin/scrabble-score/src/test/kotlin/ScrabbleScoreTest.kt new file mode 100644 index 0000000..621503e --- /dev/null +++ b/kotlin/scrabble-score/src/test/kotlin/ScrabbleScoreTest.kt @@ -0,0 +1,30 @@ +import org.junit.Test +import org.junit.Ignore +import org.junit.runner.RunWith +import org.junit.runners.Parameterized +import kotlin.test.assertEquals + +@RunWith(Parameterized::class) +class ScrabbleScoreTest(val input: String, val expectedOutput: Int) { + + companion object { + @JvmStatic + @Parameterized.Parameters(name = "{index}: scoreWord({0})={1}") + fun data() = listOf( + arrayOf("", 0), + arrayOf(" \t\n", 0), + arrayOf("a", 1), + arrayOf("f", 4), + arrayOf("street", 6), + arrayOf("quirky", 22), + arrayOf("OXYPHENBUTAZONE", 41), + arrayOf("alacrity", 13) + ) + } + + + @Test + fun test() { + assertEquals(expectedOutput, Scrabble.scoreWord(input)) + } +}