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

7
votes
6answers
736 views

Given an array of integers, return all pairs that add up to 100

I was recently given this programming challenge on an interview, and I decided to use javascript to solve it. I did, but I'm not happy with my implementation. I can't help thinking there must be a ...
3
votes
3answers
108 views

Find the missing number in a array

I'm working on a personal project to practice my programming skills and I came to this problem. I tried to create a program that will find the missing number in a array. I'm looking forward to ...
10
votes
3answers
481 views

Coding multiples that equal 100

The objective was to see what numbers can be multiplied to equal 100. Example: 1 x 1 = 1 //no match 5 x 20 = 100 //match The objective (as I'm learning) was ...
4
votes
1answer
39 views

VHDL mux in need of generics

I've built a multiplexer which takes 2 inputs: one array of std_logic_vector and one std_logic_vector to select the correct ...
4
votes
2answers
41 views

Is it ok to add a static method to the IEqualityComparer implementation?

Linq methods like Distinct need IEqualityComparer object. But sometimes I just compares two objects and to create Comparer instance for that is seems redundant. So it would be nice to use static ...
3
votes
1answer
66 views

Using std::array to implement variadic construction of class with list-of-self as subclass

I have a situation with a base class for whom a container of itself is a subclass. So a Block of Item has various ways in which ...
4
votes
3answers
213 views

Initializing a multidimensional with many default values

I need to create a \${n} \times {n}\$ multidimensional array filled with default values. Right now, I'm using this code: ...
3
votes
3answers
66 views

Listing the representations of integer M as a sum of three squares M = x^2 + y^2 + z^2

I am trying a number as the sum of 3 squares. For my particular project I will require a complete list since the next step is to compute nearest neighbors (here). In any case we'd like to find \$ M ...
4
votes
2answers
136 views

Removing numbers from the middle of an array

I have an array like this (make sure you scroll to the right): ...
2
votes
3answers
80 views

Print length of longest sequence of consecutive numbers

Problem H (Longest Natural Successors): Two consecutive integers are natural successors if the second is the successor of the first in the sequence of natural numbers (1 and 2 are natural ...
3
votes
1answer
39 views

Reading numbers from a text file into an array

I work in a project based on C language. I want to read a file that contains two lines of numeric characters. Example 9 8 9 5456 32 2 45 34 98 5 I want to ...
2
votes
1answer
39 views

Better way to manipulate URL/array

Is there a better way to do this using chaining? ...
1
vote
1answer
46 views

How can I check if a sequence is alternating?

I need to write a program that reads a sequence of integers and determines if the sequence is alternating. An alternating sequence is a sequence of numbers in which every number should be greater or ...
2
votes
3answers
115 views

Counting the out-of-order elements of an array

Is there any way to write that C function better so the procedure would spent less time to calculate the results? Assume that the array size is 1.000.000 and all the numbers are greater than 0. ...
5
votes
3answers
163 views

Printing the contents of a string array using pointers

I'm currently studying C and I'm trying to just print the contents of a string array. I'm using pNames to point to the first char pointer and iterating from there. ...
3
votes
3answers
70 views

Iteritems on a slice of a Python list

iteritems on a dict can useful. Occasionally iteritems is useful for a slice of a list and ...
2
votes
1answer
49 views

Form a loop with previous and next

I have a class Edge which looks something like this: class Edge { Edge previous; Edge Next; } I have edges in an ...
3
votes
4answers
145 views

Reversing a string in place without using iteration in C

This is function for reversing a string in C using recursive calls: ...
2
votes
2answers
83 views

Combining two arrays using nested foreach loops

I have the following arrays: ...
14
votes
7answers
1k views

Determining whether two scrambled strings are equivalent

I was able to complete the problem doing it in this manner, but I would assume there has to be an easier way. Sample input: abc, cba Output: ...
3
votes
2answers
206 views

Get missing sequential numbers from array

I have an array like Original = {1, 2, 3, 6, 7, 8, 9, 10, 12}. After removing some elements like Delete = {6, 7} from it, I want ...
5
votes
1answer
88 views

Building navigation structure for multiple users by adding values to multiple arrays at once

I have a multidimensional array with associative values... I want to add some information to multiple arrays at the same time. Doing $array1=$array2=array(... seems ...
1
vote
1answer
47 views

Concatenating 2 array variable names to create a new variable name

I'm developing a room booking system using PHP for a school project. I'm trying to create a variable name by concatenating values from two arrays together. here are the two arrays: ...
12
votes
3answers
498 views

Random permutation of int[] and ArrayList<Integer>

I wrote a simple program using int[] and ArrayList<Integer> which aims to get a random permutation output between 1 to 10, ...
4
votes
3answers
299 views

Checking two arrays for matches

Is there a better way to do this? ...
1
vote
0answers
76 views

Filling a cumulative array in Swift

I have a "cumulative" lookup array for a custom collection view layout. The idea is that I have an array of rectangles, each with an index. The index is not unique, and is monotonically increasing. ...
-1
votes
3answers
235 views

Dijkstra in C++ to find shortest path for every vertex of a directed graph

I am trying to implement the Dijkstra algorithm in c++ that finds the shortest path for a graph from a text file. The text file contains a matrix that represents a directed graph. What I am trying ...
4
votes
2answers
132 views

Counting the longest increasing subsequence in an array of integers

This is my finished function to find the length of the longest consecutive subsequence of an input array of integers. It's for an assessment so things like the numerical method used and the format of ...
0
votes
2answers
44 views

Simple print function, passing in various arrays [closed]

I wanted to create a print method that could take in a given array and print it. I can only seem to make the print function specific to my specific array. My print function only can print 1 array, but ...
0
votes
1answer
50 views

More elegant array multiplication than multiple concat statements

Background Trevor wishes to duplicate an array, transforming it by multiplying its elements four times. Existing Solution ...
1
vote
1answer
45 views

Create an Array with n values that is able to use Array methods instantly

As it is impossible to use Array methods on new Array(n), e.g. new Array(5).map(/* [some callback] */), I deviced a pseudo ...
3
votes
1answer
41 views

Comparing two implementations of smoosh()

In this question, the suggested solution for smoosh() is as shown below, ...
6
votes
1answer
66 views

Returning multiplied matrix array

Is there a more clever way of writing this piece of code? It does work but I thought there might be a better way of returning a matrix from multiplying the parameter by itself. ...
3
votes
1answer
31 views

Generating a complicated data structure in a more efficient manner

I need to convert some CSV data into a format recognizable by some old script my work uses. Changing the format is pretty much out of the question. So I've written this: ...
3
votes
1answer
64 views

Traversing a tile-based 2D-array map using keyboard controls

I've produced the beginnings of an RPG-style game using HTML5 and canvas. So far you can use the keyboard controls WASD to move an avatar around a simple tile-based map. The map is constructed of ...
6
votes
4answers
238 views

Optimizing smoosh() method further

Part I of this question says: Fill in the smoosh() method in the Homework3 class so that it performs as indicated in the ...
2
votes
0answers
66 views

Sorting an array to match the order of values of another array

I'm running hundreds of curl operations in parallel to my own API, the response array that I get is out of order ( the reason being that the first one to finish gets added to the response array ...
4
votes
1answer
165 views

Using array values to create variables, if statements and highchart dataset

I am trying to make my script maintenance-free by replacing some "static" variables and labels with dynamic ones. The main function of my code is to extract data from a SharePoint-list which contains ...
13
votes
4answers
421 views

Array alive/dead entity “refresh” algorithm

I have an Entity class that can be either dead or alive. I store entities contiguously in a resizable array. During an ...
2
votes
2answers
161 views

Function that takes an array of integers and returns that array rotated by N positions

Example: if \$N=2\$, given the input array \${[1, 2, 3, 4, 5, 6]}\$ the function should return \${[5, 6, 1, 2, 3, 4]}\$ Here is my code: ...
3
votes
2answers
81 views

Making this arraycopy more efficient

I'd like to find out how I can make my function more efficient: ...
3
votes
1answer
36 views

Loop through products and return first product that matches criteria

I am writing a function which loops through an array of products. The function needs to return: the ID of the first product that has an image and is ...
6
votes
4answers
226 views

Simple resizable array

In some (lower-level) parts of my codebase I often have the need to allocate resizable array storage for certain objects, that usually are not default-constructible. I created a simple class using ...
5
votes
1answer
41 views

Concurrently Iterable Poor Array List

As I wrote on SO, I need an ArrayList-like structure allowing just the following operations get(int index) add(E element) ...
9
votes
1answer
139 views

Passing a 1D array (single column of a Range object) to .NET to manipulate it without loops and returning it back to VBA

Background Kind of a follow up - slightly related to my other SO question. I thought that if somehow I find a way in VBA to pass a single column to .NET and convert it to a native .NET type then I ...
3
votes
2answers
269 views

Squaring numbers in an array

I want to know if there is a better way to square numbers in an array. This is what I wrote: ...
6
votes
3answers
298 views

Copying one array to the end of another array

I wrote a program that places values in one array to the end of another array. It keeps the order of the values. If the second array is bigger, then there will be leading zeroes. Is there anything I ...
2
votes
3answers
100 views
2
votes
1answer
170 views

Calculate percentage of values in an array with a certain condition

I had to write a function that calculates the percentage of values in table less or equal to 2. Is my code right or is there anything missing? ...
6
votes
3answers
152 views

Byte swapping functions

I recently programmed some byte swapping functions. As a special I did a function which can convert an entire int array. I please you to look at the following aspects: portability performance ...