November 09 2023, 09:49

Remember, last time I wrote about the “homework” Liza had on bitwise operations for some Computer Science course, which blew my mind? A week later, Liza shared a new “homework,” and it blew my mind twice as much. There’s some assembler code, and we need to reconstruct a C function that generates such code, on a specific architecture (with access to gcc and as provided).

Overall, Liza is turning out to be quite a multifaceted architect.

November 08 2023, 09:23

(Thank you everyone, we figured out that it’s not an option. If the first segment (or a part of it) is not completed, the second is cancelled – which makes the whole idea unprofitable.)

We need to go to Turkey. A ticket to Budapest via Turkey costs $680, whereas a direct ticket to Turkey on the same dates and with the same Turkish Airline costs $1100. The difference for two exceeds $700 with taxes. It’s clear that one could buy a ticket to Budapest and simply exit in Turkey. But how do you tell the luggage not to go to Budapest?

And what about the return ticket? Is it possible to board midway through the journey?

November 07 2023, 11:44

Interestingly, the Gloria Jeans coffee shop has absolutely nothing to do with the Gloria Jeans stores in Russia, Kazakhstan, and Belarus. The coffee shop is American and has been around since 1979, named after its founder Gloria Jean Kvetko. So, jeans have nothing to do with it. Meanwhile, the Gloria Jeans company traces its history back to the Gloria cooperative, founded in 1988, and yes, they make jeans—and quite impressively, they produce a lot of them in their own factories, not in China. The story about them was about how the owner, Vladimir Melnikov, decided to pay one million rubles to all employees who had worked in the company for over 10 years.

November 06 2023, 11:47

Liza has a programming course at her institute where they study pure C, essentially it’s their first semester. By the third month of their study, they have to handle homework like this:

you need to write a function int isLess(int a, int b) using exclusively the operators ! ~ & ^ | + << >> and constants ranging from 0 to 255 inclusively without using large constants like 0xffffffff, without conditional structures and loops (if, do, while, for, switch, etc.), without macros, without calling any functions, no &&, ||, -, ?, no other data types besides int.

There’s an obvious answer y + (~x + 1) >> 31) & 1, which means subtracting y from x and then observing the sign. But for a pair of numbers -2147483648 [0x80000000] and 2147483647 [0x7fffffff] the algorithm fails—it returns zero, whereas the tests expect one. This is because it exceeds the 32 bits of int while calculating the difference.

Naturally, I asked both ChatGPT and Google Bard. No help from them; zero. They don’t understand the issue from the previous paragraph. And if they do understand, they suggest a dumb solution which is obviously non-working to the naked eye.

After an hour of tinkering, we finally found the right solution together. Liza did a great job, largely figuring things out herself, plus using Google search. The solution turned out to be very complex, but it works. It involved about 15 bitwise operations in the end. Once the functions have been combined and transformed into a single expression with parenthesis—as the task requirements specify—it’s impossible to understand what’s happening. I wonder if architecture universities cover programming.

Solution: ((~(((a ^ b) >> 31) ^ 1) ^ 1) & ((a + (~b + 1)) >> 31) & 1) | (((a ^ b) >> 31) & 1) & ((a >> 31) & 1);

The most interesting part is that when I ask Wolfram Alpha to simplify the expression, it simplifies it into something that fails the tests. It seems that Wolfram Alpha does not know about the 32-bit limitation either.