Uh oh!
There was an error while loading. Please reload this page.
[Darts Approach Docs] Various fixes and improvements - #4187
Conversation
@BethanyG I feel like there's a better way to formulate this variant of the dict and generator approach, but nothing's coming to mind... defscore(x_coord, y_coord):
throw=x_coord**2+y_coord**2rules= {1: 10, 25: 5, 100: 1}
return ([pointfordistance, pointinrules.items() ifthrow<=distance]
or [0])[0] # <-- Have to specify index 0. |
That's also not a generator. It is making a |
Yrahcaz7
commented
May 16, 2026
Yeah, most of the variants of the dict and generator approach actually use generator expressions, but for some reason this one is just a list comprehension. I'll try to take a look at it again tomorrow if I have time. |
I feel like this is every bit as awkward (guess it follows the text about needing an index tho): defscore(x_coord, y_coord):
throw=x_coord**2+y_coord**2rules= {1: 10, 25: 5, 100: 1, 1000: 0}
result= [rules.get(distance, 0) fordistanceinrules.keys() ifthrow<=distance][0]
returnresultI guess we could unpack it as a generator? defscore(x_coord, y_coord):
throw=x_coord**2+y_coord**2rules= {1: 10, 25: 5, 100: 1, 1000: 0}
result= (rules.get(distance, 0) fordistanceinrules.keys() ifthrow<=distance)
returnnext(result)Feels entirely over-engineered and clever. Also requires a 4th entry in the This works too, but now I need a shower to wash off the ick: defscore(x_coord, y_coord):
throw=x_coord**2+y_coord**2rules= {1: 10, 25: 5, 100: 1, 1000: 0}
returnnext(rules.get(distance, 0) fordistanceinrules.keys() ifthrow<=distance)... defscore(x_coord, y_coord):
throw=x_coord**2+y_coord**2rules= {1: 10, 25: 5, 100: 1}
returnnext(rules.get(distance, 0) fordistancein (1, 25, 100, 1000) ifthrow<=distance)Or defscore(x_coord, y_coord):
throw=x_coord**2+y_coord**2rules= {1: 10, 25: 5, 100: 1}
result=next(rules.get(distance, 0) fordistancein
(1, 25, 100, 1000) ifthrow<=distance)
returnresult |
Yrahcaz7
commented
May 16, 2026
Yeah that last one isn't very readable. Also half the point of changing it in the first place was to get rid of the fourth dict entry 😅. Hopefully I'll have time to come back to this tomorrow... Maybe one of us will have a new idea to try by then. |
BethanyG
commented
May 16, 2026
I'm beat. Time to watch bad TV and knit. See you fresh in the AM. 💙 |
New idea: frommathimportinfdefscore(x_coord, y_coord):
throw=x_coord**2+y_coord**2rules= {1: 10, 25: 5, 100: 1, inf: 0}
return [pointfordistance, pointinrules.items() ifthrow<=distance][0] # <-- Have to specify index 0.Fairly clean, but requires an import. |
BethanyG
commented
May 17, 2026
Works for me. 😄 |
BethanyG
left a comment
There was a problem hiding this comment.
Wow. That was a LOT. Nice work. 😄
BethanyG
commented
May 17, 2026
Worried that if you or I give it one more read, there will be changes. Shall we let it sit for a bit for rereivew, or are you ready to merge? |
Yrahcaz7
commented
May 17, 2026
I think it would probably be a good idea to wait for a day and then re-review. Looking at the changes again with fresh eyes might spot previously-unseen mistake(s). (I don't trust myself enough to believe that there aren't any on this big of a change.) |
BethanyG
commented
May 18, 2026
Heya @Yrahcaz7 I just went over this again and am not seeing anything more to correct. So if you are happy with this, I will merge it! Thanks again for all the hard work here. 🙂 |
Yrahcaz7
commented
May 18, 2026
I looked it over one more time just in case, but it looks good! Feel free to merge! |
Applied the fixes and improvements to the Darts exercise's approach docs that were discussed here.