Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Add toInts() in Utils for Day 1 #6

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
johnkchiu wants to merge 1 commit into kotlin-hands-on:main from johnkchiu:FixDay1ToInts
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/Day01.kt
View file Open in desktop
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
fun main() {
fun part1(input: List<String>): Int {
fun part1(input: List<Int>): Int {
return input.size
}

fun part2(input: List<String>): Int {
fun part2(input: List<Int>): Int {
return input.size
}

// test if implementation meets criteria from the description, like:
val testInput = readInput("Day01_test")
val testInput = readInput("Day01_test").toInts()
check(part1(testInput) == 1)

val input = readInput("Day01")
val input = readInput("Day01").toInts()
println(part1(input))
println(part2(input))
}
5 changes: 5 additions & 0 deletions src/Utils.kt
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ import java.security.MessageDigest
*/
fun readInput(name: String) = File("src", "$name.txt").readLines()

/**
* Converts `List<String>` to `List<Int>`
*/
fun List<String>.toInts() = map { it.toInt() }

/**
* Converts string to md5 hash.
*/
Expand Down

AltStyle によって変換されたページ (->オリジナル) /