Posts

On the Zeroes of the Riemann Zeta Function using Von Mangoldt function

Image
Recently I was watching a Numberphile about the solution to the Riemann Hypothesis (RH). This was the video:  EET324 Class 24 One thing intrigued me when the author was talking about the explanation of the RH using the Von Mangoldt function, in particular I saw this part of the video: There is a way to implement this function and get to an alternative view of the RH. I decided to implement the Van Mangoldt function, using some simple techniques (Sieve, Binary Search, and so on). No GAI used. The interesting part is that this number in the chart below should have an upper bound of 1/2 (green light) when X goes to infinite. Hard to see in this small example (100k), but if the calculations are right in my code and the RH is true, it will continue as an upper bound. This is the famous 1/2 line in the RH. Code down below, cheers, ACC. using System; using System.CodeDom; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace RH { ...

Standard Finite-State-Machine (FSM) Implementation - II

Image
There are multiple ways to solve this problem, but I find a state machine implementation very intuitive, even if we have to leave some of the state transitions empty (no-op). The state manages whether you're in "same char" mode or "different char". Code is down below, cheers, ACC. Find Mismatched Segments Between Two Strings - LeetCode You are given two strings s1 and s2 of the same length. A mismatched segment is a maximal contiguous range of indices where the characters of s1 and s2 differ at every index. Return a 2D array containing [sub1, sub2] for each mismatched segment, where sub1 and sub2 are the corresponding substrings from s1 and s2 , respectively. Return the segments in increasing order of their starting indices. If there are no mismatched segments, return an empty array. A substring is a contiguous non-empty sequence of characters within a string.   Example 1: Input: s1 = "earth", s2 = "empty" Output: [["ar...

Sliding Window Technique - Part 14

Image
A bit of vintage coding, no GAI involved. This is a sliding window problem, it is a bit tricky because you have to maintain not only the numbers in the candidate subarray but also the sum of pairs in that subarray, so two different data structures (I used hash tables but you can use other dictionary data structures) to keep this information. You need to update both of them accordingly when moving either the right pointer or the left one. Complexity is N^2 (N==1000) however the usage of untyped hash tables is slowing down the constant significantly, there are other ways especially given that the numbers in the array are small-bounded. Code is down below, cheers, ACC. Longest Subarray With Restricted Pair Sums - LeetCode You are given an integer array nums . A subarray nums[l..r] is valid if there are no three distinct indices i , j , and k such that l <= i, j, k <= r and: nums[i] + nums[j] == nums[k] Return the maximum length of a valid subarray of nums .   Example 1: In...