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.
3
votes
0answers
21 views
Finding the longest Collatz sequence cycle
I wrote a program to calculate Collatz sequences for initial numbers between 1 and a given integer i, then find the one with the largest cycle length. My code is ...
4
votes
1answer
65 views
Converting string array to string (and vice-versa) for storing via XML
I'm using XML to store data and I need to store a string array in it. The best way (that I can think of) to store a string array is by converting it to a single string. In order to do that, I'm using ...
0
votes
0answers
32 views
How to avoid StackOverflowError caused by the number of recursion calls in Java? [on hold]
I want to solve this problem: https://www.hackerrank.com/challenges/find-median ,i.e. find the median element in unsorted array. To do this I perform quickselect algorithm. My program works correctly ...
1
vote
0answers
22 views
4
votes
2answers
76 views
Implementing write sphere of values to 3D array
The code below is sort of complicated to explain...
It writes a "sphere" of data to a 3D array from the given 3D-Position outwards in a spherical shape based on the given radius and value to write.
A ...
7
votes
3answers
262 views
Find two unique integers in sorted array
I have to write the following method:
I have sorted array of integers and in this array every integer repeats twice, except two elements. I have to find these two elements.
Input: 1, 1, 2, 3, 3, ...
4
votes
5answers
166 views
Search algorithm for specific values in a 3D array/matrix being super slow
I'm trying to create code that reads a text file (containing (double) numbers between 0 and 1) and filling up a 3D array/matrix (calling it matrix from now on) with ...
2
votes
1answer
42 views
Duplication Elimination Project [closed]
I am currently doing a project for school, and I am completely stumped. We are only on Chapter 8 of C# Development 1 and I have a question about the code.
The project is:
Use a one-dimensional ...
4
votes
1answer
50 views
Product of corresponding elements in 2 arrays
Given two arrays A and B, of length N and length k ...
4
votes
2answers
50 views
Dynamic array of Years
I wanted to make a dynamic select statement from this year to 10 years. This gets the job done, but I feel like it's a little much.
...
10
votes
5answers
562 views
Yahtzee game (using arrays and object classes)
As part of an assignment for my intro Java class (please bear with my beginner skill set), I'm working on a program for which a Die object class is used to play a Yahtzee game. An overview of the ...
4
votes
2answers
133 views
Searching for duplicates without any collection or sorting
I have written code which is easy to understand, but may not be efficient but will solve the purpose.
...
7
votes
3answers
112 views
Compare string with wildcard string
I have the following function to compare a string with a wildcard string (containing ? and *), as C# doesn't seem to have a builtin function to do it.
...
1
vote
1answer
74 views
Declaring arrays knowing their maximum size
I know the maximum array size is 6. So what is the best practice to declare an array?
In the following code I used it like this:
...
8
votes
2answers
165 views
Min and Max initialization
Is it a good practice to initialize the max to -100000 and min to 100000? Is there any other way to initialize both min and max to 0?
...
3
votes
0answers
54 views
Python Multiprocessing: Using mutable ctype arrays seems to work, yet I am not seeing significant speed-up. Why?
As a brief introduction, I am student working on a body of code which forms part of my Masters' research - this is my first question on SO. My background is in physics and mathematics, so I will ...
4
votes
2answers
187 views
Finding the value 'n' in an array that has 'n' or more larger values
Given an unsorted array of integers, you need to return maximum possible \$n\$
such that the array consists at least \$n\$ values greater than or equals
to \$n\$. Array can contain duplicate ...
5
votes
2answers
45 views
Finding the best matching block/patch in Python
I wish to locate the closest matching NxN block within a WxW window centred at location (x,y) of a larger 2D array. The code below works fine but is very slow for my needs as I need to run this ...
1
vote
2answers
60 views
Given suffix array and a pattern, search if given pattern exists
Given a suffix array for a word, check if a pattern (consecutive chars) exists.
Example:
A suffix array constructed for "ameya" should return true for "ame" but false for "foo" or false ...
7
votes
2answers
89 views
Output in one window
Can anyone give me feedback please? I used what I have learnt so far, mainly methods, loops and arrays. I would like you view based on these topics, however, comments on how to improve are welcome.
...
5
votes
3answers
272 views
How to increase performance/speed of code that uses .Count() on Lists?
The Test
PublicQuestion_ComplexTest
is taking around 1600ms (1.6 seconds) to run, but used to take 92ms. I have a feeling this is because of recent code changes ...
5
votes
1answer
39 views
explode textarea and commas [closed]
Am attempting to recreate a common feature, where a user can type several items in to a textarea, separated by commas and newlines and then submit them, i.e. for multiple record entry.
The data does ...
1
vote
1answer
48 views
Find part of string in array, replace entire row with that part of string if found
Following is the string: (I'm getting that from config file so its not constant):
...
5
votes
2answers
226 views
Fastest way to multiply two byte arrays in Java
I have two byte arrays that represent unsigned 256-bit values and I want to multiply them resulting into a new value. What is the fastest ways to do this in Java? And are there other factors I should ...
6
votes
2answers
379 views
Is there a way to optimise my Perlin noise?
I just started using Perlin noise a few days ago, and the results look quite good. But it takes over 3 seconds to calculate and draw a 1024x1024 bitmap of said noise. I use an array of 1024x1024 to ...
2
votes
2answers
59 views
Two-dimensional array allocation in Go
I am creating a two-dimensional array, which I am going to process later in ways similar to image MinFilter, procedural labyrinth generation, etc. -- implying using coordinates and neighbors.
Here ...
2
votes
2answers
53 views
Importing tab delimited file into array
I am needing to import a tab delimited text file that has 11 columns and an unknown number of rows (always minimum 3 rows).
I would like to import this text file as an array and be able to call data ...
3
votes
2answers
317 views
Check winner in a Tic Tac Toe game
I have the below code to check for a winner in a Tic Tac Toe game. I'm wondering if this is a good approach, and if there is a better way of doing this (maybe by monitoring the state of the board).
...
6
votes
1answer
64 views
Finding the sub-array with maximum sum - my slow approach
I decided to give the maximum sub-array sum problem an interesting go, however I will assure you that it doesn't perform well, and that I would never put this in production.
I'd like a review on ...
13
votes
4answers
535 views
Finding the sub-array with the maximum sum - my approach
This is the code I ended up with that implements the approach I described in a recent answer to another question about the same problem
The basic idea here is to not loop through more things than ...
1
vote
1answer
38 views
Find-and-replace optimization
I'm looking for some JavaScript code improvement and optimization. Is it possible to optimize this block of code (for example, remove double array loop)?
...
7
votes
4answers
564 views
Find the subarray with the max sum
In an interview I was asked to solve the following problem:
find a subarray with max sum
I have written a piece of code for the same. I need your help in reviewing this code.
...
3
votes
2answers
130 views
Calculate all possible combinations of an array of arrays or strings
I'm using code adapted from this Stack Overflow question to calculate all possible combinations from an array, which may contains strings.
For example:
...
2
votes
2answers
135 views
Two solutions with min max values - which should be slower?
While practicing at codinbat.com on the assignment:
Given an array length 1 or more of ints, return the difference between the largest and smallest values in ...
4
votes
1answer
97 views
Making an array editable by user
What I want to do:
Let users add data to an array through an input field and add button.
HTML:
...
7
votes
2answers
137 views
Optimize a parallelized program to optimize train schedules
This loops through a vector of vector of A and adds a smaller array to a bigger one at a specified position+random shift. Then it is checked if it is a better solution, and if yes, it is stored, else ...
4
votes
2answers
275 views
Shortest possible way of printing a specific board
I am trying to print a board exactly like this with the multidimensional array.
char score[10][10] = {' '};
...
2
votes
2answers
54 views
JavaScript Array Comparison (aka Set Comparison)
I want to compare the values in two arrays. The order of the values doesn't matter. Basically they are two Sets. This function returns true if the values are the same in both arrays, or false ...
4
votes
1answer
48 views
1
vote
1answer
46 views
Robots files generation - simplifying foreach code
I'm trying to figure out if there's a way I can simplify this code which is used to generate a robots.txt file with numerous rules. Different files/folders are separated in separate arrays because ...
2
votes
3answers
122 views
Split the array so that the sum of the numbers on one side of the split equals the sum of the numbers on the other side
I would really appreciate if you can help me to find a better way to do it.
...
1
vote
0answers
39 views
5
votes
2answers
114 views
Check for correct number of elements in exploded string
Let's say I've got this string:
$str = '1-2-3';
and I explode this like so:
$strSplit = explode('-', $str);
what would be ...
5
votes
2answers
29 views
Reading code from array efficiently
I'm trying to read data from an array. I manage to get the information I want but my code is extremely inefficiently written.
My array looks like this:
...
4
votes
1answer
52 views
Computationally efficient way of comparing and merging like object keys
Though I can achieve most ends via a series of conditionals and arithmetic, especially when iterating over or comparing arrays I frequently hear of much more efficient implementations.
Hailing from ...
2
votes
0answers
64 views
Optimization Algorithm: Too much memory consumed
What I have here is an implementation of an optimization algorithm called the covariance matrix adaptation evolutionary strategy. I am using this algorithm to optimize the position of wind turbines ...
7
votes
6answers
559 views
Python address index +1 with list comprehension
Task from CodingBat:
Return the sum of the numbers in the array, returning 0 for an empty array. Except the number 13 is very unlucky, so it does not count and numbers that come immediately after ...
1
vote
0answers
43 views
scraping and saving using Arrays or Objects
I'm using Anemone to Spider a website, I am then using a set of rules specific to that website, to find certain parameters.
I feel like it's simple enough, but any attempt I make to save the ...
5
votes
3answers
191 views
Is there a simpler way to find winners when there is a tie?
Background:
I have a Python script which parses a complicated CSV generated on election nights. Each row of the CSV represents a race. As I loop through the races, I store the candidates for each ...
4
votes
2answers
65 views
Reduce Prime Sieve Memory Consumption 2
I've made a prime number generator (for Project Euler). It uses Euler's Sieve (a modified Sieve of Eratosthenes), with a mod 30 step. I'd like to reduce the memory consumption to 4/15 what it ...