Algorithms. Physics. Mathematics. Machine Learning.
258 subscribers
131 photos
9 videos
1 file
60 links
DIY projects, fun with 3d, electronics, programming, vibe coding, math, ML algorithms.
Download Telegram
Old but gold

There seems to be two different problems. But really, it's the same problem.

1. Find the repeating and non-repeating parts of the decimal expansion of 1/n.
1/3 = 0.(3)
1/6 = 0.1(6)
2. For a singly linked list, check whether it contains a cycle.

Share your thoughts and ideas in the comments. Use the “spoiler” feature wisely. I’ll publish the canonical approach in 3 days, if needed.
👀2
The Deleted Photo

A long long time ago my colleague lent me a short-focused lens for my camera. I tested it for a week and this is my favorite shot from that week.

Just after I took this shot, it turned out the place was a police station and one of the police officers decided to teach my friend and me a lesson. He told us that it was forbidden to take photos of a strategically important facility and made us stay there for about two hours. It wasn't too bad because we were in the middle of some programming discussion and time flew by. Then the police officer asked me to show him the photos, without touching the camera and told me to delete this one. Then he let us go.

I was totally pissed off, because even from the preview screen I liked this shot very much. I turned off the camera and didn't touch it until I got home. Then I dove into photo recovery techniques. It was like "make an image of flash card onto my computer's drive; install a program that can recover files from a memory card image; start the recovery process ..." It wasn't easy, but I succeeded.

Enjoy the result!
🔥43
Periods in digits and remainders

I'm preparing a post with a solution for the first problem in the post . And there is a small question which has irked me for a while.

When we calculate digits of 1/n, there is a function which gives a digit from the remainder. So a cycle in the remainders leads to a period in digits, therefore period of digits can't be longer than period of the remainders. But why can't it be shorter?

I think that I have a glimpse of the idea, how to explain this. But if you have a good explanation, please share it.
👍1
Table with leaves

Who would guess that these wooden foldable panels on the sides of a table are "leaves"?
Not only decision trees and bushes have them.
Element of 2D sort

I don't have a fully cooked idea today, so let's discuss half-baked.

In The Farmer Was Replaced game there is a subgame where you plant cacti. Quite a complex description of game rules boils down to quite a simple idea: in order to make cacti harvest efficient, you are to sort 2D matrix of cacti heights. I.e. cacti become bigger when you move upward or to the right.

And, of course, there are limitations. You can move agent (drone) and it can swap a cactus under it with neighboring cacti. This prevents long-distance swaps, typical for traditional sorting algorithms like quicksort or merge sort and gives time complexity of O(n³) for n, the side length of the square field.

There is a global leaderboard in the game and the first place is 17 seconds for 8x8 field. My best attempt so far is 24.3 s. It's a 2D modification of insertion sort, I posted in here some time ago.

And today I'm going to try the approach in the picture. C - is the current drone position. Other letters - are the neighbors. Idea I want to test:
* write a tiny optimal procedure which sorts the cross in the order
* scan the field, apply the algorithm to each cell
* run insertion sort

My intuition is that this "cross local optimization" can cheaply move cacti far both in horizontal and vertical direction and it should take part of the load off insertion sort.
How Codex is built

I'm actively using the "Codex" agent in my work and it has always intrigued me how it works. I even wanted to find a repository with the source code and read it. Fortunately, today I stumbled upon a link to a post, where this topic is discussed. It explains the architecture and the engineering choices behind Codex.

I would summarize it as:
🤖 Codex is written in Rust
🤖 OpenAI uses Codex to build Codex
🤖 OpenAI developers multitask heavily with Codex
🤖 Skills are worth learning
🤖 Codex runs in a secure sandbox
🤖 Codex is a ReAct agent
🔥1
RAG is dead, long live agentic retrieval

Video touches a question I keep bumping into lately: do I actually need to learn RAG?

Very roughly: RAG is a way to preprocess your data into embeddings — high-dimensional vectors tied to chunks of text. During inference you retrieve the nearest chunks and feed them to the model so it has the “right” facts in front of it. If you have a text database with things that really shouldn’t be distorted, this helps reduce hallucinations.

The idea is elegant. The reality is messy. There are a lot of moving parts and a lot of “policies”: how to chunk, how to clean, how to embed, how to index, how to re-rank, what to cache, how to evaluate… It quickly becomes a whole universe where it’s easy to get lost.

In my current project I went the other way: no RAG. I just gave the agent tools like grep, cat, and a couple of small Python helpers it wrote for itself. According to the video, for agents working with codebases this is basically the SOTA approach: don’t overbuild retrieval, give the agent strong, direct access to the source of truth.

Extremely short version of the video:

📀For codebases: give the agent tools.
📀For other domains: RAG is still very relevant.

P.S. The phrase on the screenshot is from Yandex’s video summarization. It’s unintentionally hilarious.
Baghramyan mystery

I made these three photos of an escalator steps of Baghramyan metro station in Yerevan. These black and white triangles in the middle of the step intrigue me.

After the third attempt ChatGPT gave me close to the right explanation of this phenomenon. Let's try to beat it in the comments.
Web mirror of phys_math_dev is alive!

It was… kinda terrible.

Not when Codex wrote the code. Not when I deployed it to GitHub. It started when I logged into Cloudflare and began clicking around in the GUI.

The real pain came when Codex said: “Now you need to type in a dozen secrets.” Why?!! Sure, now I understand: you have to establish trust between Cloudflare, GitHub, and Telegram. But it’s not obvious at all. You bounce between different websites, copy-paste keys, IDs, tokens, and whatever else. And that little Python script that asked for my Telegram phone number and some mysterious confirmation still makes me shiver.

But anyway — it’s done. The mirror is live

It’s not ideal yet, and it definitely needs updates, but it works!
Baghramyan mystery revealed

Previously, I posted three mysterious photos. Today, let's solve the puzzle.

These triangles are the result of a strange coincidence. Shadows of handrails intersect in the middle of the step. So you see three zones:
I - brightest, lit by two lamps
II - mid shadow: lit by one lamp
III - deepest shadow: both lamps are blocked

Finally, there is a long "lever arm" in geometry, so a small shift of the lamps moves the shadows boundaries a lot. Near the bottom the bright zone dominates, near the top - the deep-shadow zone does.
Reality check

Yesterday I posted a hand-drawn sketch of the metro station. But I totally forgot that you can just take a photo of the place. Today, on the way to the office, I took this shot. Now you can compare the sketch and the photo and see whether my sketch was accurate.
🔥1
Childhood memory

While my next brainy post is baking, let me share with you a picture from my childhood.

I took this photo just today in the morning on my way to the office. The thing is that in 2026 in the Yerevan metro you can see exactly the same metal plates and signage I saw in 1989 in Moscow. Probably, this metro car was built 37 years ago at the Mytishchi Metro Car Factory and has been in use in the Yerevan metro ever since.
1
DIY. Physics laboratory

We started a small educational project. A short ride to the Vernisage flea market brought us:
⚗️ Holder for chemistry experiments
⚗️ 5 springs
⚗️ old Soviet set of weights

In a chat session with ChatGPT we explained that we aim at a worldwide site on which one can start the camera, point it at an oscillating object, get the time dependence of its displacement, extract frequencies from the signal and track experiment results. Iron Friend gave unexpected comment that putting a bright spot on the oscillating object can save us tons of work.

After some adjustments we finally got the result on the photos. Program detects the red spot on the picture, creates a mask (on the right) and writes the dependence of the vertical coordinate for the center of mass versus time. Lower image - the recorded curve.

Next steps:
📟 Calculate frequencies of components (Prony's algorithm)
📈 Track frequency change versus mass change

In general, I want to use this setup to cover the following topics:
✒️ frequency dependence on mass for elastic restoring force
✒️ frequency dependence on pendulum length
✒️ expressions for effective spring constant for series and parallel spring connections

The current state of the project
🔥3
Mystery code

Later I'm going to explain in detail, what is going on. For now I'm curious whether this subject is trivial. If you can, feel free to answer the following questions in the comments:

How come that the guessed highlighted numbers in the beginning of the post match restored at the end?
What's the connection with the previous post ?
What physics can be connected to this math?
3
How to survive in the new reality

Probably the best explanation "How to stop worrying and love agents."

In order to succeed you have to:
🟢 Hone your expertise
🟢 Use LLMs as chat, agents, tools - whatever helps you move faster

There is no silver bullet. You buy this AI fluency only by paying with hundreds of hours of trial and error.

Stolen from here (russian)
I'm not totally original

While I was digging into this area on my own, with heavy help from ChatGPT, of course, I never expected that I have a completely new result.

On Monday my colleagues and I discussed how a linear model drops out of Bayesian probability formulas and the book from the attachment was mentioned. It turns out "my" expressions are in there too - see the references in the picture.