I found a corner case on the find sum in list that I overlooked. If the list is [1,2,5] and the number is 4 I will return true because I am looking through the whole list for K-element and will of course find element. I was so happy to get a single line that worked, I am wondering if I can fix it and still keep it one line?
https://git.qoto.org/Absinthe/sum-of-number-in-list
I know count may work better than any, or some other logic to handle the special case of K-element == element
@zingbretsen care to take a shot at a fix for my one-line solution in this one?
@zingbretsen it is the direction I was trying to get to, because I don't think I need to check any one I have already visited a second time. Those list semantics with the : throw me, I am still getting to know them, but that feels right, I will try it when I get home.
@zingbretsen I like the list slicing it just isn't a first class tool for me yet. Sure if I use it a few more times it will stick
@Absinthe exactly, if you already visited an item, you don't need to check it again.
List slicing is very useful. It is inclusive of the first index and exclusive of the second index. e.g.,
[0,1,2,3,4][1:3] would return [1,2]
Leaving off the first index will start you at the beginning of the list.
Leaving off the second index will include everything through the end of the list.