Skip to content

Commit 64a09d6

Browse files
05 & 06 exercises (egonSchiele#114)
Co-authored-by: Aditya Bhargava <bluemangroupie@gmail.com>
1 parent 0292985 commit 64a09d6

File tree

4 files changed

+32
-52
lines changed

4 files changed

+32
-52
lines changed

05_hash_tables/kotlin/01_price_of_groceries.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
12
fun main(args: Array<String>) {
23

34
val book = hashMapOf<String, Double>(
@@ -7,4 +8,4 @@ fun main(args: Array<String>) {
78
)
89

910
println(book)
10-
}
11+
}

05_hash_tables/kotlin/02_check_voter.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,4 @@ fun main(args: Array<String>) {
1616
checkVoter("tom")
1717
checkVoter("mike")
1818
checkVoter("mike")
19-
}
19+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import java.util.*
2+
3+
val graph = hashMapOf(
4+
"You" to listOf("Sergey", "Viktoria"),
5+
"Viktoria" to listOf("Sergey", "Vladimir"),
6+
"Vladimir" to listOf("Sergey", "Andrew", "Nikita", "Boris")
7+
)
8+
9+
private fun breadthFirstSearch(name: String) {
10+
val queue = ArrayDeque(graph[name])
11+
val searched = arrayListOf<String>()
12+
while (queue.isNotEmpty()) {
13+
val person = queue.poll()
14+
if (!searched.contains(person)) {
15+
if (personIsSeller(person)) {
16+
println("$person is a mango seller!")
17+
return
18+
} else {
19+
graph[person]?.let { queue.addAll(it) }
20+
searched.add(person)
21+
}
22+
}
23+
}
24+
println("No mango sellers found!")
25+
}
26+
27+
private fun personIsSeller(name: String): Boolean = name.endsWith("s")
28+
29+
fun main(args: Array<String>) = println(breadthFirstSearch("You"))

06_breadth-first_search/kotlin/BreadthFirstSearch.kt

Lines changed: 0 additions & 50 deletions
This file was deleted.

0 commit comments

Comments
 (0)