17 March 2024

McLaren 720S First Impressions (6 years too late)

Last week, I wasn't planning on stopping by my local dealer, McLaren NJ, on my way home from a morning drive. I caught up with Michael and Tevyn, who was shocked to hear that I had never driven a 720S (or any P14 car) and immediately offered a test drive. Only a fool would reject such an offer…

We hopped in a CPO 720S coupe with around 3k miles on the odometer and off we went!

720S specific comments:

  • The coupe door cutout helps a lot with ingress/egress. For some reason, I did not open the door enough on my way out and hit my head. Oh, the irony…
  • The visibility is INCREDIBLE. The two biggest changes I noticed compared to a P13 (570 platform) car are thinner A-pillars and a lot more rear visibility, thanks to the C-pillar glass.
    • My hot take is that the door roof cutouts plus the C-pillar glass are reasons to get the coupe over the spider.
  • The steering wheel has this lovely metal trim. I also really liked that this car had the small and clicky metal paddles instead of the longer carbon fiber paddles.
  • For some reason, this car was not equipped with an electrically adjustable steering column.
    • The sofas are still rock hard. Seat controls are still at the front of the seat on the side near the center console.
  • Steering heft feels approximately the same as a 570S/570GT, which is lighter than that of a 600LT or Artura.
  • As with Artura, steering+chassis seems to have filtered the smaller road imperfections, i.e. higher signal-to-noise ratio. This made the ride feel significantly more refined, but less exciting for my taste.
  • The trick hydraulic suspension really does wonders for ride comfort. I'd rate the ride in comfort mode about as well as that of a Lexus ES!
  • Carbon brakes bite _hard_.
  • I'm not sure how to describe, but the engine note under acceleration is less "aggressive" than that of the 570/P13 car.
  • No engine drone at highway cruising speeds!
    • I distinctly remember being disappointed by this during my (preproduction) Artura test drive back in June 2022 and Tevyn said that production cars don't drone.
  • The surround view parking camera is mediocre. The mirror video stream stitching is not cohesive with the front and rear cameras’.
    • Tevyn told me that the surround view camera is much better in the 750S. I forgot to try it when I drove the Artura a couple years ago.

22 June 2022

McLaren Artura First Impressions

 I was invited to test drive the Artura on 22 Jun. Thanks to McLaren NJ for hosting!

Artura specific comments:

  • Hybrid is very nice, in particular for stop-and-go. However, comfort mode holds EV mode for longer than my taste, leading to an impression of a lethargic car, especially when accelerating past 20mph (first mistake I made during the test drive).
  • Same great hydraulic steering rack with the heft of a 600LT's. Honestly the heft surprised me, as I expected a more "daily drivable" car to bias towards lighter steering.
  • Steering+chassis seems to have filtered the smaller road imperfections, i.e. higher signal-to-noise ratio. This made the ride feel significantly more refined, but less exciting for my taste.
  • V6 sound is tuned towards the lower octaves, as can be heard from various YouTube videos.
  • The sofas are softer than those in the 570 series, but not as plush as those in the GT.
  • The sofas don't go as far forward as expected, i.e. I had to slouch to be able to fully rest my foot on the dead pedal. If I were ordering a car, I would get the Clubsport seats with lumbar: I sat in these in the dummy car and thought they provided me the best seating position of any car that I have tried.
  • The seat controls have been moved to the side of the seat, consistent with the rest of the industry, and a departure from those in previous McLarens. I think new clients will highly welcome this change. See photo below!
  • Braking is indeed purely mechanical. The carbon brakes bite _hard_, as expected.
  • Rearward visibility is good, though not great like in the 720S coupe. I think the rear window is a bit larger than that of the 570S's.
  • Heard motor whine when accelerating at highway speeds, but no turbo whistle (at ~4k rpm).
  • Front lift works a couple seconds faster than that of the 570 series. You still to turn the car on (not just accessory mode), but the engine does not need to turn on to use the lift.
  • Engine still drones when cruising at ~1800rpm in 8th gear (~70mph).
  • I guess the new infotainment and CarPlay is nice.


  • I still prefer the short metal shift paddles to the carbon shift paddles.

tl;dr Artura is too soft and refined for my tastes; my parents would like it. Looking forward to the LT version (and also the GT4 race car)!

16 January 2022

Making Friends with Powers of 2

In the manga/anime series "Chihayafuru," the protagonist mentions that she "makes friends" with the universe of playing cards in her sport, Karuta, to help build a connection in hopes of achieving better results.

Note that all 2^n will be "the smallest positive even nth power," so I will omit from their descriptions. In combinatorics, 2^n is the size of the powerset for a size-N set.

1: self explanatory

2: self explanatory; the one and only even prime number; base 2/binary

4: self explanatory; all squares modulo 4 give residues 0 or 1 (prove it!); typical word size of a 32-bit Intel/AMD computer

8: number of ounces in a cup (go USA); typical word size of a 64-bit Intel/AMD computer; base 8/octal

16: 0xF + 1; base 16/hexadecimal; bits in a 2-byte integer

32: bits in a 4-byte integer; number of ounces in 1/4-gallon (smaller carton of milk)

64: bits in an 8-byte integer; number of ounces in half-gallon (larger carton of milk)

128: number of ounces in a gallon (jug of milk); amount of memory (in MB) in the first iPhone

256: 0xFF + 1; how much memory in MB my first Mac had

512: how much memory in MB my first computer had

1024: approximately interchangeable with 1000 = 10^3 for fast log2 and log10 computation; MB in a GB (or KB in a MB, or B in a KB, etc)

2048: seen in computer hardware flyers

4096: max memory (in MB) supported by 32-bit computers; seen in computer hardware flyers; pixel width of a true 4k screen

8192: seen in computer hardware flyers

16384: seen in computer hardware flyers

32768: one more than the largest positive value representable by a signed 16-bit integer

65536: bits in a 16-byte integer

131072: smallest power of 2 larger than 10^5 (common constant in programming problems)

262144: number of colours representable by a 18-bit panel when PC laptop makers were too cheap to use 24-bit panels in the 2000s; smallest power of 2 larger than 2*10^5 (common constant in programming problems)


1048576: smallest power of 2 greater than 10^6


16777216: number of colours representable by a 24-bit panel (before 10-bit "high colour" panels became popular)


1073741824: number of colours representable by a 30-bit panel (e.g. a "high colour" or "photography/video" panel); smallest power of 2 greater than 10^9

2147483648: one more than the largest positive value representable by a signed 32-bit integer

4294967296: number of different values representable by 32 bits


Something that starts with 9223 and has a lot of digits: 2^63 or 2^63-1, the latter is the largest positive value representable by a signed 64-bit integer

For these large values, e.g. 2^30 and up, I only know the first handful of digits, which is usually sufficient.


Writing these out, there are a few things that stand out to me:

  • much of these numbers are from computer-related activities, e.g. programming problems or browsing computer hardware brochures
  • the powers of 2 less than 100, especially those less than 10 (1, 2, 4), come up regularly for me in my day-to-day life

If you find special meaning to a power of two, leave a comment below! I may also write about other numbers, so stay tuned.

28 May 2021

Thought process on Codeforces 1353E

Link to problem

I remember seeing this problem almost a year ago during practice and getting stuck. Well, I finally solved it almost a year later!

Since the problem asks about equal spacing (of length K) between 1s in a binary string, I immediately  thought of numbers of 0s and 1s for each residue mod K. We have enough time to try each residue if the work for each residue is linearly proportional to the number of bits in each residue, i.e. K residues * (N / K) bits in each residue = O(N) total work. We know that while we are trying each residue, the bits at positions not congruent to K mod N have to be off, which is an easy precomputation done in O(N).

Our solution looks like this so far:

i64 solve(const i64 N, const i64 K, string_view S) {
  i64 total_on = 0;
  vec<i64> resid_on(K, 0);
  for (i64 i = 0; i < N; ++i) {
  	total_on += S[i] == '1';
    resid_on[i % K] += S[i] == '1';

  i64 best = N;
  for (i64 resid = 0; resid < K; ++resid) {
    let i64 turn_non_resid_off = total_on - resid_on[resid];

    // gather the bits at resid (mod K) for convenience
    vec<bool> seq;
    for (i64 i = resid; i < N; i += K) {
      seq.push_back(S[i] == '1');
    // TODO implement solve_resid
    let i64 subproblem_ans = solve_resid(seq);
    best = min(best, turn_non_resid_off + subproblem_ans);
  return best;

Let's focus on bits at positions whose residues are resid (mod K). We know that they have to form the pattern 0*1*0*, i.e. 1111, 00111, 1000, 0000, 010, etc. So we have reduced the main problem to this problem. How do we solve it?

At first, my smooth brain thought this could be done with greedy. My approach was ignore leading 0s, ignore the 1s after the leading 0s. At the same time, ignore trailing 0s, and ignore the 1s before trailing 0s. Now we want to turn all the bits on in the middle subsegment. However, this fails on a case like:

10 2


Because we can simply turn off one of the 1s rather turn on the 3 zeros in the middle.

At this point, my mind turned to dynamic programming. I started building my recurrences as follows:

  1. Define f(pos) = minimum moves to make the suffix [pos, N) valid.
  2. Define g(pos, state: {0, 1}) = minimum moves to make suffix [pos, N) valid such that bit at pos is state. This implies:
    1. g(pos, 1) = (pos != 1) + (moves to make the suffix [pos + 1, N) have the pattern 1*0*)
    2. g(pos, 0) = (pos != 0) + f(pos + 1)
and we want to solve for f(0), which is min(g(pos, *)). The wildcard used here and below represents all possible values for that argument, i.e. {0, 1} here.

This looks promising, but what is (moves to make the suffix [pos + 1, N) have the pattern 1*0*)?? It looked suspiciously "nice", i.e. something that I might be able to turn into a recurrence. OK, let's try that:
  1. Define h(pos, state) = minimum moves to make the suffix [pos, N) have the pattern 1*0*. This implies:
    1. h(pos, 1) = (pos != 1) + min(h(pos + 1, *))
    2. h(pos, 0) = \sum_{i = pos}^N (i != 0)
Well that was nice indeed. Putting it together by plugging h into g, we have:
  1. g(pos, 1) = (pos != 1) + min(h(pos + 1, *))
  2. g(pos, 0) = (pos != 0) + f(pos + 1), as before
Implementation is straightforward:

i64 solve_resid(const vec<bool>& seq) {
  vec<vec<i64>> h(seq.size() + 1, vec<i64>(2));
  for (i64 i = seq.size() - 1; i >= 0; --i) {
    h[i][0] = seq[i] + h[i + 1][0];
    h[i][1] = !seq[i] + min(h[i + 1][0], h[i + 1][1]);
  vec<vec<i64>> g(seq.size() + 1, vec<i64>(2));
  for (i64 i = seq.size() - 1; i >= 0; --i) {
  	g[i][0] =  seq[i] + min(g[i + 1][0], g[i + 1][1]);
    g[i][1] = !seq[i] + min(h[i + 1][0], h[i + 1][1]);
  return min(g.front()[0], g.front()[1]);

Voila, Accepted!

19 January 2021

FLPoTD: Writing Checks

This problem was inspired by a puzzle on the 2021 Mystery Hunt:

Given a string S of characters from the latin alphabet (a-z), find the smallest nonnegative amount (dollars and cents) whose spelled-out representation contains S as a subsequence.

  • The dollar amount should not include 'and': 123 is "one hundred twenty three", not "one hundred and twenty three".
  • If the amount is less than $1.00 (one dollar and zero cents), then the dollar amount is omitted: $0.46 is "forty six cents"
  • The cents is always expressed: $46.00 is "forty six dollars and zero cents"
  • This table contains the names of powers of 10: https://en.wikipedia.org/wiki/Power_of_10#Positive_powers
  • Given a list of strings, all of which use exclusively lowercase letters, find the most expensive word.

30 September 2020

Min-Max Driving Sim

I have always wanted a driving sim, especially after reading about fellow driver/instructor Ian Korf's positive experiences, but don't have much space and didn't want to spend a crazy amount of money.

To give you a sense of the driving sim landscape: on the low end, you have wheels without any force feedback (around the $99 mark) to 6-axis full motion sims for >$60k, which are not dissimilar what professional drivers use for training.

Here's what I got:

ComponentPrice (includes shipping & tax)
VendorWhen Purchased
WheelSimXperience Accuforce$1055.64simxperience.comJul 2020
ComputerDell Inspiron 3670$402.37Dell OutletDec 2018
GPUZotac GTX 1080 mini$369.00eBayFeb 2019
PedalsFanatec Clubsport v3$356.60eBayJun 2019
SeatPlayseat Challenge$242.93AmazonJul 2020
VR HeadsetLenovo Explorer$99.00B&H Photo VideoNov 2018
Power SupplyEVGA 500 W1$43.29AmazonJan 2019

I optimized for great driver inputs, e.g. the wheels and pedals. I figured that direct drive is the way to go, and read good things about the Accuforce. Popular alternatives included the OSW (OpenSimWheel) and the Fanatec Podium 1 & 2. I decided against hydraulic pedals (>$1+k, unless you mod your Logitech G920 brake pedal). Looking at options half an order of magnitude lower, the Fanatec Clubsport was the popular choice.

I wanted the sim rig to take up the smallest amount of space and be easy to move, while having a solid mount between the seat and pedals so that the pedals won't slide away from me during braking. The Playseat Challenge was the obvious choice. It even has mounting holes, which are compatible with the Accuforce!

I didn't want to spend very much money or effort on the PC, so I went with a refurbished Dell with passable specs. This unit has a 6-core i5-8500, 8GiB RAM, 1TB spinner, and integrated graphics. Obviously I needed a better GPU to drive the VR headset, so I went with a GTX 1080 (not Ti). It turns out that the current generation of consumer desktops are barely wider than a mATX board, so I need a shorter version of a full-size GPU. Finally, I needed a beefier PSU that the Dell's 300W unit.

If I insisted on building the PC myself, then the components (at the time of purchase, late 2018), would have not been much cheaper. The CPU retailed for $192, motherboard $80, memory $35, disk $40, for a total of $347, which is ~$20 less than the Dell cost before sales tax. (Obviously I would sit the parts on a piece of cardboard instead of getting a case, as well as ditching the optical drive and WiFi, if not integrated into the motherboard)

Finally, for an immersive experience, I went with the (now discontinued) Lenovo Explorer VR headset. I wanted something with at least a 1440x1440 eyepiece resolution since I had a bad experience with the first Oculus Rift, which had an eyepiece resolution of 1080x1280 -- I got extremely nauseous trying to focus on a blurry-to-my-20/13-vision image.

So there you have it! A solid setup, which fits conveniently into any corner:

For its inaugural drive, I spent an hour playing Assetto Corsa driving at the WeatherTech Raceway Laguna Seca in various cars (30min in a NA Miata, then a bit in a McLaren 570S, and the rest in a Porsche GT4 Clubsport). Works pretty well!

Its next upgrade will likely be a yoga mat since the Accuforce's vibrations are felt throughout the Playseat chassis.

06 September 2020

Codeforces Round #668 (Div. 2) Postmortem

Trying a different format with problem-by-problem breakdowns, which hopefully will be more useful when I review my postmortems. I will also backfill the postmortems.

A: I first implemented the metric computation (sort sums of adjacent elements) without having any idea of how to create a different permutation to achieve the same metric. Then I realized that reversing the input preserves the adjacent sums. I won't complain about a 0:02 submission.

B: If the first nonzero element were negative, then we have to incur cost equal to its magnitude. I thought this was it, but some sample inputs didn't pass. Then I noticed that if the first nonzero element were positive, we can add the magnitude to negative terms later in the array, which existed because of the constraint that all elements sum to 0 and that the sum stays 0 after every operation. I quickly patched my solution to keep a reserve from the magnitude of positive elements and using the reserve to decrease the cost of negative elements before incurring their costs. Again, not complaining about a 0:08 submission.

C: This is where I started to struggle. Having the same number of 0s as 1s in every K subarray is the same as the subarray sum equal to K/2. I got hung up on the "system of equations" representation, where every question mark was a variable (question mark at i would be a_i), which seemed extremely hard to solve. Then I thought that I can just look at the number of equations and the number of variables, which seemed sketchy, but I YOLO-ed and incurred a WA.

At about the 0:55 mark, I realized that the system of equations implied that a_i = a_j for i = j mod K. Facepalm. I quickly coded this solution for a 1:02 submission. RIP

D: Clearly, if B is at most DA away from A, then A can reach B in the first move and win. From the problem statement, I inferred that their 10^100 limit meant that either A will reach B in finite time, or B can always move to stay DA away from A. I quickly realized that the best chance of B dodging A is on the diameter of the tree, since in no other scenario will B have the space to run away from A. This implied that if A can go from the center(s) to the ends of the diameter in DA, then A can catch B.

I made the assumption that if DA > DB (it seemed intuitive), then A will be able to reach B eventually because B will run out of space. Thinking that these three criteria were sufficient, I submitted at 1:31 for my first WA on D. Given feedback that my solution failed pretest 2, I came up with the following counterexample to my solution:

        ^           ^
        A           B
DA = 2, DB = 3

My solution would incorrectly say that A never reaches B, while after two moves, A will first move from 3 to 5 and B will move from 6 to 3, letting A move from 5 to 3 on the third move. This really tripped me up, leading me to think about the relative difference between DA and DB. I tried that if the relative difference is larger than the half the diameter of the tree, then A cannot catch B, for another WA at 1:44. Finally, as a last ditch attempt, I thought that if DB is twice or more than DA and if the diameter is greater than twice DA, then A cannot catch B, for my third and final WA at 1:59.

25 June 2020

Educational Codeforces Round 90 Postmortem

What went well
  • B, C, D took me 5 minutes, 9 minutes, and 24 minutes respectively.
What went poorly
  • A took 21 minutes (drew a huge blank; no, I did not wake up late), which was a massive penalty, since it increases the penalties for B, C, and D.
  • Couldn't get E in an hour.
Where I got lucky
  • D was on the easier side.

23 June 2020

Codeforces Round #652 (Div. 2) Postmortem

What went well
  • 0:00 submission for A!
  • Got ABCD (albeit slowly).
What went poorly
  • Incurred one wrong answer for B and C each (and took a long time too).
  • Took half an hour to recognize the recursion for the tree structure in D.
  • Thought that the residues of numbers compare the same way as the the numbers themselves (i.e. a > b implies (a % m) > (b % m)…no, just no).
Where I got lucky
  • Got D with 9 minutes to go, which involved a slight wild guess.

21 June 2020

Codeforces Round #651 (Div. 2) Postmortem

What went well
  • Decently fast ABC (0:01, 0:10, 0:23).
What went wrong
  • Walled by D. I didn't recognize that binary search works because I didn't know how to verify that a subsequence with max less than or equal to a target value was doable in O(N).
  • I thought incorrectly (yet again) that O(N lg N) is too slow for N <= 10**6, so I tried something silly to find the minimum # subsequences of the form (01)+ or (10)+, when a straightforward O(N lg N) would have worked.
Where I got lucky
  • Gained rating!