An array is a data structure consisting of a collection of elements (values or variables), each identified by at least one index. All the elements of an array are stored adjacent to each other.
0
votes
1answer
24 views
A pattern to destructively extract items from an array
I want to efficiently (few intermediate objects) and neatly (few lines and easy to read) filter an array, removing and returning rejected items. So like a call to delete_if except instead of returning ...
-1
votes
0answers
30 views
Array sorting code and file IO [closed]
I would appreciate if someone could help me finalise a code.
I need to read in people's info (such as ID, age, etc.) from a text file into different arrays. Records are like this
2012317109 Jamie ...
1
vote
2answers
39 views
Best way to check for one of two values in an array in PHP
I want to see if one of two values (a, b) are in an array. Here's my current thought:
$match_array = array('a','b');
$array_under_test = array('b', 'd', 'f');
if (array_intersect($match_array, ...
1
vote
1answer
59 views
High School Java Class: Pong Project External Reviewer
Panelball class:
import java.awt.*;
import java.awt.event.KeyEvent;
import javax.swing.*;
public class Panelball extends JPanel implements Runnable {
private static final long ...
3
votes
2answers
90 views
Optimizing unboxed array operations in Haskell
Consider this simplified code which successively permutes array elements:
import Data.Word
import Data.Bits
import Data.Array.Unboxed
import Data.Array.Base
import Data.Array.ST
test3 :: UArray Int ...
2
votes
1answer
73 views
Most efficient way to insert into ordered sequence
I have a dashboard like interface, that can have many tabs. There can be as many or as few tabs as the user likes, with the user being allowed to re order them as they wish. Exactly like browsers do.
...
0
votes
0answers
28 views
Deallocation problem [migrated]
I have the code below which contains a dynamic array of strings. I'm having problems deallocating each individual string that is generated. I assumed I could just include a new for loop which ...
1
vote
1answer
38 views
Referring to nested arrays and array_merge (php)
In such an array:
$arr = Array (
[key0] => Array (
[subkey0] => Array (
[0] => "value0"
[1] => "value1"
)
[subkey1] => Array (
...
0
votes
0answers
53 views
Bit array not working as fast as expected [closed]
I recently downloaded the bitarray module from here, for a faster prime sieve, but the results are dismal.
from bitarray import bitarray
from numpy import ones
from timeit import timeit
def ...
3
votes
1answer
77 views
Calculating n x n determinant
According to instructions and sample code from MSDN Magazine and comments from post here determinant of n x n...
I changed code to be like this:
using System;
internal class ...
0
votes
3answers
69 views
Review: Compare two Anagrams words in C
A simple attempt by me to test whether two words are anagrams or not. Here is the code:
#include <stdio.h>
#include <ctype.h>
#define CH_LEN 15
#define N 26
int main(void) {
char ...
2
votes
1answer
135 views
Snake game — made with Python
I wrote a simple Python snake game, it's about 250 lines of code. Can someone give me some advice on how to refactor/make it better?
game.py
# game.py - 3/22/2013
import pygame, sys, os
from ...
0
votes
1answer
52 views
Turning multiple PHP arrays into one array ready for conversion to Javascript
I am creating a multiple choice quiz game with PHP and Javascript. Questions can have 2 to 6 answers. I have been using the PHP queries in the code below to get arrays of the questions of a quiz, and ...
0
votes
2answers
43 views
Checking for array key exists in multi-dimensional array in PHP
Say I have a data structure like this:
array(3) {
["id"]=>
int(1)
["name"]=>
string(3) "foo"
["message"]=>
array(1) {
["action"]=>
string(3) "PUT"
}
}
Where ...
1
vote
1answer
50 views
Help creating a workable design?
I received the following feedback for my code:
"I still do not see a design here that will work.
It is a very bad idea to have the big switch and loop at this point. All you need in your main() ...