Skip to content

Conversation

@transducer
Copy link
Contributor

Dear maintainer,

Based on inquiries I changed some code. I think it's now more correct. Let me know if there are any questions.

Kind regards,
Erwin


Activity 4.01:

Align and do not use default with apply min
Since (apply min <any-coll> 0) is always 0

Exercise 6.07:

There's a bug in the code for direct routes that are not over multiple hops.
min-route expects a collection so we should always return a collection.

This way it works for both direct and indirect routes:

(find-path (grouped-routes routes) :paris :london)
;; => {:cost 236, :best [:paris :london]}
(find-path (grouped-routes routes) :paris :budapest)
;; => {:cost 251, :best [:paris :milan :vienna :budapest]}

Since (apply min <any-coll> 0) is always 0
There's a bug in the code for direct routes that are not over multiple hops.
min-route expects a collection so we should always return a collection.

This way it works for both direct and indirect routes:

(find-path (grouped-routes routes) :paris :london)
;; => {:cost 236, :best [:paris :london]}
(find-path (grouped-routes routes) :paris :budapest)
;; => {:cost 251, :best [:paris :milan :vienna :budapest]}
(->> users
(filter #(= (:status %) status))
(map field)
(apply min))) ;; do not use a default, (min '()) returns nil
Copy link

@allentiak allentiak Apr 15, 2023

Choose a reason for hiding this comment

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

Maybe this might work better?
(apply (fnil min 0)))

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@allentiak doesn't work since min takes variable amount of arguments

Copy link
Contributor Author

@transducer transducer May 8, 2023

Choose a reason for hiding this comment

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

Note that how the code was before, for the values of the game-users it will always return a min of 0

Choose a reason for hiding this comment

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

I see...

Choose a reason for hiding this comment

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

Thanks for the answer!

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