moving array elements inside the array

Whats an efficient way to move elements to a new index inside an array like this? A = collect(1:9) # [1,2,3,4,5,6,7,8,9] # now lets move elements 1:3 to index 2 move!(A,1:3,2) # [4,1,2,3,5,6,7,8,9] # lets move the 9 to index 3 now move!(A,9:9...
more »

2017-03-17 12:03 (2) Answers

Read plist into specific type

When using this: let cities: [[String : String]] = { guard let URL = Bundle.main.url(forResource: "cities", withExtension: "plist") else { return [] } return NSArray(contentsOf: URL) as! [[String : String]] }() from this: <...
more »

2017-03-16 03:03 (2) Answers

C++ how to use std::find properly

I got a question about one article in www.cplusplus.com and exactly about std::find which is function from the Algorithm library. Here is my code. Code in randnum.cpp: #include "randnum.h" void randNum (char timeATM) { int *p, newRandNum; ...
more »

2017-03-15 22:03 (4) Answers

How to fix aborting Fibonacci sequence code

I am trying to get a Fibonacci sequence of 5 million elements. This code aborts abnormally, when I pass 1000 as a parameter. def self.fibo_seq(limit) result_array = [0,1] return result_array if limit < 2 while result_array.length <= l...
more »

2017-03-15 19:03 (4) Answers

Recurse through a dynamic array

I am looking for a generalised solution for the following snippet:: var d = [[1,2,3], [1,2], [1,2,3,4,5,6]]; d[0].map((val1, index1) => { d[1].map((val2, index2) => { d[2].map((val3, index3) => { console.lo...
more »

2017-03-15 16:03 (2) Answers

Generating tall array with numpy

I'm new to python and numpy (I'm more accustomed to R) and have been playing around with creating arrays and want to create a tall array, where the first column is just a range with custom increment, and the second column is a unif random between 0 a...
more »

2017-03-15 14:03 (2) Answers

Complex Laravel collection

I'm having some issues with the Laravel Collection class. What I'm trying to do: I have a multisite solution in which a site has "facilitators". Sometimes one facilitator appears on multiple sites, and not just one. I want to list all the facilit...
more »

2017-03-15 09:03 (2) Answers

code crashes when accessing a predefined array

I'm having trouble understanding why my code crashes when accessing the array. When converting the function param to int[3][3] instead of int** I get no problems, but I can't understand why, since the int** I'm given as a argument is a valid pointer ...
more »

2017-03-15 08:03 (2) Answers

Splitting Strings within an Array

I am writing a program in python that reads in a text file and executes any python commands within it. The commands may be out of order, but each command has a letter ID such as {% (c) print x %} I've been able to sort all the commands with in the d...
more »

2017-03-15 04:03 (5) Answers

What is the difference?

Is there any difference between these two declarations: char ch; char ch[2] Actually the thing because of which this question arose in my mind is the ending with '\0' i.e. null character so one of the 2 characters of the array ch[2] is null chara...
more »

2017-03-14 17:03 (2) Answers

Find Max Slice Of Array | Javascript

I need to find the maximum slice of the array which contains no more than two different numbers. Here is my array [1, 1, 1, 2, 2, 2, 1, 1, 2, 2, 6, 2, 1, 8] My thought process on this is to find the numbers that are not repeated and return their in...
more »

2017-03-14 13:03 (3) Answers