Programming Exercise #1
So, there is a lot of help around here dealing with syntax of scripting, but I don't see much discussion on best algorithms. Be this the case, I am going to every so often (when I feel like it) post some mathematically cool problem for you all to help each other solve and break some mental barriers.
Problem 1. Given 2 arrays of numbers, find all the sets of 3 numbers that both arrays have in common. Remember, the goal is to make this as efficient as possible with graal script. Edit: For clarification, this is a sample If you have the following two sets {2,3,5,6,8,10} {1,5,3,10,6,9,2} All of the sets of 3 would be {2,3,5} {2,3,6} {2,3,10} {2,5,6} {2,5,10} {2,6,10} {3,5,6} {3,5,10} {3,6,10} {5,6,10} New Edit: Let's do unique sets. If you have two sets of {1,1,2,3}, then the answer is {1,2,3}, not {1,2,3} {1,2,3} |
I have something I put together real quick, but it searches linearly, so someone could most certainly come up with something more efficient.
Also, I assumed that if both arrays are (for example): {1, 2, 3, 4, 5, 6} Then they would just have the two sets {1, 2, 3} and {4, 5, 6}. Instead of {1, 2, 3}, {2, 3, 4}, {3, 4, 5}, {4, 5, 6}. Also, there is a high chance that there is a case where the algorithm fails, as I haven't really tested it... so feel free to find a case that doesn't work :P. PHP Code:
|
interesting *waits for novo
|
I get the feeling I'm being manipulated, but...
PHP Code:
|
Hmm I never coded gscript, but whats about quicksorting both sets and find the common ones, then?
|
I never knew Googi could script. :)
|
What Googi posted doesn't make logical sense, at all. :p
|
PHP Code:
That doesn't check if all the sets are exactly different, I'll do that next I guess. You need to give examples of input and output >:( PHP Code:
|
Posted a sample to clarify for you tards.
|
PHP Code:
PHP Code:
|
Quote:
PHP Code:
|
Quote:
|
Quote:
Someone agrees with me. :3 |
Zero, that is incredibly inefficient. We want something better then the naive algorithm
|
Quote:
Quote:
|
All times are GMT +2. The time now is 07:46 AM. |
Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.