I have a working app that needs to store up to 4 matrixes of integer data per record. I'm not sure how to get there with Titanium and SQlite.
A record will contain at least 1 but up to 4 matrixes of integers:
The matrix size is variable, each matrix consists of:
1 - 20 rows with 3 columns per row
OR
1 - 20 rows with 6 columns per row
The matrix structure will be identical for each record, i.e. 3 3x20 matrixes in
a record or 4 6x10 matrixes in a record. At this point my app starts, allows the user to choose the matrix parameters then accepts the data entry to fill in the matrix values. The matrixes are actually an JS array of arrays. How can I store an array of arrays and read it back in when I need to?
Edit: Let me see if I can clarify...
The app I'm working on is a scorecard for archery tournaments, similar in concept to a scorecard in golf. In archery you shoot for a set number of ends with a set number of arrows shot per end. The app asks for the number of ends (up to 20) and the number of arrows shot per end (3 or 6). After each shot the archer enters the score (an integer value). so for argument's sake say we're scoring for three ends with three arrows per end. We might see something like this:
arrow scores
8 8 9 (end 1)
7 9 10 (end 2)
9 9 10 (end 3)
There's my matrix that I need to save for this individual record. However, the next tournament I need to score may have a different number of ends and arrows:
arrow scores
7 8 9 10 10 10 (end 1)
10 9 9 7 8 10 (end 2)
9 6 6 6 9 9 (end 3)
7 8 6 7 8 8 (end 4)
10 10 9 8 8 8 (end 5)
Let's simplify and say that I want to store the scorecard for one archer per record. I already have my data entry and score tabulation working. I just don't understand the best way to store matrices as illustrated above.
I would recommend against storing an array of arrays. Generally speaking, its not terribly efficient to write abstractions with code that are meaningful for reasoning about matrices when make array of arrays a firm concept. The only exception I've seen is matlab/octave.
I've always found I end up with simpler code when I flatten the data. With a flat array you'll have to manage the indexing yourself. A few helper functions make that simple to reason about.
I'm not given much info to go on, but I'd assume that putting the data into two different tables will make things simpler.
CREATE TABLE mat3x20 (i1j1, i1j2, i1j2 ....
CREATE TABLE mat6x10 (i1j1, i1j2, i1j2 ....
Otherwise you have some weird behavior flag in the data which will make it less obvious what the code is supposed to be doing somewhere in the call stack.
Related
I have the following table in html built with json (there are columns that describe what the numbers are also):
1
2
7
10
11
15
Now from a button i want is when user enters a new row, I want the number to go in its place. E.g. if 4, it should be between 2 and 7. If 14, it should be between 11 and 15.
$('tbody#days > tr:nth-child(' + daynumber-1 + ')').after(new_row_data);
failed to work because the index couldn't be found. It works sometimes if for e.g. I have 3 and 5 and tried to insert 4.
I thought have looping the column top to bottom but i usually have 100-113 rows and I am wondering if there is a practical and efficient way of doing this.
Any tips?
The snippet you posted should work fine. However, this will throw an error if the all days are greater than the input.
For efficiency, you could maintain an array of already inserted days and populate it as more days are being inserted.
Before each insertion, look through the array of days and find a spot for that day and just insert it right away. Code for that will be
$('tbody#days > tr').eq( lowerIndex ).after( new_row_data );
firstly the language Im writing in is node (javascript) but really Im looking for the computer science behind it, and how to actually do it, not just the code.
Basically what I have is a 2,000 x 2,000 two dimensional array (what I mean by that is that every entry in the 2,000 entry long array has its own 2,000 entries). Inside this array I have values 0, 1, 2 3, etc. They are spaced out different, with different rarities as to how common each appears. What I want to do is generate this array based on a key, idc how long the key/seed is, just a reasonable length that can get the job done. I want the same key to generate the same array if its the same key and a different one if its a different key. Basically take a key and generate longer data from it but for no recognizable patterns to appear in this data.
My thoughts on this is to have a key that is a decimal of some sort I multiply against a bunch of constants to get a location in the array, but tbh I really have no Idea where to start. Essentially its like how minecraft takes a seed and turns it into map and the same seed will again generate an identical map.
Any random number generator (RNG) that can be seeded will give the same series of random values for a given seed & should have no determinable pattern. Unfortunately, the default RND for javascript is not seedable; as per this SE post, you will need to write your own or use a someone else's.
Once you have a seedable RNG, for each entry, first get a random value & then convert the random value into the desired output value. There's a number of different ways to do the conversion; if you only have a few, I would do something like this (assumes random_value is between 0 & 1):
if(rand_value <= 70){
output_value = 1;
}
else if(rand_value <= 90){
output_value = 2;
}
else if(rand_value <= 97){
output_value = 3;
}
else {
output_value = 4
}
This gives a 70%, 20%, 7% & 3% to get a 1,2,3 or 4 respectively; adjust the values as needed. Note: if you have many output values you should edit your question to reflect this, as there are cleaner ways to solve this than a giant if else block.
I'm struggling with increasing the speed of my pseudo branch & bound algo & thought a trie structure might be a good fit, but I'm stuck.
The problem (simplified & isolated best I can):
I've got 9 nodes & 3 vehicles. Each vehicle must visit 3 unique nodes. So, I created every possible trip (9 choose 3 = 84) & stuck it in an array. Now, I want to find every combination.
For example, trip 1 could be 111000000. trip 2 would be 000110001 and trip 3 would be 000001110. (84^3 = 592704 combinations).
To find out if they match, I just do a bitwise & and accept the trip combination if the value is 0.
I can't use nested loops since the # of vehicles may change, so I keep track of combinations with a counter that ticks up depth-wise like an odometer (e.g. 0,0,82, 0,0,83, 0,1,0).
I reduce combinations by keeping the following digit greater than the one that just increased (e.g. 11,83,83 goes to 12,13,14 because anything less than a 12 in the 2nd column would be a repeat like 12,1,1 is a duplicate of 1,1,12).
I also perform the bitwise AND check at each change (e.g. if (val[12] & val[13]) > 0 don't bother checking the 71 possibilities in the 3rd column, because the 12 and 13 invalidate the route. This reduces the combinations to 24720.
Since I'm doing depth-first, it's really space efficient (no queue to save), but computationally expensive. What I'd like to do is use a width-first approach to create subsets and minimize the search space. For example, assume the counter was at 11,19,20. Currently, it would check 20 - 83 in the 3rd column before incrementing the 19 to a 20. I would like to compute the AND for 19 - 83 in the 2nd column before moving on. In doing so, I would know all the values that don't work with the 11 in the first column and could use that subarray for the 3rd column (e.g. if (val[11] & val[45]) > 0, don't bother checking 11 & 19 & 45, rather use an array that excludes 45 from the 3rd column.
My idea is to create a trie, where each key is the result of the AND operation with an end key that would be the subarray.
For example:
doc = {
1: {
5: {
end: [8,9,10]
},
7: {
end: [11,14,42]
},
end: [81, 13, 42]
}
}
My problem is I can't for the life of me figure out how to iterate over my data to grow the trie. Or maybe there's a better approach? Any advice or code snippets would be great, and thanks for reading through the wall of text.
I just cannot figure this out, nor find any kind of similar question that makes any sense to me. My problem: I am extracting records from a database and displaying them in multiples of 12 per panel on my web page. I therefore need to know how many panels to display all records, using JavaScript (or possibly JQuery). Example:
records = 27;
panels = records / 12; //(which is 2.25)
Obviously I will need 3 panels to display all 27 records, but how can I get that from the result of 2.25? I've tried also using % instead of / but somehow I'm just not getting it.
records = 27; panels = Math.ceil(records / 12); // 3
Round up.
if result is not fully divisible by 12, then use Math.ceil (2.25) which equals 3
I want to create a Adwords Script which will keep track of Quality Score for specific keywords on a daily basis. The results will be stored in a Google Spreadsheet.
So, what I want is:
the first column to be the Keywords Column (which will not change)
and then each column to have the current date and the keyword's quality score.
This will run on a daily schedule so next day it should write that day's results in a new column:
Keywords___|__Date1___|__Date2__|_DateN_|
samplekey1_|___ 8 ____|___ 9 ___|___9___|
samplekey2_|___ 6 ____|___ 7 ___|___9___|
samplekey3_|___ 8 ____|__ 10 ___|___9___|
samplekeyN_|___ 7 ____|___ 8 ___|___8___|
(the numbers are the quality score of that keyword for the given date)
Is there an easy way to code that script?
What I really need is a way to check if a column is empty and if yes, to write the quality score results of the keyword in that column. Thanks for any help.