Posts

Showing posts from January, 2025

Standard Simplified RegEx Implementation II

A simple modification to the code shown in the previous post can accommodate a new capability in the RegEx. Suppose that you want to add a new capability to the RegEx: given a digit N in the RegEx (from 0-9), match any number of N characters in the input. For example, for the RegEx: "a2c", the following are valid matches: 1. "abbc" 2. "cccc" Whereas the string "abbbc" would be an invalid since between the 'a' and 'c' there are 3 characters instead of 2. The change in the code to implement this functionality in highlighted here . You can see that the structure of this code allows us relatively easily to add new functionalities to the RegEx. This is one of them, but one can imagine others such as "matching a minimum of N characters" instead of exactly N characters. Hope it is helpful - cheers, ACC. private bool HasMatch(string str, string regex, int strEndIndex, ...

Standard Simplified RegEx Implementation

Image
Although this problem constraints the regex to one "*", it is simple to extend the solution to multiple stars. Two important points to consider here: 1. Instead of doing string manipulation, just pass and manipulate indexes 2. Think about the base case and the induction case Time seems to be a higher side due to the recursion and extrapolation to handling multiple stars. Code is down below, cheers, ACC. Substring Matching Pattern - LeetCode You are given a string  s  and a pattern string  p , where  p  contains  exactly one   '*'  character. The  '*'  in  p  can be replaced with any sequence of zero or more characters. Return  true  if  p  can be made a  substring  of  s , and  false  otherwise.   Example 1: Input:   s = "leetcode", p = "ee*e" Output:   true Explanation: By replacing the  '*'  with  "tcod" , the substring  "eetcode"  matches th...

IBM Ponder This January 2025 - Regular and Bonus Questions

Image
The January 2025 edition of IBM’s Ponder This puzzle ( IBM Research | Ponder This | January 2025 Challenge ) turned out to be a fascinating (and somewhat tricky) exercise in applying search algorithms to a classic problem: measuring specific water volumes using three jugs. Even more challenging, there’s a bonus problem that requires finding an optimal rational volume for one of the jugs and demonstrating that 1 liter (with a very tight tolerance) can be measured in only 11 steps. In this blog post, I’ll walk you through: The puzzle description Key insights for solving it My C# solution (including the bonus) How the code works under the hood 1. Puzzle Description Here’s the short version of what the January 2025 IBM Ponder This puzzle asks: You have three jugs: Jug A has a volume of 5 \sqrt{5} liters. Jug B has a volume of 3 \sqrt{3} liters. Jug C has a volume of 2 \sqrt{2} liters. You can do only three types of operations: Fill a jug to the top (from a ta...