Articles are paginated with only three posts here for example. You can set the number of entries to show on this page with the “pagination” setting in the config file.
Posts
USACO Jan 2020 Bronze - Race
\(O(1)\) solution I am surprised that the solution posted is \(O(n)\) since \(n\) can be as large as \(10^9\).
In coming up with a solution for \(O(1)\) we consider three phases. The first phase accelerates the ‘left hand’ speed until it reaches the terminal speed. If it can’t reach the terminal speed then it just reaches whatever speed it can and terminates.
The second phase is like a palindrome stage, where I remove similar increasing speeds from both ends, kind of like climbing up a tall peak from both ends.
Posts
Minimax - alpha beta pruning
Normal pruning Imagine you are given the following problem: Find the depth of the the leaf closest to the root of a tree.
def smallest_depth(node, depth): if node is None: return depth - 1 a = smallest_depth(node.left, depth + 1) b = smallest_depth(node.right, depth + 1) return min(a, b) You could improve this a little bit by passing some information to your children:
def smallest_depth(node, smallest_sofar, depth): if node is None: return depth - 1 if depth >= smallest_sofar: return depth a = smallest_depth(node.
Posts
Appscript - Sheets
Getting started Appscript is pretty powerful and free, it is javascript with google api for manipulating things.
Begin with a sheets document. Open tools/script editor Write in Code.gs Rename to some Run with the triangle button Ctrl + Enter to see the Log Save it Since most of the time I am operating on some selected range, you would first select on some cells before running the script.
Posts
Bellman-Held-Karp Hamiltonian path and Traveling Salesman
Figure below with mypaint and a Bamboo tablet on Ubuntu Floyd-Warshall connection This section can be skipped, because it is basically my own brain mapping of this problem, since I feel there are some similarities with Floyd-Warshall.
For FW, I think of a source and destination pair \(i\) and \(j\) going through some intermediate node \(k\), and relaxing in a reverse triangle inequality kind of way, i.e.
\[ d[i][j] := \min(d[i][j], d[i][k] + d[k][j]) \]
Posts
Hugo: custom css, social-follow, svg, baseurl, comments
hugo social buttons It stated with wanting to add social buttons on my web page. This was as easy as changing the config.toml file. For Ananke theme, it is looking for some parameters, in the [params] sections. Just add you link to facebook, twitter, etc as facebook = "https://www.facebook.com/ID".
case of missing id I was upset that it had a slack link available, but no discord one. One because I don’t even know what is one’s slack id.
Posts
1320 Minimum Distance to Type a Word Using Two Fingers
Analysis of lee215’s solution Lee already explained fairly well how to get the 1D dp. I just want to expound a little bit because there is a heavy dose of intuition that I believe is very beneficial for other problems.
Intuition One of the first things that one tries when playing with this problem is figuring out when the second finger comes into the picture. I applaud the earlier posts in assuming a special starting position for both fingers, so that there is nothing special about when it transitions from one finger to two fingers.
Posts
Zookeeper 2.3
api We recapped re the API. Basically try to derive it yourself. Next divide which ones are write vs read related. Note that the read related contain a watch. Note that the write related contain a version. guarantees or promises Next we guessed what are zookeeper promises Why have these two promises Why A-linearizable? async vs sync what part of the writing is async? example is large configuration file what does it mean to be pipelined and issued asynchronously when a client issues a change, when does the system respond back with an ack?
Posts
Tree Depth - USACO Platimum Dec19
This is a commentary on the solution from Benjamin Qi.
from permutation to tree generation Before we go into the solution of this problem it is good to be able to understand how to create a tree using a permutation.
First how does a permutation \(a\) translate into a tree? Think of \(a[i]\) as the time in which node \(i\) is inserted to the tree. We’ll use the following \(a=42315\) for illustration.
Posts
Blackhole - Recording Sound Output in Macbook
blackhole installation https://github.com/ExistentialAudio/BlackHole
mix output command space - midi audio midi setup click on the plus sign at bottom left add a multi-output device should contain built in output and add blackhole you can adjust the volume (I can’t seem to be able to do that) setting the input there are two options all input command space - sound change the input to default to blackhole specific input quicktime start screen recording next to the record button there is a settings button arrow (small) set the device to blackhole
Posts
Rectangle counting
The problem is to count the number of rectangles (aligned to x and y coordinates) that can be formed by a set of points. Answer from competitive programmer Errichto.
def num_rect(points): m = defaultdict(lambda: 0) answer = 0 for p in points: for p_above in points: if p.y < p_above.y: answer += m[(p.y,p_above.y)] m[(p.y,p_above.y)] += 1 return answer Consider the following set of points:
x x x 1 2 3 This is for k = 3, there are 3 possible rectangles.