2

# I hate manipulating collections. It's difficult matter for me. Nodes, trees, traversal, efficiency. Argh.

• 0
Well, it's easy, but it's ugly as shit in JS. Whenever I have to do it there, my brain just says "no pls why"
• 0
@kescherRant Ok, if it's easy, provide an algorithm for the following:

Find a list of values in a list of lists and after going through all lists, if that value is not found, then break program flow.

problem: if you go through the last collection and the values aren't found there, program flow will break. This is not desired.

Requirements: performance may not be O(n)².
• 1
@CaptainRant bigList.filter(_==neededList)
• 0
@yellow-dog I meant an algorithm invented by yourself, not using an existing one. Thanks though.
• 0
@CaptainRant isn't your above mentioned situation contradicting with the problem, where the algorithm should break? am I missing something?
Sounds a bit like a problem, where you have to find a sequence of characters in a block of text. Is that relatable? I've had a uni course about this, where different strategies were explained, but I don't remember anything about that.
It might be a hint to a solution?
• 0
@CaptainRant here, even tho filter and == are pretty atomic functions, you didnt specify i needed to do it like its 1991

edit: fuck it looks awful, highlight bot doesnt like things pasted on desktop, here it is: https://hastebin.com/dasajimowe.sca...

@highlight

object Main extends App {

val listOfLists = List(List(1,2,3),List(3,5),List(7,7,10,2))

val neededList = List(3,5)

def listEq(l1: List[Int], l2: List[Int]): Boolean = {

if(l1.isEmpty && l2.isEmpty) true

listEq(l1.drop(1).dropRight(1), l2.drop(1).dropRight(1))

else false

}

println(listOfLists.filter(listEq(_, neededList)))

}
• 0
• 0
@yellow-dog Thanks for the effort. I'm just not used to modern language constructs because I've mostly used Java 1.5 professionally, not 8 and above. It's like a whole new world out there.
• 0
@cb219 It's basically:

-> You have a list of lists, where each list line contains a <key,val>

-> You have a list of fixed values that are supposed to match the keys in the aforementioned collection

-> For each list, match the fixed values in the static list to to <key> part

-> If after having gone through all lists, one of the values in the static list isn't found at any point in the traversal, the program should abort because the requirement is that all values in the static list should be present and matchable with one or more of the lists in the list of lists.
• 0
@CaptainRant so will the keys be represented more than once in the original set? As in: will I need to insert the value in the second list more than once or could I put them in a stack and pop/check one at a time and discard it once its' match has been found and then break if it's not allocated?
• 1
@CaptainRant also, I kinda like data structures and learning about them. There's a certain kind of beauty in the way algorithms can be applied to different data structures and the logic is like a torch in the darkness
• 0
@ArcaneEye I'm not sure, but I think it's the second situation you've mentioned. Interesting implementation idea you have there.. a stack..
• 0
@ArcaneEye :) Spoken like a true innovator.
• 0
@CaptainRant eh, I don't consider myself innovative, I'm just good at taking a problem and figuring out what existing tools work well, innovation has more to do with finding a problem noone knows is there and that's not really my strong suit.

I just... Really like numbers and patterns and systems, in a non-rainman-kinda-way :-p