An array is an ordered data structure consisting of a collection of elements (values or variables), each identified by one (single dimensional array, or vector) or multiple indexes.

learn more… | top users | synonyms

4
votes
0answers
40 views

Simple sparse array

Today, I tried to create a really simple sparse_array container adapter. I did not provide all the STL-like functions, only the elementary ones as a proof of concept. I also trimmed the class from its ...
2
votes
1answer
33 views

Create object-properties from an array

I'm writing a simple table-oriented storage for objects. The schema of a table is stored in the columns-array and the data in the rows-array. // example: table "employees" var columns = ["id", ...
4
votes
1answer
37 views

Multidimentional array initialization

I am initializing a PHP array as follows $newArray = array(); $newArray['2014-13-03']['SMD']['IMPR'] = 5; $newArray['2014-13-03']['SMD']['CLICK'] = 10; I just wanted to check if you think this is a ...
8
votes
3answers
262 views

Writing a function to add or modify an existing object inside an array

I have an array of objects. Each object has two properties, id and quantity. I wrote a function to add an object to the array. But the function must check if the object already exists within the ...
5
votes
1answer
59 views

Optimize Cython code with np.ndarray contained

Can someone help me further optimize the following Cython code snippets? Specifically, a and b are np.ndarray with int value (range(256)) in them. They are one dimension arrays with dynamic length. ...
6
votes
1answer
59 views

Generate permutations with symbols

Goal: Create a combination of emails based from inputted first name, last name, middle name, and a domain. Add in common separators. Then I'll check which one is correct with the rapportive API. This ...
0
votes
0answers
22 views

Checking login from associative array vulnerabilities

For a very simple databaseless website, I'm using an associative array to store logins like this: $logins = array( 'user' => 'password', 'user2' => 'password2', ); I check login attemps using ...
-1
votes
0answers
17 views

How to generate an array/list from an output using .split()? [closed]

I just started picking up Python (2.X) and here I'm trying to "isolate" useful data set from a file so that I can do calculation. I get to print out lines of data (numbers) by splitting the ...
2
votes
2answers
67 views

How to get the Split value from collection?

I have the following key value pair in an array, and am trying to extract and load them into a collection. The below code is working but it can be optimized using Linq: string _data = ...
2
votes
2answers
50 views

Is there a better way to combine these arrays?

Is there a better way to do this kind of array combination with a PHP native function like array_combine? I'm trying to improve my skills, and at certain points I note that I am using too many nested ...
10
votes
3answers
1k views

Reverse a String in Java

Here is the code for the CString class that I created. public class CString { public String reverse(String s) { char[] array = new char[s.length()]; array = s.toCharArray(); ...
2
votes
1answer
56 views

Computing sum and counting matches in an array

The problem was pretty straightforward and used two simple algorithms from our examples; the one for computing the sum, and the one for counting matches. The array for the problem wasn't provided, but ...
1
vote
2answers
51 views

Same function but use different array data

I have these two carousels that randomly pick up pictures. [fiddle] Each of them picks up pictures and links from their own different inner array. It works fine as it is, but I was just wondering if ...
6
votes
2answers
64 views

Return index of array where sum first passes n

I have an array of integers and a number n. I want to sum the elements of the array and return the index where the sum passes n, as efficiently as possible. For example, assume: theString = ...
3
votes
1answer
34 views

Display PHP Menu Stored in an Array and Looped

I'm creating a PHP website for a non-profit. They have some restrictions (no MySQL or pre-installed CMS) so I'm creating a CSS menu displayed by an unordered list where all of the elements are stored ...
0
votes
2answers
28 views

Trying to convert an extended Array.prototype to a function

I got a random image rotator working by using the following script (demo). But I was told that it is a bad practice to extend Array.prototype. And it does. It conflicts with the chained select box ...
3
votes
2answers
54 views

Returning all the LIS of given array of int

I have this assignment where I'm supposed to code an algorithm for finding the quantity of Longest Increasing Subsequences from an array of (different) integers and print them all. I developed one ...
10
votes
2answers
96 views

Improve performance of math function applied to arrays

This block of code is already somewhat optimized thanks to some answers given over at Stack Overflow. In the last question I made (Improve performance of function without parallelization) the code was ...
8
votes
1answer
108 views

Faster way to find maximum deviation?

So, it was a part of my coding challenge and the last one, but I failed because it failed to yield a result in two seconds for some of sample inputs (out of six samples, three passed but three failed ...
4
votes
1answer
48 views

Writting day_of_month and month_day with pointers instead of array indexing

Rewrite the routines day_of_year and month_day with pointers instead of indexing. The exercise is quite simple, this is the solution: int day_of_year(unsigned int year, int month, int day) { ...
1
vote
2answers
110 views

Print the elements of an array into a table

I am trying to print the elements of an array into a table, but I'm having trouble formatting the array elements itself. Perhaps there is a better solution than what I'm currently using? import ...
6
votes
1answer
47 views

Optimize YUV channel splitting function

The input pointer *data contains the data that needs to be split into different arrays and put in yuvInput. Each pixel is 32 bytes 4 * 8. Note the (j*4) to break it up per pixel segment. The 4th ...
6
votes
2answers
364 views

Read an input text file and store the tokens in 2 different arrays

I am very new to Java so please ignore if there are obvious mistakes. If my question seems redundant then please guide me towards the correct link. However, I have surfed enough in order to find the ...
10
votes
3answers
107 views

Displaying random quotes from an array

Is there anything that I could have done better in this code? <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>Quotes</title> <style> body { ...
1
vote
1answer
52 views

Problem comparing list to an array [closed]

I am attempting to compare an array to a list. The list contains 4 items that should be repeated in the array and in the same order. Previously all I had to do is make sure that each of the array ...
7
votes
2answers
548 views

Fastest way to cut an array into two arrays at a particular index

Suppose I have the array: double[] arrayToCut = new double[100]; for(int i = 0 ; i < 100 ; ++i) { arrayToCut[i] = Math.random(); } My objective is to end up with two arrays, firstArray and ...
4
votes
1answer
32 views

Simplifying an associative array()

Would it be better to convert the array in the following code to $langs = array("en", "de", "fr"); and then reusing the values for both $folder and $flag? If so, how then would my foreach (or maybe ...
8
votes
2answers
157 views

Rotating array members

I had a situation when I needed to move all array elements in circular fashion. When I say this, I mean: 0 1 2 3 1 2 3 0 2 3 0 1 3 0 1 2 So the array: var players = ...
4
votes
1answer
60 views

How to make this lingo game more compact?

I made a lingo game using Python: You guess a word, and if its letter(s) is in the same spot as a hidden word's, you add [] around the letter. If it's in the hidden word, but not in the same spot, ...
1
vote
3answers
71 views

Complex data structure organization in javascript?

Upon suggestion in the original question within stackoverflow, I'm bringing this question here. Question Explained: In a website that I built, I used complex multidimensional arrays to organize a ...
5
votes
1answer
47 views

Backbone collection filter

I've got this Collection in my Backbone application: var AnswersCollection = Backbone.Collection.extend({ model: Answer, initialize: function() { console.log('Hello from new answers ...
1
vote
1answer
34 views

Converting List to Array when list has quotes and embedded comma

This function converts List to Array when list has quotes and embedded comma array function convertRow(required string lstRow) { var arResult = []; var arTemp = ListToArray(arguments.lstRow, ...
3
votes
2answers
100 views

Array manipulation exercise

While trying to learn more about arrays in C, I tried to write some code that did the following: Read a stream of numbers from the stdin and store them in an array Print the array in the order the ...
-3
votes
1answer
59 views

Create arraylist on driver class [closed]

I don't quite understand what I'm doing and what I'm doing wrong. Please help me to fix/finalize my code. I am supposed to create at least 3 Student objects with input data of your choice to ...
17
votes
6answers
3k views

Guessing a unique 4 random digits number

I've created a simple game, in which the user needs to guess 4 digits number between 0-9, generated randomly using Random() Each of the 4 digits are different from each other, with no repeated digits. ...
5
votes
2answers
139 views

Elegant way to split an NSArray into NSDictionary of array

I need to split one NSArray into NSDictionary. Every key in NSDictionary will contain an NSArray with the object with the same value. i.e. I have an array with 1000 customers and I want create an ...
3
votes
4answers
186 views

Median of two sorted equal sized arrays on combination

The comprehensive description of the problem can be found here. I'm looking for code review, clever optimizations, adherence to best practices. etc. This code is also a correction of code previously ...
0
votes
1answer
86 views

Find the mean of the medians of two equal sized sorted arrays [closed]

A corrected solution is found here Looking for code review, clever optimizations, adherence to best practices. etc. As an example: a1[1, 3, 5, 7] a2[2, 4, 6, 8] The median for each array is the ...
1
vote
1answer
58 views

Grouping a CSV by column

I've started writing a small CSV parser class as I needed a method to group a CSV file by a given column. class CSVParser { private $FileName; private $FileHandle; private $HasHeaderRow ...
5
votes
1answer
89 views

Performance of Large BigInteger square root and cube root functions, and excessively large array

This is a continuation of this: Performance of BigInteger square root and cube root functions in Java I've made most of the changes suggested, but since I'm loading literally the largest array ...
2
votes
1answer
22 views

Handling objects and arrays simply in this tagging library

I have written this little tagging module to make it easier to generate small html snippets on the fly. The examples below show how this make things a bit easier. My question is about the handling of ...
4
votes
2answers
67 views

Processing array of objects into two strings

I have an array of Item objects that each have a string particular and a numeric amount. I want to put all particulars (separated by newlines) into a single string and the same for all amounts. ...
10
votes
2answers
167 views

Best way to handle elements of a private array

This feels like a simple question, but I'm wondering what the best way would be to manage the elements of a private, fixed-size array. Context: I'm making a simple particle engine, and my Emitter ...
0
votes
1answer
143 views

how many alternative ways are there, and how much better are they to transform this array?

These arrays are the result of Store Procedure. They are to build a Google Chart, therefore I need transform the array to a specific format. I also want to remove the $col and $row elements that ...
10
votes
2answers
863 views

Word count program in Java

I am trying to write clean code in Java for reading text of any size and printing the word count in ascending order without using Java collection framework. For example, given the following input ...
2
votes
1answer
34 views

Painting Tom Sawyer's Fence - programming on Free Pascal

Tom Sawyer has many friends who paints his fence. Each friend painted contiguous part of the fence. Some planks could stay unpainted, some could be painted several times. Program must output the ...
4
votes
2answers
340 views

Fastest way to iterate over Numpy array

I wrote a function to calculate the gamma coefficient of a clustering. The bottleneck is the comparison of values from dist_withing to dist_between. To speed this up, I tried to adapt and compile it ...
6
votes
1answer
356 views

A boolean expression parser, written in Java

I was trying to write some of the Haskell list functions into Java, and I realized that one of the key strengths for many of the functions was the ability to pass in a boolean expression. I decided to ...
0
votes
1answer
54 views

How to put a lot of information in the class?

I have such a problem: I'm parsing a lot of HTML files with Simple HTML DOM Parser, that's why I need to use three foreachs to parse the necessary information from it -> I am getting a lot of ...
5
votes
1answer
86 views

Optimising Funny Marbles

Problem statement is at http://www.codechef.com/DEC13/problems/MARBLEGF Lira is given array A, which contains elements between 1000 and 2000. Three types of queries can be performed on this ...