The tag has no usage guidance.

learn more… | top users | synonyms

-3
votes
0answers
43 views

Longer version of sort array [on hold]

I have an array of structs. struct Item { let textLabel : NSDate let detailTextLabel : NSDate } I sorted them with the following code: myArray.sort{$0.textLabel.compare($1.textLabel) == ...
-2
votes
0answers
20 views

Stripping one set of arrays and replacing quotes [on hold]

How could I take: s = [[0,0,0,0],[0,0,0,1]] and change it to: s = ["0,0,0,0","0,0,0,1"] Don't really mind how elegant it is.
-3
votes
0answers
21 views

Mixing then printing arrays, but they all end up the same anyways? [migrated]

I'm making a sudoku game. I have an array (puzzle[][][]) containing nine other arrays (zone1[][]-zone9[][]), which each initially contain {{1,2,3},{4,5,6},{7,8,9}} (and they're assigned those values ...
3
votes
2answers
120 views

Is it a good idea to modify the array keys in foreach

First let me say that i am talking about PHP, but the question is a general one. Some times i need to modify an array key for example something like: $temp = array(); foreach($arrayIWantToModify as ...
1
vote
0answers
57 views

Why was Go list iteration designed with the index before the element? [closed]

When iterating over an array or slice in Go you can use the range keyword. for idx, e := range someSlice { } Here, the idx represents the current index and the e the current element in the array. ...
0
votes
0answers
71 views

Using a PHP loop or MySQL table for arrays values

I have the following results page from the previous form: <?php //Get the form results (which has been converted to an associative array) from the $_POST super global $musicgenres = ...
0
votes
0answers
27 views

Is it better to store integer data or array references in a javascript visualization?

Say I have a tree that I'd like to visualize with d3. Nodes have various attributes produced by the d3 library, attributes like an index and position variables. Now, I could add more attributes to ...
0
votes
0answers
24 views

Microcontroller oLED Display Buffering Optimizations or Alternatives For Speed?

I'm developing a UI/Layout for a 128 x 64 oLED Monochrome Pixel Display. I've got a small netMF microcontroller driving the display via SPI at 40mhz. I'm using some basic methods, like these here, to ...
-3
votes
0answers
13 views

Sand 3D Printer Slicing Issue [migrated]

For my doctoral thesis I am building a 3D printer based loosely off of one from the University of Twente: http://pwdr.github.io/ So far, everything has gone relatively smoothly. The hardware part ...
1
vote
0answers
225 views

Why is deep plucking a bad idea?

Both underscore and lodash refuse to implement deep plucking, despite many requests from users and gists or modules that implement the feature. ...
2
votes
1answer
104 views

sort multidimensional array recursively - is this reasonable

In a nutshell, I needed to traverse any number of dimensions of a multidimensional array (or not) and I wanted the process to be as predictable as possible (in order to proliferate the pattern ...
3
votes
2answers
58 views

Reducing a sequence of array modification operations (insert, sort, replace, remove)

Given a plain array of values, e.g. ["Apple", "Orange", "Banana", "Strawberry"] and a list of operations from the set of [insert, delete, sort and replace], e.g. [ {cmd: "insert", index: 2, ...
12
votes
1answer
362 views

Why using sizeof of type to calculate the number of elements in an array is considered inferior to using sizeof of an element?

I'm reading "King K.N's C programming" and I'm reading the following statement: We discussed using the expression sizeof(a)/sizeof(a[0]) to calculate the number of elements in an array. The ...
0
votes
1answer
110 views

Normalizing a numpy array

I checked a while back for questions relevant to my own about normalizing numpy arrays but couldn't find any. So I'll pose my question following this line of code: for i in ...
2
votes
2answers
58 views

How to create a 2D array at runtime in Ada? [closed]

In Ada programming, What is a best practice way to create a 2D array of a size that is specified by the user? I'm teaching myself Ada for work (after many years of C programming), and I'm having ...
2
votes
2answers
118 views

Find the maximum number of pairs of numbers that are in a range, between two arrays

Lets say I have two arrays A and B A = {1,2,3} B = {12,11,67} and have max sum value S = 10 How many maximum number of unique pairs can be formed between the two arrays who's sum is less than or ...
2
votes
1answer
136 views

Beginners C# question about Array.Reverse

I am sitting through a very well-explained and thorough video tutorial series, using Visual Studio 2012 as my developing environment. Anyway, one thing that is hard to figure out is this. Say you ...
1
vote
2answers
157 views

What is the algorithmic time complexity of this program?

I wrote a simple program in java to create and maintain Dynamic Arrays: public class DynamicArrays { private Integer[] input = new Integer[1]; private Integer length = 0; private Integer ...
3
votes
1answer
313 views

Why is iterating through List<T> more expensive than iterating through Array in .NET?

According to the answers in this post, List<T> is backed by an Array. According to this article, list iteration is considerably slower than array iteration. If Lists are arrays 'under the ...
0
votes
0answers
68 views

GMP Core Dump while using mpz_clear in C

I'm working on a prime factorization program written in C using the GMP library through cygwin. The algorithm that I have now works fine, but has memory leaks from not using the mpz_clear function on ...
0
votes
1answer
107 views

Split multiple overlapping intervals to non overlapping intervals

currently I try to build an algorithm to split an array of overlapping intervals to a new array with non overlapping intervals. For example: Array of overlapping intervals: [ {0,7}, {8,12}, ...
1
vote
1answer
96 views

What is VLA and how it is implemented?

Most languages does support variable length arrays on the heap but I've heard that those can be stored on the stack too. I'm curios what languages support this construct, some examples and how are ...
1
vote
0answers
178 views

How to loop through array bidimensional in diagonal according to a position in degrees

The title could be no self-explanatory enough but I need some conceptual help in order to implement a solution to go through an array: I'm developing a program to calculate the "most shadepath" route ...
1
vote
1answer
147 views

Non-fixed-size Fenwick Tree implementation

I'm planning to implement a non-fixed-size Fenwick tree. That is, a Fenwick tree that allows interleaving range queries with adding/removing elements. All implementations and samples I've seen so far ...
3
votes
2answers
262 views

How to draw rectangles for 2D arrays

I have an 2D boolean array that looks like this: [0][0][0][0][0][0][0][0][0][0] [0][0][0][0][0][0][0][0][0][0] [0][0][0][0][0][0][0][0][0][0] [0][0][0][1][1][1][0][0][0][0] ...
0
votes
1answer
77 views

Why use atomic vectors or matrices in R at all?

In reading Hadley Wickham's Advanced R I learned about the difference between atomic vectors and lists; and matrices/arrays and dataframes. This is something I hadn't really appreciated before, and ...
-2
votes
3answers
549 views

How to store integer array in mysql database [closed]

I am making a college attendence system so i need to store attendence of thousands of students. if I go for 1 column for each day then it will take 12*30 almost 360 column for a year. So I want to ...
3
votes
3answers
297 views

How do you iterate through an array and delete an element?

I have an array and I can iterate through it. I know that it is impossible to change the size of an array; however, how do I take out a certain element that I not want in the array anymore? Example: ...
1
vote
2answers
52 views

Function that would output all distinct values in an array

I want to create a function that outputs the distinct values in a given array. For example, in the following sequence 2 2 1 1 5 2 , the distinct digits are 2 1 5. What I've done till now is: void ...
1
vote
3answers
193 views

Addition or deletion of elements of a dynamic array

Is there any consensus among programmers (or a common convention) on the "right way" to deal with the addition or deletion of one or more elements of a dynamic (mutable) array at runtime while ...
1
vote
1answer
38 views

Expectations on input / output of array dimensions and approaches to implement support for variable dimensions input arrays

Preamble As we are vectorising our colour API, we are changing the accepted input types for most of our functions. We would be keen on keeping backward compatibility with the existing code. Let's ...
0
votes
1answer
53 views

Two dimensional matrix-like data type using lists and/or mutable lists

I am trying to think of an implementation of a two dimensional matrix-like data type. Normally I would take an array of arrays but I'm bound to a relatively low language level which only provides ...
1
vote
0answers
110 views

Should I use enums or arrays for a dynamic data source?

I've inherited an iOS project that uses NS_Enum to store the number of rows and sections in a UITableView At the moment, the UITableView is static; no rows are being added to it. However, that is what ...
0
votes
2answers
248 views

Check all “lines” in an array?

I have a 3D array with booleans and I need to check if there are "lines" that all contain true or false. With lines I mean horizontally, vertically and diagonally within the array. However I only need ...
-3
votes
1answer
43 views

How can this allocation of bi-dimensional arrays work?

I was seeing this post on StackOverflow and saw a new way (at least for me) to define a two dimensional array of 5x5, it works well, but I feel I don't understand what is going on in the background. ...
1
vote
3answers
144 views

Question about multidimensional arrays

I was wondering something about the multidimensional arrays and then I got a doubt about a concept, specifically about their representation on memory. For example, an array can be defined as follows. ...
1
vote
1answer
72 views

Is it possible to quickly change an array declared on the stack to one declared on the heap

I have about 5000 lines of code which manipulates a large array in C++. The problem is that when I try to make the array even larger i.e. A[10000][10000], the gcc compiler throws me a segmentation ...
0
votes
3answers
548 views

Using action array vs Switch Case [closed]

I have an occasion of code in which I will draw a different set of buttons in a screen (depending on the number of the buttons). One thought (and my current implementation) is to use an action array ...
3
votes
1answer
94 views

Conveniently sorting and (binary?) searching an array of pairs of numbers?

So I have an array of distinct pairs of positive integers. That is, my array looks something like this (for instance): { (1,5) , (6,4), (5,3), (2,3), (2,4) } And my task is, for a given pair (a,b) ...
0
votes
1answer
264 views

Big O notation allocate array of N element

In Big O notation, allocate an array of N element is defined by O(1) or O(n) ? For example in C#, if I allocate an array like this : int[] a = new int[10] When I display this array, I have : ...
0
votes
1answer
34 views

String splits to create arrays

Creating an array of strings for configuration or verification purposes can get long and ugly in code. For example: arrayOfStrings = ['one','two','three','four'] Often to reduce the characters and ...
1
vote
3answers
154 views

memory management of multi-dimensional array

Could you please show me an example how to compute the location of an element in a multi-dimensional array. It is illustrated in Robert Sebesta's book Concept of Programming Languages that location ...
0
votes
3answers
170 views

How to do “image shifting” faster?

I have a grayscale matrix (implemented as a simple array) to be shown on a display: line 1: | a | b | c | line 2: | d | e | f | a-f are grayscale values. This pattern has to be shifted by a ...
4
votes
3answers
375 views

@SuppressWarnings in generic array declaration

While doing a coding test, I ran into a problem where I need to initialize an array of generic type in Java. While trying to figure out how to do that, I looked at this Stack Overflow question and it ...
1
vote
2answers
2k views

2D linked list vs. multidimensional array/vector

I hope that programmers is the correct stack exchange for this, as it is quite a concept based question. I'm working on a data structure in C++ that is a represents data in 3D space. The x-y plane is ...
39
votes
2answers
5k views

How do I move away from the “for-loop” school of thought?

This is a rather conceptual question, but I was hoping I could get some good advice on this. A lot of the programming I do is with (NumPy) arrays; I often have to match items in two or more arrays ...
-1
votes
2answers
216 views

Estimation of space is required to store 275305224 of 5x5 MagicSquares? [closed]

Here are some examples of 5x5 Magic Squares found by some good solvers : Magic Square Generator by Marcel Roos this program state using 2.4GHz Intel takes about 95 hours to generate all solutions. ...
0
votes
3answers
262 views

Why is the complexity of fetching a value from an array be O(1)?

How come the complexity of fetching a value from an array by it's index is O(1)? I thought the algorithm has to go through all the indexes, find the correct index, and then know what value to return. ...
1
vote
2answers
801 views

Why a hashtable? Why not just a non-hashed associative array?

I've been learning about using a hashtable to efficiently check for items in a list without looping through the whole thing, but there's one thing that I don't get: Why hashed keys? It seems like: ...
0
votes
1answer
165 views

Why is first column of list called 0th in so many languages? [duplicate]

If you want first element of list or array you reference it as 0 in many languages (like C or Clojure). Is there are some really good reasons why the programming languages was design this way? In ...