So we have this "homework" which seems to be one of those things found in Roswell, I guess. Looking for someone to help me out with this - literally any insight is priceless.
The code picks six object - each one of them contains two numbers. Then it eliminates one of the objects, and then eliminates another one from the remaining five, leaving only four of them at the end.
I have an array containing thirty nine rounds containing six objects and the result which one got deleted first and which one got deleted second. The 40th row contains only objects' values, and we need to find a pattern and assume which two objects will be deleted in the 40th round.
Here's the link to the array in PDF
and in Excel format
Is that even possible? Any idea on how to get started is ultra valuable.
Thank you for your time.
Related
I am trying to count only completed components in a manufacturing shift report.
Example:
I have 6 components (each having three parts) in column A represented by array constant {1,2,3,4,5,6} (in other words this column repeats three times per component - 1,1,1,2,2,2,3,3,3,4,4,4,5,5,5,6,6,6)
I have three parts per component in column B represented by array constant {"a","b","c"}. (in other words component 1 has an "a" part on one line, a "b" part on the next line and a "c" part on the third line in the shift print report.
I also have a status/ critera comment in column C represented by "Complete"
My formula trying to count only completed components (each having it's three parts) is:
{=sum(countifs(A:A,{1,2,3,4,5,6},B:B,{"a","b","b"},C:C,"Complete"))}
THIS HOWEVER ONLY WORKS FOR THE FIRST THREE COMPONENTS, i.e. NOT 4,5,6.
Please help with this as my full application would be up to a hundred components each shift each with three parts that I must report as ready for despatch only when column C is "Complete".
I am doing this manually at this time which is massively numbing work.
An alternative formula I tried but which only works if A:A has one value:
{=sum(if((A:A={1,2,3,4,5,6})*(B:B={"a","b","c"}),1,0))}
I am totally confounded by this one - awesomely braintwisted!
I tried looking for resources on mismatched array constants, which I thought relevant in this case but do not understand how to proceed (anyway).
Please can some one show me the light!
Thanks,
Stu
Try transposing one (but not both) of your array constants so that it is orthogonal to the other, i.e. either:
=SUM(COUNTIFS(A:A,{1,2,3,4,5,6},B:B,{"a";"b";"c"},C:C,"Complete"))
or:
=SUM(COUNTIFS(A:A,{1;2;3;4;5;6},B:B,{"a","b","c"},C:C,"Complete"))
Note that these constructions do not require committing as array formulas, i.e. with CSE.
If you're interested in an explanation as to this required syntax, see here:
http://excelxor.com/2014/09/28/countifs-multiple-or-criteria-for-one-or-two-criteria_ranges/
Regards
I've got a spreadsheet that, for goofy reasons, has two columns next to each other in each of which is a series of dates, separated by ctrl-rtn linefeeds. They amount to a list of start/stop periods. There are reasons it's done this way, and will probably continue to be (I am open to other suggestions).
Given this structure, I'd like to be able to pull out the periods and/or period lengths. That is, given:
1/1/2015 1/3/15
1/15/15 1/20/15
2/3/15 2/7/15
(in only two adjacent cells) I'd like to be able to pull out at least:
2
5
4
and perhaps optionally break it up into six different cells (note that the lists will be variable lengths). This is much less important.
I am having a hard time figuring out how to even approach this. If I was in VBA I could regex it easy-peasy. I'm utterly new to Spreadsheet Scripts. Thanks so much for any help.
You should be able to split each cell (say A1) into three with:
=split(substitute(A1,char(10),","),",")
Repeat for the next (say A2), format as dates and in B3 and copied across to the right to suit:
=B2-B1
I have n arrays of data, each of these arrays is sorted by the same criteria.
The number of arrays will, in almost all cases, not exceed 10, so it is a relatively small number. In each array, however, can be a large number of objects, that should be treated as infinite for the algorithm I am looking for.
I now want to treat these arrays as if they are one array. However, I do need a way, to retrieve objects in a given range as fast as possible and without touching all objects before the range and/or all objects after the range. Therefore it is not an option to iterate over all objects and store them in one single array. Fetches with low start values are also more likely than fetches with a high start value. So e.g. fetching objects [20,40) is much more likely than fetching objects [1000,1020), but it could happen.
The range itself will be pretty small, around 20 objects, or can be increased, if relevant for the performance, as long as this does not hit the limits of memory. So I would guess a couple of hundred objects would be fine as well.
Example:
3 arrays, each containing a couple of thousand entires. I now want to get the overall objects in the range [60, 80) without touching either the upper 60 objects in each set nor all the objets that are after object 80 in the array.
I am thinking about some sort of combined, modified binary search. My current idea is something like the following (note, that this is not fully thought through yet, it is just an idea):
get object 60 of each array - the beginning of the range can not be after that, as every single array would already meet the requirements
use these objects as the maximum value for the binary search in every array
from one of the arrays, get the centered object (e.g. 30)
with a binary search in all the other arrays, try to find the object in each array, that would be before, but as close as possible to the picked object.
we now have 3 objects, e.g. object 15, 10 and 20. The sum of these objects would be 45. So there are 42 objects in front, which is more than the beginning of the range we are looking for (30). We continue our binary search in the remaining left half of one of the arrays
if we instead get a value where the sum is smaller than the beginning of the range we are looking for, we continue our search on the right.
at some point we will hit object 30. From there on, we can simply add the objects from each array, one by one, with an insertion sort until we hit the range length.
My questions are:
Is there any name for this kind of algorithm I described here?
Are there other algorithms or ideas for this problem, that might be better suited for this issue?
Thans in advance for any idea or help!
People usually call this problem something like "selection in the union of multiple sorted arrays". One of the questions in the sidebar is about the special case of two sorted arrays, and this question is about the general case. Several comparison-based approaches appear in the combined answers; they more or less have to determine where the lower endpoint in each individual array is. Your binary search answer is one of the better approaches; there's an asymptotically faster algorithm due to Frederickson and Johnson, but it's complicated and not obviously an improvement for small ranks.
I'm trying to apply only the minimal number of changes when table's data is updated (it's an iOS app and table view is the UITableView of course, but I don't think it's relevant here). Those changes include adding new items, removing old ones and also moving some existing ones to a different position without updating their content. I know there are similar questions on SO, but most of them only take the adds and removes into account and existing ones are either ignored or simply reloaded.
Mostly the moves involve not more than a few existing elements and the table can have up to 500 elements.
Items in the arrays are unique.
I can easily get added items by subtracting the set of items in new array from the set of items in the old array. And the opposite operation will yield a set of deleted items.
So the problem comes down to finding the minimal differences between two arrays having the same elements.
[one, two, three, four]
[one, three, four, two]
Diffing those arrays should result in just a move from index 1 to 3.
The algorithm doesn't know if there's only one such move. Just as well the change can be:
[one, two, three, four, five]
[one, four, five, three, two]
Which should result in moving index 1 to 4 and 2 to 3, not moving 3 and 4 two indexes to the left, because that could result in moving 300 items, when in fact the change should be much simpler. In terms of applying the visual change to the view, that is. That may require recalculating cell heights or performing lots of animations and other related operations. I would like to avoid them. As an example - marking an item as favorite that causes moving the item to top of the list or 300 items takes about 400 milliseconds. That's because with the algorithm I'm using currently, e.g. 100 items are moved one index up, one moved to index 0, 199 other are left untouched. If I unmark it, one item is moved 100 indices down and that's great, but that is the perfect, but a very rare, case.
I have tried finding item's index in old array, checking if it changed in the new array. If there were a change I moved the item from new index to old one, recorded the opposite change and compared arrays until there're equal in terms of element order. But that sometimes results in moving the huge chunks of items that actually were not changed, depending on those items' position.
So the question is: what can I do?
Any ideas or pointers? Maybe a modified Levenshtein distance algorithm? Could the unmodified one work for that? I'll probably have to implement it in one form or another if so.
Rubber duck talked:
Thinking about finding all unchanged sequences of items and moving around all the other items. Could it be the right direction?
I have an idea, don't know if it would work.. Just my two cents. How about if you would implement an algorithm similar to the longest common subsequences on your array items.
The idea would be to find large "substrings" of data that have kept the initial sequence, the largest ones first. Once you've covered a certain threshold percent of items in 'long sequences' apply a more trivial algorithm for solving the remaining problems.
Sorry for being rather vague, it's just meant to be a sugestion. Hope you solve your problem.
I am trying to divide arrays recursively... I think that is what this would be called haha....
For instance, lets say the initial array contains 50 values the highest being 97 and the lowest being 7... I want to split this array into two, dividing them based on whether they are greater or lower than the midrange of the entire set. The midrange being 52...( (97+7)/2 )
Then I want to divide these two arrays using the same method and so on, ideally having a program that repeat this process an arbitrary number of times....
Load Values into array1
Find Midrange
For every value in array1{
if value > midrange{
assign value to ArrayHigh1}
Else{ assign value to ArrayLow1}
}
Perform same thing on ArrayHigh1 and ArrayHigh2
Etc etc etc.
I'm having trouble figuring out how I would create the successive arrays (ArrayHigh2 3 4 etc)
Also, I feel like there must be an easier way to do this, but I cannot think of one at the moment...
Thanks for the help
You seem to be working your way towards a B-tree or an implementation of Merge- or Quicksort. Plenty of reference implementations are available online.
Though speaking generally, you might benefit greatly from reading a book many here are familiar with.