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
5
votes
5 answers

Algorithm for music imitation?

I'm interested in automatic music making. I was thinking about a program that is fed a large number of 1-bar arpeggios (= fixed length sequences of notes, for simplicity) and generates its own sequences, based on what it learnt. To start with, I…
janesconference
  • 6,333
  • 8
  • 55
  • 73
5
votes
2 answers

Automatic enumeration of an Sequence

Is there standard function to enumerate an F# sequence that works like Python's enumerate()? It's very easy to write from scratch: let enumerate (sq : seq<'T>) = seq { let rec loop (e : IEnumerator<'T>) index = seq { if e.MoveNext() then…
qehgt
  • 2,972
  • 1
  • 22
  • 36
4
votes
2 answers

Readable unit testing of a yielded sequence?

Let's suppose I have some method that returns a IEnumerable object. This methods make use of yield return keyword to produce a infinite sequence. Example of the Fibonacci algorithm : public static IEnumerable Fibonacci() { long x =…
Steve B
  • 36,818
  • 21
  • 101
  • 174
4
votes
1 answer

How to return early from an iteration on a sequence?

Given a predicate "p", that tells if a solution is good enough. A cost function "f" that tells how good a possible solution is and a function that searches for the "best" (i.e. lowest cost) solution in a sequence of possible solutions. How does an…
Alexander Battisti
  • 2,178
  • 2
  • 19
  • 24
4
votes
1 answer

Quick way to compute n-th sequence of bits of size b with k bits set?

I want to develop a way to be able to represent all combinations of b bits with k bits set (equal to 1). It needs to be a way that given an index, can get quickly the binary sequence related, and the other way around too. For instance, the…
Eduard
  • 127
  • 4
4
votes
5 answers

F# how to abstract Console.ReadLine() as string seq

I want to write a function to abstract Console.ReadLine() into a string seq the seq should break when line = null ConsoleLines(): unit -> string seq To be used like this: for line in ConsoleLines() do DoSomething line How do you write this…
Luca Martinetti
  • 3,396
  • 6
  • 34
  • 49
4
votes
8 answers

Why do you hate sequences on Oracle?

Some people don't like sequences on Oracle. Why? I think they are very easy to use and so nice. You can use them in select, inserts, update,...
FerranB
  • 35,683
  • 18
  • 66
  • 85
4
votes
1 answer

F# combining two sequences

I have two sequences that I would like to combine somehow as I need the result of the second one printed right next to the first. The code is currently where playerItems refers to a list: seq state.player.playerItems |> Seq.map (fun i ->…
Kieran Dee
  • 129
  • 9
4
votes
2 answers

Generic reverse of list items in Python

>>> b=[('spam',0), ('eggs',1)] >>> [reversed(x) for x in b] [, ] Bummer. I expected to get a list of reversed tuples! Sure I can do: >>> [tuple(reversed(x)) for x in b] [(0,…
mrkafk
  • 617
  • 1
  • 5
  • 4
4
votes
1 answer

Best choice for growing, fixed capacity generic sequence

I'm trying to keep an in-memory list of entries in my .NET cache, representing the last N HTTP requests to my app. What's the best .NET sequence to use for this? Requirements Fixed number of items (e.g 50) Serializable (need to add sequence to .NET…
RPM1984
  • 72,246
  • 58
  • 225
  • 350
4
votes
2 answers

SQL Split data by continuous increasing sequence & then subset each by a pattern

I have data where I am trying to identify patterns from. However the data in each table isn't complete (there are missing rows). I would like to separate the table into chunks of complete data and then identify the patterns from each. I have a…
Olivia
  • 814
  • 1
  • 14
  • 26
4
votes
1 answer

F# - Why Seq.map does not propagate exceptions?

Imagine the following code: let d = dict [1, "one"; 2, "two" ] let CollectionHasValidItems keys = try let values = keys |> List.map (fun k -> d.Item k) true with | :? KeyNotFoundException -> false Now let us test…
psfinaki
  • 1,814
  • 15
  • 29
4
votes
4 answers

JavaScript Pattern Comparison

I'm working on a small machine learning theoretical algorithm using nodeJs. My goal is to compare many array patterns to one source pattern then return how similar they are represented as a percent . For an example pattern1 maybe 80% similar to the…
KpTheConstructor
  • 3,153
  • 1
  • 14
  • 22
4
votes
2 answers

Getting primary key sequence number in postgres

We've got a table where we're exposing a ShortID to our consumers that generates a Youtube like identifier (heavily inspired by this SO post). We use the primary KEY of the row to generate it (in the view). For example SELECT…
Lisa Anna
  • 87
  • 1
  • 9
4
votes
2 answers

Does Seq.groupBy preserve order within groups?

I want to group a sequence and then take the first occurrence of each element in the group. When I try this Seq.groupBy f inSeq |> Seq.map (fun (k,s) -> (k,s|>Seq.take 1|>Seq.exactlyOne)) I find that sometimes I get a different element from s. Is…
Robert Sim
  • 1,428
  • 11
  • 22