Skip to content

Partial solution for Exercise 3 #13

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

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

Slobodanvukojevic
Copy link

πŸš€ Programing language Kotlin course - Assignment Submission For Exercise 3 (Except Task 3)

πŸ‘¨β€πŸŽ“πŸ‘©β€πŸŽ“ Full name of the Author

Full name: Slobodan Vukojevic

βœ… Checklist

  • The submitted code is cleaned up.
  • Solutions passes all tests.

@vuksa vuksa added the exercise3 label Apr 1, 2024
TODO("Implement me!!!")
val stack = mutableListOf<Char>()

for (char in expression) {
Copy link
Owner

Choose a reason for hiding this comment

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

Well done! For practice, try solving it with a functional approach. :)

@@ -10,29 +10,56 @@ package exercise3.task4
* Find all the drivers who performed no trips.
*/
internal fun TaxiPark.findFakeDrivers(): Set<Driver> {
TODO("Implement me!!!")
return allDrivers.filter { driver -> trips.none { it.driver == driver } }
Copy link
Owner

Choose a reason for hiding this comment

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

This is a correct solution, but its performance is not great because we'll have to do D * T iterations, where D is the number of drivers, and T is the number of trips.

The same solution can be done by mapping all the drivers from trips and then deducting all drivers from the list of drivers present in trips.

allDrivers - trips.map { it.driver }
This way we only once iterate over the trips list.


return passengerDiscountTripsCount
.filter { (_, discounts) ->
discounts >= trips.size / 2
Copy link
Owner

@vuksa vuksa Apr 6, 2024

Choose a reason for hiding this comment

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

Why are we comparing this with half of all trips? Shouldn't we compare against half of the trips this user made?

@vuksa vuksa added the reviewed label Apr 20, 2024
@vuksa vuksa force-pushed the main branch 3 times, most recently from 6106c56 to 8296ece Compare May 20, 2024 11:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants