As of May 31, 2023, we have updated our Code of Conduct.

Questions tagged [pattern-matching]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
3 votes
1 answer
55 views

Wildcard Matching: LeetCode 44 Attempt 2

Original post: Based on feedback from J-H in his answer I have done another attempt. Link to question: Given an input string (s) and a pattern (p), implement wildcard pattern matching with support ...
Martin York's user avatar
  • 93.4k
4 votes
2 answers
159 views

Wildcard Matching: LeetCode 44

Follow up post Link to question: Given an input string (s) and a pattern (p), implement wildcard pattern matching with support for '?' and '*' where: '?' Matches any single character. '*' Matches ...
Martin York's user avatar
  • 93.4k
2 votes
2 answers
67 views

Stepwise nested pattern mattching with exceptions

Background I'm building a lisp-like toy language in Haskell with the following (stripped down) AST: ...
mingmingrr's user avatar
1 vote
0 answers
191 views

Find directories and files matching certain pattern and copy them with powershell

I need to recreate project folders containing all article numbers acquired from a list. It's searching for article names in the foldernames and inside the folders. If the directory is found, it will ...
Lucas's user avatar
  • 11
1 vote
1 answer
77 views

PartialOrd of Rust Enums based on encapsulated data

I have an Enum the encapsulates numeric primitives (u8, i8, u16, i16, u32, i32, u64, i64, f32, f64) into a common type called "Number". I want to implement a PartialOrd train for the enum ...
Darko's user avatar
  • 111
3 votes
2 answers
397 views

pattern matching coding challenge

I have implemented a simple pattern matching for the below algorithm in Java with time complexity of O(n)(n is the size of the input array). Any suggestions for optimization?? one of the most ...
teja sri's user avatar
0 votes
1 answer
68 views

Cardinal to ordinal numbers in F# code reuse

I've been experimenting with the F# Bolero environment to learn F# a bit and I was trying to get the hang of pattern matching by generating ordinal numbers (1st, 2nd, 3rd, ...) from cardinal numbers (...
JansthcirlU's user avatar
4 votes
1 answer
248 views

A different approach to string pattern matching algorithm

Although there exists the most efficient "Knuth-Morris-Pratt" algorithm of string pattern matching. I tried to achieve the same result with a different approach. But I am not sure about it's ...
Deepeshkumar's user avatar
-2 votes
1 answer
729 views

Find repeating pattern in a string

I have written a C function that finds the shortest substring that can be repeated to produce the entire string. input: abcdeabcde result: ...
user786's user avatar
  • 145
1 vote
1 answer
101 views

State monad and pattern matching on data constructors

I am writing a Settlers of Catan server in Haskell for fun. Currently I am passing around state manually. I want to learn more about the State monad and want to incorporate it into my project. However,...
The Coding Wombat's user avatar
3 votes
2 answers
684 views

Structural Pattern Matching syntax to match a value in a list

I was looking into Python 3.10's Structural Pattern Matching syntax, and I want to refactor one of my code that uses if-else, using structural pattern matching. My ...
Sayandip Dutta's user avatar
2 votes
3 answers
118 views

How to refactor the boolean logic of this F# function?

I have a list of path I want to filter out. I want to keep only paths matching a specific pattern and remove all paths matching another specific pattern. To achieve this I pattern matched on each ...
aloisdg's user avatar
  • 561
1 vote
1 answer
2k views

Match Multiple Patterns in 2D Array and Return (x,y) Coordinates of the highest pattern

Problem Description We are given 2 arrays: 1 array representing the image and containing the patterns to be match and another one representing the pattern. Each image is represented as an vector ...
Hani Gotc's user avatar
  • 191
5 votes
4 answers
383 views

Check if a given string matches a wildcard pattern

I'm trying to optimize my solution to the following question: given a regular expression with chars and special char '*', (star which is a joker we can replace with any string), and a string, write a ...
Maor Rocky's user avatar
5 votes
2 answers
164 views

Separating data from string representation of objects, with added extras

Given a string representation of data, I want to extract the information into its corresponding object. However, If the string has "|" separators then these should be considered options and ...
Lewis Morris's user avatar
1 vote
0 answers
195 views

Idiomatic Rust matches with pattern guards

I'm quite new to Rust, and am working on a virtual machine image decompiler. I have some working code that uses match to check opcode numbers, but it doesn't feel ...
curiousdannii's user avatar