Questions tagged [sequences]

A sequence is any type for which there is a bijective relation between the integers `0..n` and the elements of the sequence, and the elements may be accessed in the order `0..n`, where `n` is the number of elements in the sequence.

A sequence is any type for which there is a bijective relation between the integers 0..n and the elements of the sequence, and the elements may be accessed in the order 0..n, where n is the number of elements in the sequence.

A sequence may be infinite, in which case, the relation is with the open range 0....

538 questions
8
votes
2 answers

Debugging Seq.sumBy

I was trying to learn me some F# by looking at last years AdventOfCode solutions. I came across this neat peice of code, which I cannot parse at all: i 1|>Seq.sumBy(" (".IndexOf) Note, I believe I understand the prior line (in the link): let i…
Joshua Ball
  • 23,260
  • 6
  • 27
  • 29
8
votes
2 answers

Find the nth number in the increasing sequence formed by 0,2,4,6,8?

We have an increasing sequence in which each element is consist of even digits only (0, 2, 4, 6, 8). How can we find the nth number in this sequence Is it possible to find nth number in this sequence in O(1) time. Sequence: 0, 2, 4, 6, 8, 20, 22,…
Godfather
  • 5,711
  • 5
  • 21
  • 27
8
votes
4 answers

Ruby equivalent of C#'s 'yield' keyword, or, creating sequences without preallocating memory

In C#, you could do something like this: public IEnumerable GetItems() { for (int i=0; i<10000000; i++) { yield return i; } } This returns an enumerable sequence of 10 million integers without ever allocating a collection in…
Drew Noakes
  • 300,895
  • 165
  • 679
  • 742
8
votes
1 answer

Using Alt-left/right to switch between windows in tmux

I am trying to configure tmux to switch between windows using alt-left, alt-right sequences. This is what I have in my .tmux.conf bind-key -n M-Left previous-window bind-key -n M-Right next-window Unfortunately, it doesn't work. On my machine,…
Alexander Sandler
  • 2,078
  • 2
  • 19
  • 21
8
votes
4 answers

I need a better algorithm to solve this

Here is the question (link: http://opc.iarcs.org.in/index.php/problems/FINDPERM) : A permutation of the numbers 1, ..., N is a rearrangment of these numbers. For example 2 4 5 1 7 6 3 8 is a permutation of 1,2, ..., 8. Of course, 1…
2147483647
  • 1,177
  • 3
  • 13
  • 33
7
votes
10 answers

C++ API for returning sequences in a generic way

If I am writing a library and I have a function that needs to return a sequence of values, I could do something like: std::vector get_sequence(); However, this requires the library user to use the std::vector<> container rather than allowing…
jonner
  • 6,331
  • 6
  • 30
  • 28
7
votes
5 answers

Linq statement for an infinite sequence of successive halves

Given a starting number, imagine an infinite sequence of its successive halves. 1, 0.5, 0.25, 0.125, ... (Ignore any numerical instabilities inherent in double.) Can this be done in a single expression without writing any custom extension methods…
Drew Noakes
  • 300,895
  • 165
  • 679
  • 742
7
votes
3 answers

Sequence expansion question

I have a sequence of 'endpoints', e.g.: c(7,10,5,11,15) that I want to expand to a sequence of 'elapsed time' between the endpoints, e.g. c(7,1,2,3,4,5,6,7,8,9,10,1,2,3,4,5,1,2,3,4,5,6,7,8,9,10,11,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15) …
Zach
  • 29,791
  • 35
  • 142
  • 201
7
votes
1 answer

How do you get the next value in a sequence into a variable?

So I'm writing a stored procedure and am having trouble getting the next value of a sequence into a variable. The sequence name is passed into the function and is stored as a varchar2 variable. How can you get the next value in that sequence into a…
user439199
  • 387
  • 2
  • 5
  • 8
7
votes
7 answers

Find the largest sequence of numbers in an integer arraylist

This is what I've gotten so far. What I've tried to do is go through and find the sequence using greater or equals too in an if statement. Then when that value no longer is greater or equal to the preveious number it goes into the else statement…
user2088748
7
votes
3 answers

Longest common contiguous subsequence - algorithm

My question is simple: Is there an O(n) algorithm for finding the longest contiguous subsequence between two sequences A and B? I searched it, but all the results were about the LCS problem, which is not what I'm seeking. Note: if you are willing to…
Rontogiannis Aristofanis
  • 8,883
  • 8
  • 41
  • 58
7
votes
1 answer

number rows by variable, but start over when condition is hit

I want to number certain combinations of row in a dataframe (which is ordered on ID and on Time) tc <- textConnection(' id time end_yn abc 10 0 abc 11 0 abc 12 1 abc …
Max van der Heijden
  • 1,095
  • 1
  • 8
  • 16
7
votes
2 answers

Algorithm to measure similarity between two sequences of strings

How can I measure similarity-percentage between two sequences of strings? I have two text files and In files there sequences are written like First file: AAA BBB DDD CCC GGG MMM AAA MMM Second file: BBB DDD CCC MMM AAA MMM How to measure…
7
votes
5 answers

Javascript - How Do I Check if 3 Numbers Are Consecutive and Return Starting Points?

If I have an array of [1, 2, 3, 5, 10, 9, 8, 9, 10, 11, 7] and wanted to find each case of 3 consecutive numbers (whether ascending or descending), how would I do that? Second part would be then to alert an array with the index of each of these…
Yasir
  • 879
  • 5
  • 13
  • 31
6
votes
2 answers

Analysis of “Finding Maximum Sum of Subsequent Elements” algorithm

If possible, I would like someone to give an analytic explanation of the algorithm. For example, given the sequence -2, 4, -1, 3, 5, -6, 1, 2 the maximum subsequence sum would be 4 + -1 + 3 + 5 = 11 This algorithm I am reffering to is an divide…
Vaios Argiropoulos
  • 387
  • 1
  • 8
  • 18