arrays

Help with object from mouse algorithm

I wasn't sure what to call this. I'm building a tile based game where the user can click on a tile. it is a 2d c++ vector of tiles. right now I have an algorithm that positions them like this: [][][][][][][][][][][] [][][][][][][][][][][] [][][][][][][][][][][] [][][][][][][][][][][] [][][][][][][][][][][] [][][][][][][][][][][] they ...

haml syntax - nesting partial properties

what i want is a way of nesting partial properties, this seems a tad long winded: = partial('frames/tabs_a', :locals => {:tabs_title => 'semi-dynamic-tabs', :tabs_id => 'p001', :panel_a => 'views/article-highlights_a', :a_id => 'p_002_0', :a_ft => '123 More in highlights', :a_tt => 'panel a', :a_c => 'magazine', :panel_b...

how to assign random energy E to every node and compare two nodes for maximum energy and also find distance between them?

As helped by gnovice I got following code, but now I want to assign energy (randomly) to every nodes using E=floor(rand(1)*10) and also want to compare for maximum energy and what is distance between them? N=input('no. of nodes : '); %# Number of nodes coords = num2cell(rand(N,2)) %# Cell array of random x and y coordin...

jQuery iterate over object with $.each

I have an object options: options = {title : 'title1', name : 'name1', url : 'url1', etc.} which is passed in as a parameter to a function. I'm trying to iterate over that object, pass it through another function evaluate, and store the result in another object opts, like so: var opts = new Object(); $.each(options, function(key,valu...

shuffle Objects php

how can i sort object in php? i tryed shuffle but that expects an array Warning: shuffle() expects parameter 1 to be array, object given in /var/www/index.php on line 366 Warning: Invalid argument supplied for foreach() in /var/www/index.php on line 334 here is the code public function updateStatusWithoutDB() { $this->upda...

sizeof array of structs in C?

In C I have an array of structs defined like: struct D { char *a; char *b; char *c; }; static struct D a[] = { { "1a", "1b", "1c" }, { "2a", "2b", "2c" } }; I would like to determine the number of elements in the array, but sizeof(a) returns an incorrect resu...

More efficient access to an multi-dim array

I'm trying to nicely output a data array (with Kohana v2.3.4), and am thinking there has to be a more efficient and elegant way to do this. My array looks like this: array('category_id' => value, 'category_title' => value, 'posts' => array( 'id' => value, 'title' => value, ... )) And here's how I'm outputting it in my view (some arr...

Extracting the index of an Xcode array

The following line works fine in the NSLog: NSLog(@"Selected Number: %@. Index of selected number: %i", [arrayNo objectAtIndex:row], row); but I would like to make the index assigned to an integer variable: int num = ([arrayNo objectAtIndex:row], row); the line above produces an error. What I am doing wrong? ...

Populate ruby Array1 with Array2 String element if and only if Array2 element matches Hash value(not key).

I have a ruby hash: VALS = { :one => "One", :two => "Two" } and an Array: array2 = ["hello", "world", "One"] Question: How can I populate a new array1 so that it only pulls in any values in array2 that match exactly the values in VALS? For example, I have tried: array2.each_with_index do |e,i| array1 << e if VALS[i] ~= e end Alon...

Ruby Array Intersection, Hash.has_value? for intersection with array[i+1] based on hash values

I am trying to populate an array with an intersection of an array and hash based on hash values: array2 = ["hi","world","One"] Vals = {:one => "One", :two => "Two"} array2 = VALS.values & array2 print array2 Works fine for intersection of hash values and array2[ i ], but if I want to instead populate with array2[ i+1 ] element from ar...

Using boost::bind output as an array subscript.

How do I get boost::bind to work with array subscripts? Here's what I'm trying to achieve. Please advice. [servenail: C++Progs]$ g++ -v Reading specs from /usr/lib/gcc/i386-redhat-linux/3.4.6/specs Configured with: ../configure --prefix=/usr --mandir=/usr/share/man --infodir=/usr /share/info --enable-shared --enable-threads=posix --di...

how to insert multiple array into database using PHP

I need help. What seems to be the problem with our php codes? We can't seem to insert our data into our database. I'm just a beginner and I'm tasked to store multiple data into multiple arrays into our database. What we're actually doing is to enter a number (ex: 5) and 5 forms should show within that page. each form would consist of nam...

PHP - How to use arrays for form input and update respective database records

I'm new to PHP... I want to know how to populate a form from mySQL. I'm stumped at the input section where I am trying to allow the user to select choices for radio button /checkbox for each record. thanks in advance for anyone's help! TC Here's a snippet of my code: <?php $mQuantity = 1; $con = mysql_connect("localhost","t","c");...

regex on an array to rename keys

Hay all, i have an array Array ([near_prescription] => Array ( [go_to] => inter_selection [distance_right_sph] => 0.00 [balance_right] => [distance_right_cyl] => 0.00 [distance_right_axis] => [distance_left_sph] => 0.00 [balance_left] => [distance_left_cyl] => 0.00 [distance_left_axis] => ...

How to change a value in multidimension array in PHP.

I want to change some values in my multidimension array in PHP. Suppose that I have: $photographer[0]['uid'] = '1001'; $photographer[0]['point'] = '0'; $photographer[1]['uid'] = '1002'; $photographer[1]['point'] = '1'; I want to change point of photographer that have uid = '1001' to 3. How can I do it? ...

String problem in PHP

How do I take off a certain character in a string and put them all together in an array like: "{2} in better that {1} when it comes to blah blah blah" and the output would be: array(0 => "2", 1 => "1"); I have used regular expression but it seems like it doesn't loop throughout the string or maybe I'm missing something? Thanks ...

Should I be concerned about .NET dictionary speed?

Hello, I will be creating a project that will use dictionary lookups and inserts quite a bit. Is this something to be concerned about? Also, if I do benchmarking and such and it is really bad, then what is the best way of replacing dictionary with something else? Would using an array with "hashed" keys even be faster? That wouldn't hel...

Flash CS4 [AS3]: Generating an array using a loop.

Below I have an array that works but it is far too long and I am thinking there is a far easier way to generate the same result using a loop but I just can't get my head around it at the moment. The array is as follows: var CardDeck = new Array(); CardDeck[0] = new C1(); CardDeck[1] = new C2(); CardDeck[2] = new C3(); CardDeck[3] = new ...

array vs vector vs list

I am maintaining a fixed-length table of 10 entries. Each item is a structure of like 4 fields. There will be insert, update and delete operations, specified by numeric position. I am wondering which is the best data structure to use to maintain this table of information: array - insert/delete takes linear time due to shifting; update ...

How do i sort multidimension array in PHP?

I have array like Array ( [608665839] => Array ( [score] => 2 ) [1756044141] => Array ( [score] => 5 ) [523536777] => Array ( [score] => 2 ) ) and I want to sore this array by score. How can I do? ...