Skip to content

I have created a PR otherwise it is hard to comment on the code#1

Open
yuriykulikov wants to merge 24 commits intoreviewedfrom
main
Open

I have created a PR otherwise it is hard to comment on the code#1
yuriykulikov wants to merge 24 commits intoreviewedfrom
main

Conversation

@yuriykulikov
Copy link
Collaborator

If you want you can create PRs every day to discuss

@yuriykulikov yuriykulikov requested a review from tspopp December 10, 2022 17:14
var lookup = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";

fun silver(lines: List<String>): Int {
return lines.map { line -> Pair(line.substring(0, line.length / 2), line.substring(line.length / 2)) }
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return lines.map { line -> Pair(line.substring(0, line.length / 2), line.substring(line.length / 2)) }
return lines.map { line -> line.substring(0, line.length / 2) to line.substring(line.length / 2) }


fun silver(lines: List<String>): Int {
return lines.map { line -> Pair(line.substring(0, line.length / 2), line.substring(line.length / 2)) }
.map { pair ->
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
.map { pair ->
.map { (left, right) ->

}
}

fun createPairOfCollections(line: String): Pair<List<Int>, List<Int>> {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Try to avoid Pairs in function signatures. It is hard to read.


@Test
fun sampleSilver() {
val (stack, commands) = parseStackAndCommands("sample")
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not 2 functions?

}
}

fun findMessage(line: String, length: Int): Int {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!

RIGHT
}

typealias Coordinate = Pair<Int, Int>
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
typealias Coordinate = Pair<Int, Int>
data class Coordinate (val x: Int, val y: Int)

return Forest(lines.map { it.windowed(1, 1) }
.flatMapIndexed { y: Int, row: List<String> ->
row.mapIndexed { x, it ->
Coordinate(
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very nice!

Copy link
Collaborator Author

@yuriykulikov yuriykulikov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking good 👍

}
}

fun pointInExactRadius(point: Point, radius: Int): HashSet<Point> {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good one!

return render
}

override fun equals(other: Any?): Boolean {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

data classes already have both hashCode and equals

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, but I wanted to exclude the rendered char from equals. A point which is rendered as x should be equal to a point at the same coords rendered as #.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants