Here's the fastest answer I got through Mathworks: range = endIds(1) - startIds(1); t3 = bsxfun(@plus, startIds(:), 0:range); At the time of this writing, this is the only version that is faster than my for loop version, which is in turn faster than using arrayfun or ndgrid. See my detailed...

php,mysql,normalization,sequences

Just relate records to the parent and use a sequence flag. You will still need to update all the records when you insert in the middle but I can't really think of a simple way around that without leaving yourself space to begin with. items table: id | name |...

javascript,python,regex,replace,sequences

You could use the following function: function return_quarter(str) { return str.replace(/([0-9]+)/g,function (number) { return Math.round(number * .25); }); } return_quarter('width: 32px; height: 11px; top: 102px; left: 36px;') returns "width: 8px; height: 3px; top: 26px; left: 9px;" Edit: Looking at your code, you need to catch everything withing the brackets, not...

C#/.Net iterators (IEnumerator<T> as returned by IEnumerable<T> ) are read-only forward only iterators and do not allow removing items from underlying collection compared to Java's iterator.remove. Most collections support removing items by index like List<T>.RemoveAt which would be close equivalent. Alternatively if you just want to skip item during iteration...

algorithm,math,compression,theory,sequences

All compression methods are like that: the output is a set of parameters for a set algorithms that renders the input, or something similar to the input. For example MP3 audio codec breaks the input into blocks of 576 samples and converts each block into frequency-amplitude space, and prunes what...

Here's a way: a = arrayfun(@(x)(1:x), diff(find([1,diff(x),1])), 'uni', 0); [a{:}] The idea is to generate a list of the 'run lengths', i.e. [3,2,1,3,1,1,6] in your case, then just concatenate a bunch of vectors that count to each value in that list, i.e. cat(2, 1:3, 1:2, 1:1, 1:3.... I use arrayfun...

You are using input_string in the body of your loop, but that is never changed, it is always the very first string, in your example "1". Probably changing the first line of the inner loop with: input_string = total_sequence[i] for current_char in input_string: should be enough, but I didn't test...

algorithm,set,permutation,combinatorics,sequences

What you are looking for is the number of surjective functions whose domain is a set of K elements (the K positions that we are filling out in the output sequence) and the image is a set of S elements (your input set). I think this should work: static int...

Use collect instead of map to keep only the elements you want: val elements = parent.child.collect { case n if (n.label == "p") => Paragraph(n) case n if (n.label.matches("h\d")) => Heading(n, n.child.head)) } Anything that isn't defined within the PartialFunction you pass to collect is discarded. There's no reason to...

algorithm,relationship,sequences

A sequence is d-smooth if you can increment/decrement each number at most d times to obtain a (strictly) increasing sequence.

c#,sequences,alphabetical,sequencing,sequence-generators

Lucky for you, I've done this once before. the problems I've encountered is that in the Excel sheet there is no 0, not even in double 'digit' 'numbers'. meaning you start with a (that's 1) and then from z (that's 26) you go straight to aa (27). This is why...

Yes this is an idiomatic way of going about padding partitions of a sequence. In fact that code is very similar to part of the partition function in clojure.core the difference being that partition does not assume a single padding value and instead asks for a sequence: core.clj: ([n step...

performance,algorithm,recursion,sequences

I want to add a little complexity analysis and estimate the size of f(n). If you look at one recursive call of f(n), you notice, that the input n is basically divided by 2 before calling f(n) two times more, where always one call has an even and one has...

string,algorithm,combinations,permutation,sequences

A clue: the first case is a number of paths (with +-1 step) from (0,0) to (n+m, n-m) point, where path never falls below zero line. (Like Catalan numbers for parenthesis pairs, but without balance requirement n=2m) Desired formula is a number of (+-1) paths which never rise above (n-m)...

This can be accomplished using a combination of cycle and partition (take 5 (partition 3 1 (cycle '(a b c d)))) ;; => ((a b c) (b c d) (c d a) (d a b) (a b c)) ...

Maybe you can use a logic like this - >>> A = [-1, 1, 3, 3, 3, 2, 1, 0] >>> def indices(l): ... res = [] ... for i in range(0,len(l)-2): ... diff = l[i+1] - l[i] ... for j in range(i+2,len(l)): ... if (l[j] - l[j-1]) == diff:...

To understand why, you have to understand a bit of pointer arithmetic. abc is the same as &abc[0] and (abc + 3) is the same as &abc[3] that being said, cout prints a string from a given char * to a null character. Therefore, you are basically just printing the...

c++,algorithm,vector,sequences

It works First, it does not quite work, unless vec is sorted to begin with. Otherwise, next_permutation(...) would produce false without exhausting all possibilities, possibly skipping the permutation in which the right solution would be found. but takes too long even when the vector size is just 20. That's...

Change your assignment line to: myNums[i] = i % 2; ...