matching

Match the pairs search algorithm?

I found an interesting pairs matching game at http://xepthu.uhm.vn. The rule is simple, you have to find and connect two identical pokemon but the path between them is not blocked and the direction can't not be changed 3 times. Let's see an example: I've think alot about the algorithm to check if the path between any 2 selected pokemo...

Grouping fields that partially match in MySQL

I'm trying to return duplicate records in a user table where the fields only partially match, and the matching field contents are arbitrary. I'm not sure if I'm explaining it well, so here is the query I might run to get the duplicate members by some unique field: SELECT MAX(id) FROM members WHERE 1 GROUP BY some_unique_field HAVING COU...

Match elements between 2 collections with Linq in c#

Hi, i have a question about how to do a common programming task in linq. lets say we have do different collections or arrays. What i would like to do is match elements between arrays and if there is a match then do something with that element. eg: string[] collection1 = new string[] { "1", "7", "4" }; string[] collecti...

How do I go about building a matching algorithm?

I've never built an algorithm for matching before and don't really know where to start. So here is my basic set up and why I'm doing it. Feel free to correct me if I'm not asking the right questions. I have a database of names and unique identifiers for people. Several generated identifiers (internally generated and some third party), ...

Matching two columns in MySQL

I'm quite new to SQL and have a question about matching names from two columns located within a table: Let's say I want to use the soundex() function to match two columsn. If I use this query: SELECT * FROM tablename WHERE SOUNDEX(column1)=SOUNDEX(column2); a row is returned if the two names within that row match. Now I'd also like t...

"(1:k) Tree-Matching" - Solvable in polynomial time?

Some months ago there was a nice question regarding a "1:n matching problem" and there seems to be no poly-time algorithm. I would like to add constraints to find a maximum matching for the 1:n matching problem with a polynomial algorithm. I would like to say: "For vertex A1 choose either {B1,B2,B5} or {B2,B3} if the vertices are not a...

Expect script, working for years, behaves unexpectedly with new Expect version

I recently migrated from a FreeBSD 4.x server to a FreeBSD 8.0 server. I am now using expect-5.43.0_3. I don't remember what the old version of expect is, and I can't quickly check, because the hard drive on the old system crashed within minutes of finishing the migration! (WHEW!) Anyway, I have an expect script that creates a zipped...

Ocaml exception handling for opening input channel

Hi! As a beginner in Ocaml, I have this current working code: ... let ch_in = open_in input_file in try proc_lines ch_in with End_of_file -> close_in ch_in;; Now I would like to add error handling for non-existing input files, I wrote this: let ch_in = try Some (open_in input_file) with _ -> None in match ch_in with | Some x -> t...

Django approximate matching of unicode strings with ascii equivalents

I have the following model and instance: class Bashable(models.Model): name = models.CharField(max_length=100) >>> foo = Bashable.objects.create(name=u"piñata") Now I want to be able to search for objects, but using ascii characters rather than unicode, something like this: >>> Bashable.objects.filter(name__lookslike="pinata") ...

Match returning a string instead of object

This simple regex matching returns a string instead of an object on every browser but the latest firefox... text = "language. Filename: My Old School Yard.avi. File description: File size: 701.54 MB. View on Megavideo. Enter this, here:" name = text.match(/(Filename:)(.*) File /); alert(typeof(name)); as far as i know ...

Why does a positive lookahead lead to captures in my Perl regex?

Hi everyone, I can't get why this code work: $seq = 'GAGAGAGA'; my $regexp = '(?=((G[UCGA][GA]A)|(U[GA]CG)|(CUUG)))'; # zero width match while ($seq =~ /$regexp/g){ # globally my $pos = pos($seq) + 1; # position of a zero width matching print "$1 position $pos\n"; } I know this is a zero width match and it dosn't put the ma...

Looking for ideas for a simple pattern matching algorithm to run on a microcontroller

I'm working on a project to recognize simple audio patterns. I have two data sets, each made up of between 4 and 32 note/duration pairs. One set is predefined, the other is from an incoming data stream. The length of the two strongly correlated data sets is often different, but roughly the same "shape". My goal is to come up with some s...

Matching a string in a Large text file?

I have a list of strings about 7 million in a text file of size 152MB. I was wondering what could be best way to implement the a function that takes a single string and returns whether it is in that list of strings. ...

How would I order a table by the number of matching params in the where clause of an sql statement?

I'm writing sql to search a database by a number of parameters. How would I go about ordering the result set by the items that match the most parameters in the where clause. For example: SELECT * FROM users WHERE username = 'eitan' OR email = '[email protected]' OR company = 'eitan' Username | email | company 1)...

How can I extract a string between matching braces in Perl?

My input file is as below : HEADER {ABC|*|DEF {GHI 0 1 0} {{Points {}}}} {ABC|*|DEF {GHI 0 2 0} {{Points {}}}} {ABC|*|XYZ:abc:def {GHI 0 22 0} {{Points {{F1 1.1} {F2 1.2} {F3 1.3} {F4 1.4}}}}} {ABC|*|XYZ:ghi:jkl {JKL 0 372 0} {{Points {}}}} {ABC|*|XYZ:mno:pqr {GHI 0 34 0} {{Points {}}}} { ABC|*|XYZ:abc:pqr {GHI 0 68 0} ...

PHP Regex: How to match anything except a pattern between two tags

Hello, I am attempting to match a string which is composed of HTML. Basically it is an image gallery so there is a lot of similarity in the string. There are a lot of <dl> tags in the string, but I am looking to match the last <dl>(.?)+</dl> combo that comes before a </div>. The way I've devised to do this is to make sure that t...

How to implement best matching logic in TSQL (SQL Server 2000)

I have two tables X and Y: Table X C1 C2 C3 1 A 13 2 B 16 3 C 8 Table Y C1 C2 C3 C4 1 A 2 N 2 A 8 N 3 A 12 N 4 A 5 N 5 B 7 N 6 B 16 N 7 B 9 N 8 B 5 N 9 C ...

Can I use regular expressions with String.Replace in C#?

For example I have code below string txt="I have strings like West, and West; and west, and Western." I would like to replace the word west or West with some other word. But I would like not to replace West in Western. Can I use regular expression in string.replace? I used inputText.Replace("(\\sWest.\\s)",temp); It dos not wor...

Is there a way to optimise finding text items on a page (not regex)

After seeing several threads rubbishing the regexp method of finding a term to match within an HTML document, I've used the Simple HTML DOM PHP parser (http://simplehtmldom.sourceforge.net/) to get the bits of text I'm after, but I want to know if my code is optimal. It feels like I'm looping too many times. Is there a way to optimise th...

How do you code up a pattern matching code block in scala?

How do you code a function that takes in a block of code as a parameter that contains case statements? For instance, in my block of code, I don't want to do a match or a default case explicitly. I am looking something like this myApi { case Whatever() => // code for case 1 case SomethingElse() => // code for case 2 } And insid...