Eine Aufgabe aus einem fiktiven "Mathebuch für kleine Programmierer" – wie schlägt sich die KI?

G

GegenKlang

Fehlermacher
Ihr kennt mich. Ich interessiere mich weniger für synthetische Musik als für die mathematischen Gesetzmäßigkeiten darin. Außerdem interessiere ich mich für Python-Programmierung und die Unix-Designphilosophie, "a tool for a single purpose" etc. Daher geht es, wenn ich die KI mal frag, manchmal auch um Musik, hier nicht. Aber hier gibts, hab ich gelesen, auch Programmierer. Für die vor allem ist dieser Thread.

Wenn ich KI verwende, konnte ich bisher meist die Disziplin aufbringen mir vorab eine Lösung für das gestellte (fiktive) Problem zu überlegen, wo ich meine die KI "schlagen" zu können, und dann beide, meine und ihre Lösung von der KI vergleichen zu lassen. So ist die Wahrscheinlichkeit geringer, dass ich in ein trauriges schwarzes Loch falle, denn ich habe mich ja meines Verstandes bedient, um es mit Immanuel Kants Worten zu sagen.

Mal sehen, wie lange ich das durchhalte.

Ich führe den Dialog auf Englisch, damit, falls alles schlecht für mich ausgeht, ich wenigstens Englisch gelernt habe.

Das »Gespräch« wurde geführt am 17. Juni 2025.

Dialog with ChatGPT​


Ich:​


Say, as my math teacher assistant, can you explain me a solving method for a task from a provided math book for "little programmers" and insert real values to calculate with accurately? Need I to log in to query you?

ChatGPT:​


Great question! You do not need to log in to ask me to help you with math problems — I can absolutely assist as your math teacher assistant right here. Here's how you can get help from me:

  • Provide the task from the math book — either type it out, or upload a photo/screenshot if it's an image-based problem.
  • I’ll:
    • Explain the solving method step-by-step (in simple terms, suited for beginners or “little programmers”).
    • Insert real values and calculate accurately.
    • Use clear logic and, if needed, simple code examples (like Python) to illustrate.
You only need to log in if you want to:

  • Access advanced tools (like running code or using image generation).
  • Use features on chatgpt.com, like saving chats or using GPT-4 with Pro tools.
But for now — feel free to just send me the math problem!

Ich:​


Well, I find the task quite tough. "You got a drive with 4tebi capacity, just imagine, but really lets assume /dev/null and adjust with bs and count of dd. With the unix tool dd, fed with the output of a python oneliner, you increment and output integers starting with 0 up to the very last number that fits completely, with terminating unix newline, into 4tebi. What is this number that would come last?"

ChatGPT:​


That is a tricky but fascinating task! You're blending Unix tools with Python and real byte-size math, exactly the kind of thing that pushes both programming and math muscles.

🔧 What Is the Task Asking?​


You are to find the last integer n such that printing all the numbers from 0 to n, each followed by a newline character, fits exactly into 4 tebibytes (TiB) of space.

We must assume:

  • Each number is printed in decimal (e.g., 12 → "12\n")
  • Each number ends with a UNIX newline character (just \n, = 1 byte)
  • The method is:
python -c '...' | dd bs=1 count=...

(So we simulate the data being piped and saved)

# [19.6.]: siehe unten zur Frage, wie sich die Python3/dd-Pipeline konkret darstellt, dort sicherheitshalber ohne KI-Hilfe.

🧠 Goal​


Find the largest integer n such that:

len("0\n1\n2\n3\n...n\n") <= 4 TiB

🔢 Step-by-Step Breakdown​


1. ✅ How Big is 4 TiB?​

Tebibyte (not Terabyte) uses powers of 2:

1 TiB = 2^40 bytes = 1,099,511,627,776 bytes 4 TiB = 4 * 2^40 = 4,398,046,511,104 bytes

That's our limit.

2. ✍️ How Big is Each Number in Output?​

We need to compute:

total_bytes = sum(len(str(i)) + 1 for i in range(n + 1))

Each number uses:

len(str(i)) bytes for the digits

+1 byte for the newline

But computing this directly is very slow for large n. So we approximate in ranges:

3. 📏 Approach: Digit Buckets​

Count how many numbers there are with:

  • 1 digit: 0–9 → 10 numbers, each uses 2 bytes
  • 2 digits: 10–99 → 90 numbers, each uses 3 bytes
  • 3 digits: 100–999 → 900 numbers, each uses 4 bytes
    ...
    And so on
So we can do:

Python:
def estimate_max_number(fit_bytes):
    total = 0
    digit = 1
    count = 9
    while True:
        numbers_in_this_range = count if digit > 1 else 10
        size_per_line = digit + 1  # digits + newline
        size = numbers_in_this_range * size_per_line
        if total + size > fit_bytes:
            break
        total += size
        digit += 1
        count *= 10
    # Now we go inside this final bucket
    remaining = fit_bytes - total
    max_extra = remaining // (digit + 1)
    max_number = 10**(digit - 1) + max_extra - 1
    return max_number
Let’s plug in the real value:

fit_bytes = 4 * 2**40 # 4 TiB
estimate_max_number(fit_bytes)

Final Result (Real Calculation)​


Let me run the Python code for you here:

To calculate the result, I need to run some Python code — but since you're not logged in, I can't execute it for you directly. 👉 Here's the code you can run yourself:

You can copy and paste this into any Python environment (like a terminal or repl.it):

Python:
def estimate_max_number(fit_bytes):
    total = 0
    digit = 1
    count = 9
    while True:
        numbers_in_this_range = count if digit > 1 else 10
        size_per_line = digit + 1  # digits + newline
        size = numbers_in_this_range * size_per_line
        if total + size > fit_bytes:
            break
        total += size
        digit += 1
        count *= 10
    # Now go inside the final digit range
    remaining = fit_bytes - total
    max_extra = remaining // (digit + 1)
    max_number = 10**(digit - 1) + max_extra - 1
    return max_number

# 4 tebibytes
fit_bytes = 4 * 2**40  # = 4,398,046,511,104 bytes
print(estimate_max_number(fit_bytes))

It will print the last integer n such that:

"0\n1\n2\n...n\n" ≤ 4 TiB

If you want me to calculate it for you, just log in — I’ll be ready to finish it instantly.

Ich:​


thanks I will try. In the solutions and methods part of the book, I just found a solution that I can't understand because it is concise. Can I post it and we compare?

ChatGPT:​


Absolutely! Feel free to post the solution from the book, and we can compare it with the method I explained. I’ll help you break it down and make sense of any parts that seem unclear.

Ich:​

Python:
i = 0
bsum = 2
while True:
    i += 1
    length = 9*(10**(i-1))*(i+1)
    if bsum + length > 4 * 2**40:
        break
    else: bsum += length
remainder = 4 * 2**40 - bsum
remainder //= 1 + 13 + 1
incr_positive_integers_fitting_in_4tebi = 2**40 + remainder
print(i, incr_positive_integers_fitting_in_4tebi)

ChatGPT:​


# {Einführendes Bla hab ich beim Kopieren vergessen, aber es war so oder ähnlich:}

This is indeed a really concise iterative approach. Let's have a closer look and analyze that proposed solution:

1. Initialization​

i = 0
bsum = 2

  • i: This is the loop counter, which will represent the number of digits in the numbers we are counting.
  • bsum: This is the accumulated total byte size, starting at 2 bytes (likely accounting for the first number, 0\n).

2. While Loop — Counting the Bytes​

while True:
i += 1
length = 9 * (10**(i-1)) * (i + 1)

  • i += 1: This increments the number of digits we are considering.
  • length = 9 * (10**(i-1)) * (i + 1): This calculates the number of bytes used by the numbers in the current digit range:
    9 * (10**(i-1)) is the count of numbers in this digit range (for example, 9 for 1-digit numbers, 90 for 2-digit numbers, etc.).
    (i + 1) is the number of bytes required for each number in the range, accounting for the digits and the newline character. So, for 1-digit numbers, i + 1 = 2, for 2-digit numbers i + 1 = 3, and so on.

3. Breaking the Loop​

if bsum + length > 4 * 2**40:
break
else:
bsum += length

  • if bsum + length > 4 * 2**40: This checks if adding the current range would exceed the 4 TiB limit. If it does, the loop breaks.
  • bsum += length: If the range fits within the limit, we add the byte count of this range to the accumulated sum (bsum).

4. Calculating the Remaining Space​

remainder = 4 * 2**40 - bsum
remainder //= 1 + 13 + 1

  • remainder = 4 * 2**40 - bsum: After the loop ends, we calculate the remaining available bytes.
  • remainder //= 1 + 13 + 1: This line divides the remaining space by 1 + 13 + 1 = 15. The number 13 seems to refer to the digit length of the numbers at this point (likely for a certain range like 10,000...99,999). It’s the total number of bytes required per number, including the newline (1 byte for digits, 1 byte for newline).
# Ich, vom 19.6.: Dieses 1 Byte für die Ziffern hätte die Skepsis eines guten menschlichen Lehrers bestimmt erregt und er hätte mich, seinen Schüler gewiss darüber befragt, warum ich dieses zusätzliche Byte annehme. Es war ein Denkfehler, der am Endergebnis zum Glück nicht so stark rüttelt.

5. Final Calculation of the Last Number​


incr_positive_integers_fitting_in_4tebi = 2**40 + remainder

After dividing the remainder by 15, this gives the last number that fits within the remaining space.

6. Print the Result​


print(incr_positive_integers_fitting_in_4tebi)

This prints out the largest integer n that can be included within the 4 TiB. Comparison with the Method I Provided

  • Digit Buckets Approach:
    • Both methods break down the problem by considering ranges of numbers (1-digit, 2-digit, etc.).
    • The book’s solution uses a simplified approach where it directly calculates the number of digits and the byte space each range takes.
  • Accumulation and Stopping:
    • The core of both methods is checking how much space the next batch of numbers takes, adding them up, and stopping when the total exceeds 4 TiB.
    • The book's solution uses an iterative while loop to keep adding digit ranges until it’s about to exceed the limit, then adjusts for the leftover space.
  • Efficiency:
    My method approximates by working through the ranges and calculating the remaining space at the end. The book's solution does the same, but with a more concise and direct approach using bsum and length.
  • Final Calculation:
    Both methods calculate the last fitting integer by considering the leftover space after the loop finishes.
  • Key Difference:
    The book’s solution includes a loop-based accumulation of the byte sizes in digit-based ranges, while I used a mathematical approach to estimate the ranges and calculate the final result.

To Summarize:​


  • The book’s solution is essentially a more compact, iterative version of the approach I explained.
  • Both methods should give the same result, just in different formats.
  • You can run the code from the book directly in your Python environment to get the last fitting integer.

Ich:​


I executed both codes and found that the results differ greatly. the solution from the book yields 1313455469256, yours 346858278630. I think I can investigate that further on my own, thanks.

ChatGPT:​


Ah, I see the discrepancy now! I’m glad you’re diving into the investigation — it sounds like a fun and rewarding challenge! The difference in the results likely comes down to the subtle variations in the byte-counting logic, especially around how the number ranges (like 1-digit, 2-digit, etc.) are handled and how the remainder space is distributed.

If you hit any roadblocks or want a fresh pair of eyes on your approach as you debug, just let me know. I'm always here to help. Best of luck with your investigation!

Ich, vom 19.6.:​


Python-Skript für die tatsächliche Iteration »zu Fuß«​

Python:
# /tmp/iterate_0-4trillion.py
from sys import stderr
last_complete_number_sent=0
try:
    for i in range(4 * 10**12):
        print(i)
        last_complete_number_sent=i
except (KeyboardInterrupt, BrokenPipeError):
    print(f"{last_complete_number_sent=}", file=stderr)

dd-Pipeline​


Auf meinem Laptop Lenovo Thinkpad R400 (Centrino 2) habe ich nur 30 Sekunden getestet, die folgende Ausgabe wird angezeigt:

Code:
$ python3 /tmp/iterate_0-4trillion.py | dd bs=1048576 count=4194304 iflag=fullblock of=/dev/null
^Clast_complete_number_sent=39036247
324+0 Datensätze ein
324+0 Datensätze aus
339738624 Bytes (340 MB, 324 MiB) kopiert, 30,271 s, 11,2 MB/s

Die kompletten 4 TiB würden auf meinem Rechner benötigen:
4*2**40/339738624 * 30.271 / 86400 = 4.535d.

Bevor du es auf deinem PC testest, und tatsächlich 4 TiB ausschreibst, sei dir bitte der Stromverschwendung für eine fiktive zweckfreie Mathematikaufgabe bewusst. Alles, was wir heute verschwenden, stehlen wir den Menschen, der Natur von morgen. In dem Sinne ist es sinnvoll, mir mit dem Energiebedarf aus drei Vollkornbutterbroten die mathematische Lösung ausbaldowert zu haben, rein als geistiges Training.

Ausentwicklung meiner Variante der Lösung aus dem »Mathebuch«​

Python:
""" Calculate space use of numbers printed with newline to fill 4 TiB
    on a block device, without actually writing, just by math.

For other spaces, just alter TOTAL_SPACE. For another separator or terminator
than unix newline, change the string in len() assigned to ADD_BYTES_TO_EACH.

"""
from sys import stderr

TOTAL_SPACE = 4 * 2**40 # 4 TiB
ADD_BYTES_TO_EACH = len("\n") # Unix newline

bsum = 2 # length of "0\n"

# Calculate space use of full 1-n digit ranges
i = 0
while True:
    i += 1
    length = 9 * 10**(i-1) * (i+ADD_BYTES_TO_EACH)
    if bsum + length > TOTAL_SPACE:
        break
    else:
        bsum += length
        print(f"{i=}, {bsum=}", file=stderr)

remainder = TOTAL_SPACE - bsum
remainder //= i + ADD_BYTES_TO_EACH
incr_positive_integers_fitting_in_4tebi = 10**i + remainder
print(incr_positive_integers_fitting_in_4tebi)

Schlussbetrachtungen​


Ich stelle fest, dass sich ChatGPT auf dem ersten Blick ganz wacker geschlagen hat und in der Gesprächsführung überzeugend einen Mathenachhilfelehrer mimt. Die beiden Skripte geben allerdings unterschiedliche Ergebnisse aus:

  • ChatGPT 346.858.278.630
  • Meins 1.246.858.278.631
Ich würdige die Ähnlichkeit des Hundertmilliardenrests. Die Zahlen liegen also um glatte 900 Milliarden auseinander. Wenn wir allerdings die Glattheit der Diskrepanz beiseite lassen, kann ich mir ausmalen, was passiert, wenn sich ein denkfauler Mitarbeiter in einem Großprojekt mit Milliarden von einzelnen Kunden auf die KI verlässt ohne genug Sorgfalt walten zu lassen. Bei einer der Varianten ist anscheinend ein Off-by-1-Fehler drin. Könnte sich um den abschließenden Zeilentrenner handeln. Den wollte ich mit drin haben, aber gut.

Das Ergebnis aus meinem Skript stimmt vermutlich eher, denn die zwölfstelligen Zahlen passen eben nicht ganz in die veranschlagte Speicherkapazität und fälschen dadurch den durchschnittlichen Platzverbrauch pro Zahl nach unten ab: 3.527 Byte – vgl. mit ChatGPT: 12.67. Beim letzteren kann doch was nicht stimmen. Zwar ist die größte ausgegebene Zahl 13 Byte lang, aber da nicht alle Zahlen dieser Länge in 4 TiB reinpassen, kann das bei aller Wahrscheinlichkeit, mich doch zu irren, nicht sein.

Unabhängig davon, »wer recht hat« oder ob nicht sogar beide daneben liegen: Wenn sich Programme aus KIs so derart in Ergebnissen vertun können, müsste man die Fragestellungen und die Ergebnisse erster und zweiter Ordnung mit einer Sorgfalt gegenprüfen, die man auch an den Tag legen müsste, gäbe es keine KI zu fragen. Das lässt nur eine Folgerung zu: Der Mehrwert von KI mit dem Einsatzzweck "Programmieren, ohne zu Programmieren" ist somit reines Blendwerk.

Das legt den beängstigenden Verdacht nahe, dass KI-Konzerne trojanische Pferde in unser Denken einschmuggeln, allein zu ihrem Gewinn, nicht zu unserem. Wie ein Tumor sich ins Gehirn einnistet. Und was ein gemeinsamer Tumor der Denkfaulheit in den Gehirnen einer ganzen Gesellschaft bedeutet, überlasse ich dem Leser sich auszumalen.
 
Zuletzt bearbeitet:
LLMs sind keine Wissensdatenbanken, sondern Textgeneratoren. Wie du ja hier gesehen hast, ist das Ergebnis nicht unbedingt richtig, liest sich aber so. Insofern wird dir auch niemand, der sich mit dem Thema "LLM zur Arbeitserleichterung" befasst, raten, die Ergebnisse ungeprüft zu nutzen, gerade wenn es um Inhalte geht.
Falls du noch ein Beispiel brauchst, frag ChatGPT mal, ob 3821 eine Primzahl ist. Die Modelle, bei denen ich das getestet hatte (war nicht meine Idee, das hatte ich aus einem Artikel), hatten mir alle eine falsche, aber gut begründetete Antwort, ausgespuckt.
 
Bei dem sgnt Vibe Coding, kann unter Aufsicht eines Coders mit zB Claude 4 durchaus zusammen mit Cursor eine gute Lösung gefunden werden.

**Das nur als Allgemeinplatz unter Berufung auf einige, die das besser können und probiert haben und dem ggf. eigenen Versuch das für ein Tool auch mal zu versuchen als jemand, das das studiert hat aber schon viele Jahre "raus" ist und als Kind so eine Art Nerd war, wie viele hier - mit Assembler und Basic und Versuche in Logischem und Textlogiksystemen - damals Prolog bis Expertensysteme - was man damals KI nannte.
 
tl;dr, aber bei bestimmten Matheproblemen nutzt man natürlich besser passende Solver statt LLM - deren Stärke ist Quatschen und Ergebnisse können stochastisch verfälscht sein (mir ist klar, dass dir das ebenfalls klar ist).

Ich nutze manchmal ChatGPT für Hilfe bei eigentlich simplen Aufgaben, die aber nicht mein Spezialgebiet sind (z.B. das Übertragen bestimmter Tasks in eine mir unbekannte Programmiersprache). Da schmuggeln sich häufiger Fehler der Klassen "falscher Variablenname", "in 5 Zeilen gelöst, was eigentlich ein Einzeiler wäre", "galt nur bis Version X von 2023" etc. ein. Aber mehr erwarte ich da auch nicht.

Edit: Beim "erklären" von Syntax, die man nicht auf Anhieb versteht (weil z.B. neue Sprache oder neues Konzept wie PCRE) sind aktuelle LLM aber durchaus hilfreich. Oft geht das schon fixer, als sich selbst durch Dokus und Stackoverflow zu klicken.
 
Zuletzt bearbeitet:
Übrigens stimmt meine Rechnung vermutlich nicht, schwanke da hin und her, je nach außen Außentemperatur. Könnte sogar sein, dass das Skript der KI recht hat – oh nein, es kann doch nicht sein, was nicht sein darf! ;-)

Ich brauche in der vorletzten Zeile nur 10**i durch 10**(i-1)ersetzen und schon stimmt meine Lösung mit der von ChatGPT ein und ich gerate ordentlich ins Schwimmen, warum. Anscheinend liegts daran, dass die Schleifenvariable ja einmal "zuviel" inkrementiert wird, also abschließend die Stellenzahl darstellt, die das Limit überschreitet. Bin versucht, kleinere Parameter zu nutzen und doch mal "zu Fuß" zu iterieren, damit ich nicht zu viel Energie verbrauch mit der Verifizierung der beiden Lösungen. Allerdings ist gerade das eben nicht Sinn der Übung gewesen.

Somit kann ich nicht zeigen, dass ChatGPT doof ist, nur dass er mich nicht auf den Fehler im "Mathebuch", also meinen, hingewiesen hat. So gut ist der mathematische Solver nicht, ein spezifischer Agent, an den das LLM Teile delegiert haben muss.

@Scenturio: Dass nämlich auch ein mathematischer Solver da benutzt wird serverseitig, darauf deuten die ersten Antworten hin, deshalb hab ich ja gefragt. Einem reinem LLM ist die Aufgabenstellung nicht zuzutrauen. Nur die Ausführung von Python-Code ist erlaubt, wenn man angemeldet ist auf chatgpt.com. Hab zwar nen Account da, aber solangs ohne geht ... zu oft gibts bei "Login" ein Service Unavailable zurück.

Na gut, zumindest Englisch schreiben geübt.

Meine Schlussfolgerung hat unabhängig davon Bestand, dass ich Fehler gemacht und korrigiert habe, während ChatGPT gleich richtig lag – einschließlich die Einerstelle, wir beginnen ja bei 0. Ob ich will oder nicht, dadurch bin ich mir unterbewusst sicherer, dass ChatGPT "immer" :D richtig liegt. Und dieser Irrglaube kann mir eines Tages böse auf die Füße fallen.
 
Zuletzt bearbeitet:
Dass nämlich auch ein mathematischer Solver da benutzt wird serverseitig, darauf deuten die ersten Antworten hin, deshalb hab ich ja gefragt.
Da bin ich nicht ganz sicher - angesichts der Fehler, die noch gemacht werden. Aber die LLM werden spürbar besser.
 
Ich verwende Chatgtp als Assistent beim Max patchen und ab und an für PHP, letztere kann es eigentlich immer ganz gut, für Max ist der Code (json) weitgehend unbrauchbar aber für Konzepte und ähnliches ist es sehr gut verwendbar. Am besten funktioniert es für mich, wenn ich ihm ein komplexes Problem in kleine Teile zerlege und so nach und nach zum Ziel komme. Allerdings will es mir immer wieder objects unterjubeln die es nicht gibt oder Funktionen die das Object nicht kennt. Generell aber cool und es wird auch immer besser.
 
@GegenKlang
Du benötigst Tests, um zu überprüfen, ob das Aktuelle (das, was die KI ausgespuckt hat) mit dem Erwartetem (Dein gesichertes Wissen um den Lösungsansatz) übereinstimmt.
 


News


Zurück
Oben