Ranter
Join devRant
Do all the things like
++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatar
Sign Up
Pipeless API
From the creators of devRant, Pipeless lets you power real-time personalized recommendations and activity feeds using a simple API
Learn More
Comments
-
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"
-
@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)². -
@yellow-dog I meant an algorithm invented by yourself, not using an existing one. Thanks though.
-
cb21910195y@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? -
@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
else if(l1.head == l2.head && l1.last == l2.last)
listEq(l1.drop(1).dropRight(1), l2.drop(1).dropRight(1))
else false
}
println(listOfLists.filter(listEq(_, neededList)))
} -
@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.
-
@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. -
@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?
-
@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
-
@ArcaneEye I'm not sure, but I think it's the second situation you've mentioned. Interesting implementation idea you have there.. a stack..
-
@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
Related Rants
-
nachocode18If you had one language One framework To code everything you want Would you learn it or let it pass His cod...
-
blacckpigy12When i open a 2 gigabyte wordlist text file and forgot that my defaults text editor is GUI based.
-
reactivedev10When developers are frustrated with stupid laws 😂😂
I hate manipulating collections. It's difficult matter for me. Nodes, trees, traversal, efficiency. Argh.
rant
collections
junior dev
frustration