sequences

Recursively generate ordered substrings from an ordered sequence of chars?

Edited after getting answers Some excellent answers here. I like Josh's because it is so clever and uses C++. However I decided to accept Dave's answer because of it's simplicity and recursion. I tested them both and they both produced identical correct results (although in a different order). So thanks again everyone. Say I have a st...

Avoiding stack overflow (with F# infinite sequences of sequences)

I have this "learning code" I wrote for the morris seq in f# that suffers from stack overflow that I don't know how to avoid. "morris" returns an infinite sequence of "see and say" sequences (i.e., {{1}, {1,1}, {2,1}, {1,2,1,1}, {1,1,1,2,2,1}, {3,1,2,2,1,1},...}). let printList l = Seq.iter (fun n -> printf "%i" n) l ...

Cygwin BASH and ANSI control sequences

Several things here: Can anyone point me at C code to decode ANSI console escape sequences? Is there a way to get Cygwin BASH to emulate a dumb old TTY? Maybe this should be 2 questions. Thanks. ...

How can I remove an item from a sequence in Clojure?

First, I assume each structure-specific sequences would have different ways to remove an item: Vectors could be by index, List could be remove first or last, Set should be passing of the actual item to remove, etc. Second, I assume there are some methods for removal that are structure agnostic; they work on seq interface. Since sequenc...

N-Grams for sequence correction

Sorry for the difficult question. I have a large set of sequences to be corrected by either/or adding digits or replacing them (never removing anything) that looks like this: 1,2,,3 => 1,7,4,3 4,,5,6 => 4,4,5,6 4,7,8,9 => 4,7,8,9,1 4,7 => 4,8 4,7,1 => 4,7,2 It starts with a padded original sequence, and a sample correction. I'd lik...

What is the proper JPA mapping for @Id in parent and unique sequence in base classes

I have a class hierarchy: abstract DomainObject { ... @Id @GeneratedValue(strategy = GenerationType.SEQUENCE, generator="SEQ") @SequenceGenerator(name="SEQ",sequenceName="SEQ_DB_NAME") @Column(name = "id", updatable = false, nullable = false) private Long id; ... } BaseClass extends DomainObject { ... // Fill in ...

Regex and a sequences of patterns?

Is there a way to match a pattern (e\d\d) several times, capturing each one into a group? For example, given the string.. blah.s01e24e25 ..I wish to get four groups: 1 -> blah 2 -> 01 3 -> 24 4 -> 25 The obvious regex to use is (in Python regex: import re re.match("(\w+).s(\d+)e(\d+)e(\d+)", "blah.s01e24e25").groups() ..but I al...

Interesting strings algorithm

Given two finite sequences of string, A and B, of length n each, for example: A1: "kk", A2: "ka", A3: "kkk", A4: "a" B1: "ka", B2: "kakk", B3: "ak", B4: "k" Give a finite sequences of indexes so that their concentration for A and B gives the same string. Repetitions allowed. In this example I can't find the solution but for example if...

In Clojure, when should I use a vector over a list, and the other way around?

I read that Vectors are not seqs, but Lists are. I'm not sure what the rationale is for using one over the other. It seems that vectors are used the most, but is there a reason for that? Any answers are appreciated, thanks! ...

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 know I could use letter (digram? trigram?) frequency analysis, only applied to note pitches,...

Calling Seq.skip and Seq.take in F#

let aBunch = 1000 let offset = 0 let getIt offset = MyIEnumerable |> Seq.skip aBunch * offset |> Seq.take aBunch |> Seq.iter ( .. some processing ...) Calling getIt() with different offsets eventually gives me an 'Invalid operation' exception with additional info that 'the input sequence had insufficient elements' I try to...

Oracle: How are sequences implemented?

To meet some odd business requirements, I'm going to have to implement my own sequence-like counters. I'm going to make a first cut of this in the obvious way, but I would like to understand a bit more about how Oracle implements sequences. For example, can they use latches instead of locks? I've been unable to find much about this on...

interleaving bits with a mask

inputs: arbitrary bitset, e.g. bit positions 012345 arbitrary bit mask, e.g. (x=1) xx0x0x output: xx0x1x2345 That is, I want the first bit of the bitset to be placed in the first 0 of the mask. Likewise, the second bit is placed in the second 0 of the mask. example: mask = 1001001 bits = 1101 result = 1111011 I know that this ...

F#: How do i split up a sequence into a sequence of sequences

Background: I have a sequence of contiguous, time-stamped data. The data-sequence has gaps in it where the data is not contiguous. I want create a method to split the sequence up into a sequence of sequences so that each subsequence contains contiguous data (split the input-sequence at the gaps). Constraints: The return value must ...

How do I get a sequence's MINVALUE in Oracle 10g PL/SQL?

I wrote a PL/SQL script to set a sequence's value to the maximum value of a table's primary key: DECLARE max_idn NUMERIC(18, 0); seq_nextval NUMERIC(18, 0); increment_amount NUMERIC(18, 0); BEGIN SELECT MAX(mbr_idn) INTO max_idn FROM mbr; SELECT mbr_seq.nextval INTO seq_nextval FROM DUAL; increment_amount := max_id...

Sequential numbers in distributed word

We are building order processing system. We have a cluster of processing servers. We need to assign readable numbers to the orders (e.g. ORD-000001, ORD-000002). Main problem that this is hard for us to implement system wide lock. I am thinking about schemas with lock expiration. But everything comes in mind still have bottlenecks. We...

List all sequences in a Postgres db 8.1 with SQL

I'm converting a db from postgres to mysql. Since i cannot find a tool that does the trick itself, i'm going to convert all postgres sequences to autoincrement ids in mysql with autoincrement value. So, how can i list all sequences in a Postgres DB (8.1 version) with information about the table in which it's used, the next value etc w...

Is Clojure object-oriented at its heart? (Polymorphism in seqs)

Clojure is a functional lisp, reportedly not at all object-oriented, even though it runs on the JVM, a VM designed for an object oriented language. Clojure provides identical interfaces for iterating over lists and vectors by abstracting them to an interface called seq. This is even implemented internally using a Java interface called ...

Python: Removing characters from beginnings of sequences in fasta format

Hi, I have sequences in fasta format that contains primers of 17 bp at the beginning of the sequences. And the primers sometimes have mismatches. I therefore want to remove the first 17 chars of the sequences, except from the fasta header. The sequences look like this: > name_name_number_etc SEQUENCEFOLLOWSHERE > name_number_etc SEQUE...

Can you BLAST with BioPython? Anyone have experience with this?

Hi, I am going to BLAST several sequences and download the top 100 hits or so from each sequence. Then I will pool the downloaded sequences and remove duplicates. I was thinking of trying out BioPython for this since I am learning Python, but I don't know if this is feasible? Comments to this anyone? Thanks! Jon ...