Skip to content
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

triangle: incorrect test in some tracks #95

Closed
kytrinyx opened this issue Jan 29, 2016 · 1 comment · Fixed by #96
Closed

triangle: incorrect test in some tracks #95

kytrinyx opened this issue Jan 29, 2016 · 1 comment · Fixed by #96

Comments

@kytrinyx
Copy link
Member

Please check if there's a test that states that a triangle with sides 2, 4, 2 is invalid. The triangle inequality states that for any triangle, the sum of the lengths of any two sides must be greater than or equal to the length of the remaining side. If this doesn't affect this track, go ahead and just close the issue.

@yurrriq
Copy link
Member

yurrriq commented Jan 29, 2016

There is not. On it.

Upon re-reading, I get your intended meaning.

yurrriq added a commit that referenced this issue Jan 30, 2016
Use empty lines between top-level forms.

Exclude #'clojure.core/type to avoid collision

Make #'triangle/type point-free and ~2x faster

If the sides are invalid, there's no need to compute the set.
Unlike cond, case does a constant-time dispatch. Since we're effectively
performing case analysis on 1 and 2 (constants), we might as well use
case instead of cond. The point-free-ness of this change is both a
matter of personal taste and "lazy" evaluation, i.e. don't compute
unnecessary values.

The previous solution's use of:

    (partition-by identity (sort [a b c]))

... is unnecessarily complex.

    (hash-set a b c)

... gets the job done more simply.

Fix #95

https://github.com/bbatsov/clojure-style-guide#empty-lines-between-top-level-forms
@yurrriq yurrriq reopened this Jan 30, 2016
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 a pull request may close this issue.

2 participants