Skip to main content
7 votes
Accepted

Aho-Corasick algorithm implemented in C

references Woo hoo! You cite a reference for the underlying algorithm. Excellent. In the header comments for match(), nit: Minor grammar / typos. includes ...
J_H's user avatar
  • 29.4k
5 votes
Accepted

Separating data from string representation of objects, with added extras

Type hinting Instead of having helpdocs declare the types of function parameters, why not go with type hinting? Complexity Your code currently has too many moving parts. You define 2 different ...
hjpotter92's user avatar
  • 8,716
4 votes

Aho-Corasick algorithm implemented in C

To add to @J_H's good points: Only include what's required: In "aho_corasick.h", <stddef.h> should suffice for ...
Harith's user avatar
  • 9,120
4 votes

Structural Pattern Matching syntax to match a value in a list

Like you, I am excited about Python's new pattern matching. Unfortunately, I don't think your use case is a good fit. Every tool has strengths and weaknesses. In this specific situation, ordinary <...
FMc's user avatar
  • 12.8k
4 votes

Check if a given string matches a wildcard pattern

The code you wrote can be improved in lots of places. I'll go through it from top to bottom. #include <stdio.h> #include <string.h> Perfect until now. ...
Roland Illig's user avatar
  • 21.3k
4 votes
Accepted

A different approach to string pattern matching algorithm

A couple of comments on your answer: Code style If you've already stored the pattern.length(), why keep calling the method? Just be consistent and use that ...
Miguel Alorda's user avatar
3 votes
Accepted

Wildcard Matching: LeetCode 44

Nice code, good identifiers. if (tryMatch(s, sPos + loop, p, pPos + 1, max)) { In starMatch, don't we maybe get to ...
J_H's user avatar
  • 29.4k
3 votes

pattern matching coding challenge

your code looks fine - some minor issues: test driven developement if you have clear requirements, write test to validate them. "The method should pass the following tests" i hope you have ...
Martin Frank's user avatar
  • 2,838
3 votes

Structural Pattern Matching syntax to match a value in a list

I like your implementation as a whole, I do not think the if part you mentioned is the problem. [_, *middle, _] is a bigger ...
N3buchadnezzar's user avatar
3 votes
Accepted

Find repeating pattern in a string

main() void main() Oops: that's not a standard signature for main(). You probably meant <...
Toby Speight's user avatar
  • 77.1k
3 votes
Accepted

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

Your solution is overly complicated and not very efficient. First, since we are dealing with strings, you can use std::string::find() to check if a row from ...
G. Sliepen's user avatar
  • 58.3k
3 votes

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

This could be simplified by using straightforward composition: ...
gsuuon's user avatar
  • 141
2 votes

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

I would avoid using Option .IsNone and .Value, mainly because .Value will throw an exception ...
TheQuickBrownFox's user avatar
2 votes

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

Lets focus on filterByPattern. A Predicate is a function returning a boolean ('T -> bool). Since the predicate host most of ...
aloisdg's user avatar
  • 561
2 votes

Check if a given string matches a wildcard pattern

Move your main() to the bottom, so you don't have to declare other functions, it's also less prone to errors. '*' is not called ...
paladin's user avatar
  • 426
2 votes

Separating data from string representation of objects, with added extras

Here's an implementation whose major endeavour, when compared with your implementation as well as that of the accepted answer, is separation of parsing and execution. It's unclear whether this is ...
Reinderien's user avatar
  • 62.5k
2 votes
Accepted

State monad and pattern matching on data constructors

In general, you would extract the state using get and then case-match on it, like so: ...
K. A. Buhr's user avatar
2 votes
Accepted

Stepwise nested pattern mattching with exceptions

After tinkering around, I settled on this solution using optics and some type classes: ...
mingmingrr's user avatar
2 votes

Stepwise nested pattern mattching with exceptions

The amount of repeated code isn't large, I don't think that's worth worrying about. It does seem like you've got a lot of buried cases making your nice ...
ShapeOfMatter's user avatar
2 votes

Wildcard Matching: LeetCode 44

Make sure you match the required API Ideally, you wouldn't use a class Solution for this, and just create free functions. However, if you are given an API you have ...
G. Sliepen's user avatar
  • 58.3k
1 vote

Wildcard Matching: LeetCode 44 Attempt 2

Move your code out of class Solution I modified the method slightly. If you no longer feel bound by the interface imposed on you by LeetCode, then I would not put ...
G. Sliepen's user avatar
  • 58.3k
1 vote

PartialOrd of Rust Enums based on encapsulated data

You can match on a tuple, which flattens everything: ...
Francis Gagné's user avatar
1 vote

pattern matching coding challenge

null Nulls can be useful, however they can also be more trouble than their worth. Do you really need to use null, or could you get away with using "" ...
forsvarir's user avatar
  • 11.7k

Only top scored, non community-wiki answers of a minimum length are eligible