Habr AI→ original

GLM-5.1 helped develop a new algorithm for analyzing bit strings

A C++ programmer asked GLM-5.1 + OpenCode to develop an algorithm for analyzing bit strings. AI created an original solution from known components. The author s

GLM-5.1 helped develop a new algorithm for analyzing bit strings
Source: Habr AI. Collage: Hamidun News.
◐ Listen to article

A C++ programmer proposed GLM-5.1 and OpenCode develop an algorithm for one of their tasks — and received an original solution that works.

The Task: Searching Bit Strings

Find all positions in a bit string where this condition holds: the number of ones minus the number of zeros up to this position equals a given number. This is a classic problem that appears in the context of RMQ (Range Maximum Query) and LCA (Lowest Common Ancestor) on data structures. The task is not trivial, but not new either. However, it requires careful implementation and optimization for C++.

What AI Came Up With

GLM-5.1 developed a solution composed of well-known components:

  • Prefix sums for counting ones and zeros
  • Hash table for tracking positions
  • Single-pass algorithm without redundant computations

The combination of these elements creates an original approach that the programmer might not have come up with immediately on their own. It's not a revolutionary algorithm, but a practical and efficient one.

How to Achieve Good C++

One of the main challenges is getting AI to write adequate C++ code. The article's author shares techniques:

  • Explicitly specify performance requirements
  • Ask for specific data structures (instead of general recommendations)
  • Check code for logical correctness before using it
  • Iterative improvement instead of full reliance on the first version
"This is not a celebration of AI — just an honest account of how tools

help in real work," — the article's author.

What This Means

AI assistants become useful not because of genius, but because of speed and a supporting role. The programmer remains the critical link, AI is a tool. For specialists who know how to work with tools, this saves time on routine code.

ZK
Hamidun News
AI news without noise. Daily editorial selection from 400+ sources. A product by Zhemal Khamidun, Head of AI at Alpina Digital.
What do you think?
Loading comments…