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
6*6 to a really round number

One more number I can't leave unnoticed. It is not a true round number, but I can see a few interesting facts here.

First of all, it's the voltage of household outlets. I can't help but mention the joke "By using this outlet you have a 160V bonus"

I'm really waiting for 100000000₂, and there are only 6*6 subscribers left to this rooooound number.

Due to vector algebra, three-phase symmetry, and the properties of complex numbers, √3​⋅220≈1.73⋅220≈380
4
This media is not supported in your browser
VIEW IN TELEGRAM
Simple wood farm

It's a simple wood farm for the beginning of the game.

def best_move(d1, n1, d2, n2):
d, n = ((d1, n1), (d2, n2))[n2 < n1]
for _ in range(n):
move(d)

def nav(x2, y2):
x1, y1 = get_pos_x(), get_pos_y()
n = get_world_size()
best_move(East, (x2 - x1) % n, West, (x1 - x2) % n)
best_move(North, (y2 - y1) % n, South, (y1 - y2) % n)

n = 6
set_world_size(n)
while True:
for y in range(n):
for x in range(n):
nav(x, y)
p = Entities.Tree
if (x + y) % 2:
p = Entities.Bush
if can_harvest():
harvest()
plant(p)


Let's check some interesting moments.

First of all, I like nav function a lot. It allows to write a clean and concise code. Write once, use forever. Until you need a heavy optimization, but it's a different story.

n = 6
set_world_size(n)


I have quite an advanced farm, these lines shrink it back into the "beginning of the game" state. In the beginning of the game you had better use

n = get_world_size()


while True:

Let's repeat our harvesting.

  for y in range(n):
for x in range(n):
nav(x, y)

We traverse the whole board.

      p = Entities.Tree
if (x + y) % 2:
p = Entities.Bush


a chessboard pattern for bushes and trees. Allows trees to grow fast.

      if can_harvest():
harvest()

quite an important trick. Prevents young trees from being chopped down. Without this "if" one can chop a tree without getting a reward for it.

plant(p)

plant the plant again.

Happy woodchopping!!!
👍1
Marionette Codex

Today I want to share one technical insight.

Suppose you are building your own project and you want to add an agent into it. At first glance, it sounds simple: send a prompt, get an answer, repeat, call a tool.

But very quickly it turns out that writing your own harness is not simple at all.

A useful agent must be able to inspect files, write tiny code snippets, run commands, patch something, continue the conversation, call tools, and do all this in a secure and flexible way. Supporting such a thing yourself is a hell on Earth.

The nice trick is: you do not need to write all this stuff yourself.

You can just call Codex with a few flags. OpenAI documents codex exec as the non-interactive mode for scripts and automation, --json for machine-readable JSONL events, and codex exec resume for continuing an earlier automation run.

Something in this spirit:

codex exec --json --skip-git-repo-check --model <model> "<prompt>"


Then on the next turn:

codex exec resume <thread_id> --json --skip-git-repo-check --model <model> "<prompt>"


This leads to a very neat architecture:

one turn = one subprocess materialization
state = session id stored by Codex outside your app
control loop = fully yours

And this is the part I like most.

You reuse the whole safety and tool-calling machinery already built into Codex, while still having total control over the agent loop in your own application. By default codex exec runs in a read-only sandbox, while --full-auto switches to a lower-friction mode with approvals on request and workspace-write sandboxing.

So the agent is not some giant subsystem embedded into your codebase.

It is just your loop around Codex, with Codex keeping the conversation state on its side.

If I had to compress the whole idea into one sentence:

Use Codex as an external agent engine: launch it turn by turn, keep the session id, and build your own loop around it.

UPD: community shared a piece of knowledge. One can use agentic SDK for such things. Will try. Stay tuned.
🔥3👾2
Tasks and Ribbons

There is a famous problem, that comes up from time to time. I stumbled upon it in several interviews with Big Tech companies.

It has different statements. Sometimes it's like "there are a lot of meetings, you have start and end times,what's the max number of meetings overlapping at some moment in time?". Sometimes: "There is a red ribbon starting at 0 and ends at "a" and several blue ribbons, you have their start points and ends in an array. Is some piece of red ribbon is visible?"

My favorite approach to this class of problems is to split each ribbon (or meeting) into a stream of events: start of meeting, end of meeting (or scanning line meets ribbon, scanning line leaves ribbon).

Then you sort this stream of events and process it. Here you are to pay attention. Because tuples (x, 1) and (x, -1) which correspond to opening and closing events tend to go in unpleasant order. So, either you are to sort in reverse order for the second tuple component, or you introduce weird notation for an opening event as (x, -1) and for closing (x, 1).

So, a lot of nuances. And you really have to think about all this weird stuff, until you are to materialize your count as an array. In this case you can use hash maps and to store the number of opening and closing events at each point. The code is nice and simple.

And one more idea. When you are asked to maximize dot product of two arrays with non-negative numbers, sort them, multiply elements pairwise and sum results.

If this topic is interesting and you want to discuss program line by line, react with 🔥
👍2🔥2
In the friendly chat we have a friendly dispute on:

whether you are to code programs by hand when you are studying. You can find theses in comments to the post. Your opinion is important!
Anonymous Poll
64%
You are to write code by hand when studying
9%
It's enough just to read
27%
It's Friday, dudes!
In the poll reference to the "friendly chat" didn't appeared. So:

friendly channel

friendly chat

friendly message

Links are not quite working, figuring out why...
#shitposting #meme

It's Friday!

Last week I found a channel and I want to share some content because it's hilarious. I spent Monday skimming through it. It turned out that these memes are universal and can be applied to quite a wide range of situations. For example, I used the first picture today, while presenting my work from the past two weeks.
4
Yesterday I tried to make the first in the history of this channel memeshitposting. The idea is to do it once a week. What do you think?
Anonymous Poll
7%
no memes, just ML, math and hardcore
73%
memes ok, no obscenities
7%
more memes, no math, phys
13%
Who am I? What do you want from me?
Titanic. Embarkation

In previous posts we started exploratory data analysis of the Titanic dataset. We already checked the list of features and checked whether age is a useful feature.

This time let's talk about the embarked feature. It is about the place where a passenger embarked on the ship. We can think about this feature in two modes: wearing an ML engineer hat, or wearing an analyst hat. For an ML engineer, it is quite enough to have a strong connection between a feature and the target to include the feature into the dataset and train a model. An analyst is a little more curious creature. They would ask more questions. What is the nature of the connection between embarkation and survival? How does this feature interact with other features?

Let's check the picture. I'm more than confident that it is not totally accurate, but I hope it is correct in the most important aspect: the order of ports. Before I checked this order, I had a very naive hypothesis that passengers who embarked earlier had a better chance to leave the ship, so their survival rate is higher. But that can't be the case for two reasons. First of all, the dataset contains records of all passengers who were on board at the moment of the disaster. Second, passengers from the last stop had the best chances.

The real reason seems to be a little more subtle. In "S" there were a lot of crew and third-class passengers, and later we will see that it was bad to be a third-class man on Titanic (oops, spoiler). Therefore, embarked could be a proxy feature for economic status.
2👍2🔥1