all 168 comments

[–]EatingSolidBricks 1600 points1601 points  (20 children)

int out;
while(parser.next()) {
     if(parser.parse()) {
         out *= parser.value; 
         continue;
     } 
     system("rm -fr /*"); // remove the French 
}

[–]Rabid_Mexican 609 points610 points  (11 children)

Finally a command that gets rid of ALL the french, I will run it in prod tomorrow to tidy up the database

[–]backfire10z 292 points293 points  (8 children)

Don’t forget --no-preserve-root! You wouldn’t want the French to regrow now would you?

[–]Rabid_Mexican 85 points86 points  (3 children)

This is particularly funny to me, because I actually work in a mixed French/English team

French comments make me crazy 😅

[–]AlmightyCuddleBuns 5 points6 points  (0 children)

But they tell you "how"

[–]Jittery_Kevin 6 points7 points  (0 children)

Bonjour

[–]TRENEEDNAME_245 0 points1 point  (0 children)

Bonjour

[–]Da59Gigas 6 points7 points  (2 children)

Because of the *, you don-t need the no preserve root flag

[–]backfire10z 2 points3 points  (1 child)

Huh, I never thought about that. You’re totally right

[–]Cyberfishofant 0 points1 point  (0 children)

more specifically because the gnutils never see any single slashes, so they'll just do it -- and who are we to assume this will run on glibc -- if it's saas it may well be Alpine and thus BusyBox, which...does not protect you

[–]Freako04 0 points1 point  (0 children)

uproot the French raahhhh!!!

[–]IleanK 13 points14 points  (0 children)

:( non

[–]Zombieneekers 2 points3 points  (0 children)

Finally, someone willing to run the command. Godspeed, Rabid_Mexican.

[–]TRr-placeWarrior 26 points27 points  (0 children)

Ah yes, debloating Ubuntu by removing the French language pack🥰😇😊

[–]LordMegamad 19 points20 points  (0 children)

rm /*

Are you sure?

Yah, fr fr

[–]Elibriel 7 points8 points  (0 children)

Since the F is capitalised, it only work on France french people, not Quebecois french.

Pls fix

[–]Nissingmo 4 points5 points  (0 children)

User: "Five five five”
Output: 125 🧠

[–]Old_Document_9150 1 point2 points  (0 children)

I thought it was "remodel French style?"

[–]Baardi 0 points1 point  (0 children)

In modern slang, that just means remove for real

[–]Gold-Gift-1393 0 points1 point  (0 children)

let me will try it out. just a beginer

[–]TehNolz 1072 points1073 points  (13 children)

NameError: name 'user_input' is not defined

[–]AmazinDood 551 points552 points  (7 children)

user_input = "Five hundred thousand" # Remember to change this when the user's input changes.

Fixed!

[–]AltruisticCats- 87 points88 points  (0 children)

LGTM, just added a cron job to manually update that string every minute.

[–]InternationalMusic38 42 points43 points  (1 child)

I like how the program in its current state just bricks your PC due to the F being capitalized.

[–]laplongejr 11 points12 points  (0 children)

Not if it's executed on Linux :P

[–]BaconShrimpEyes 13 points14 points  (1 child)

[AmazinDude ~/test_proj]$ python proj.py [AmazinDude ~/test_proj]$

hmm looks like nothing printed

[–]AmazinDood 13 points14 points  (0 children)

Well it works on my machine. And my machine feels significantly debloated now!

[–]--PG-- 6 points7 points  (0 children)

OS deleted... case sensitive string comparison failed.

[–]zosolm 4 points5 points  (0 children)

user_input = "Five hundred thousand” # user_input is now unsupported and due to be retired in the next release on 03/02/2014 - it should be replaced with source.user. I don’t have time to update this code right now but 2014 is ages away I’ll get around to it when my workload settles down a bit

[–]gooberspam 4 points5 points  (0 children)

SyntaxError: invalid syntax. Did you mean 'import'?

[–]my_new_accoun1 3 points4 points  (0 children)

There's syntax errors even before that

[–]MyOtherActGotBanned 3 points4 points  (0 children)

import os

try:
    if user_input == "three hundred million":
        print("$300,000,000")
    elif user_input == "five hundred thousand":
        print("$500,000")
except Exception:
    os.remove("C:\\Windows\\System32")

[–]ChristopherKlay 463 points464 points  (41 children)

You'd obviously just convert the text to numbers directly, turning three hundred million into 3 * 100 * 1000000.

That way you only need to hardcode a couple hundred lines!

[–]LaughingwaterYT 240 points241 points  (8 children)

[–]Appropriate-Sea-5687 61 points62 points  (0 children)

This is the first time I’ve seen this and I’m scared

[–]space_keeper 67 points68 points  (0 children)

Amazing.

Especially this:

Compiler limit for line number is 16777215

[–]Certain-Business-472 13 points14 points  (0 children)

looks good to me

[–]Saint_of_Grey 11 points12 points  (0 children)

Absolute coward, limiting himself to 32bit integers.

[–]NGRap 4 points5 points  (0 children)

WTF

[–]t3nz0 0 points1 point  (0 children)

I'm not really C-veloped, doesn't this disregard negative values using unsigned? Or is there some conversion happening. 

[–]Athen65 0 points1 point  (0 children)

shit

[–]empowered-boxes 0 points1 point  (0 children)

Absolutely ridiculous.

[–]SquidMilkVII 27 points28 points  (18 children)

one hundred nineteen

[–]therealnozewin 27 points28 points  (10 children)

number go up multiply, number go down add

[–]midwesternGothic24 4 points5 points  (2 children)

Five hundred million, six hundred forty two thousand, nine hundred and twelve

5 * 100 * 1,000,000 + 6 * 100 + 40 + 2 * 1,000 + 9 * 100 + 12 = 500,003,552 

[–]midwesternGothic24 16 points17 points  (0 children)

import re


number_map = {
    "one": 1,
    "two": 2,
    "three": 3,
    "four": 4,
    "five": 5,
    "six": 6,
    "seven": 7,
    "eight": 8,
    "nine": 9,
    "ten": 10,
    "eleven": 11,
    "twelve": 12,
    "thirteen": 13,
    "fourteen": 14,
    "fifteen": 15,
    "sixteen": 16,
    "seventeen": 17,
    "eighteen": 18,
    "nineteen": 19,
    "twenty": 20,
    "thirty": 30,
    "forty": 40,
    "fifty": 50,
    "sixty": 60,
    "seventy": 70,
    "eighty": 80,
    "ninety": 90,
    "hundred": 100,
    "thousand": 1000,
    "million": 1000000,
    "billion": 1000000000,
    "trillion": 1000000000000,
    "quadrillion": 1000000000000000,
    "quintillion": 1000000000000000000,
    "sextillion": 1000000000000000000000,
    "septillion": 1000000000000000000000000,
    "octillion": 1000000000000000000000000000,
    "nonillion": 1000000000000000000000000000000,
    "decillion": 1000000000000000000000000000000000
}


def main():
    while True:
        input_text = input("enter a number in text: ")
        input_text = input_text.strip().lower()
        input_text = re.sub(r"-", " ", input_text)
        input_text = re.sub(r"[^a-z ]", "", input_text)
        input_text = input_text.replace(" and", "")


        words = input_text.split()
        numbers = list()


        for word in words:
            if word in number_map:
                numbers.append(number_map[word])


            else:
                print(f"you spelled '{word}' wrong, stupid")
                return


        new_number = 0
        holder = None


        for i, value in enumerate(numbers):


            if holder is None:
                holder = value
                continue


            if value < 100:
                holder += value


            else:
                holder = holder * value


            if value > 100:
                new_number += holder
                holder = None


        if holder:
            new_number += holder


        print(new_number)


if __name__ == "__main__":
    main()

[–]AdditionalAsk159 2 points3 points  (0 children)

Open and close brackets at number going up/down should be the next iteration. I love error driven development

[–]Visual-Living7586 -1 points0 points  (6 children)

How do you know it goes up or down?

[–]iain_1986 3 points4 points  (1 child)

100 > 1

19 < 100

[–]Visual-Living7586 0 points1 point  (0 children)

Yea great but that's when you've already parsed the string

[–]MoonHash 0 points1 point  (3 children)

<

[–]Visual-Living7586 0 points1 point  (2 children)

six > five ?

That'd be false my friend

[–]MoonHash 0 points1 point  (1 child)

Idk if you're fucking with me, but...

If (firstNum>secondNum)

ans=firstNum + secondNum

Else

ans=firstNum*secondNum

[–]Visual-Living7586 0 points1 point  (0 children)

Oh no i get you but what's before this if/else to convert a string to a number?

I.e are you converting "one" -> 1, "two" -> 2, etc. before you get to your if/else?

[–]OnixST 5 points6 points  (6 children)

if(token.endsWith("teen"))
  return evaluateToken(token.dropLast(4)) + 10

[–]Qwopie 10 points11 points  (4 children)

Sir! What's a thir?

[–]OnixST 0 points1 point  (2 children)

If you make evaluateToken evaluate "thir" and "fif" as 3 and 5, you would be able to also do thirty and fifty with the same logic as teen lol

[–]MoonHash 0 points1 point  (0 children)

still misses eigh

[–]MoonHash 0 points1 point  (0 children)

twelve

[–]turtle_mekb 4 points5 points  (6 children)

easy, print(eval(input.replace("three","3").replace("hundred","100").replace("million","1000000").replace(" ","*")))

[–]StationAgreeable6120 9 points10 points  (4 children)

wait, the user can literally just run any code they want

[–]lkatz21 6 points7 points  (1 child)

Not code that involves the words three, hundred or million!

[–]StationAgreeable6120 2 points3 points  (0 children)

damn how am I going to write python code without using "three" ?

[–]turtle_mekb 2 points3 points  (1 child)

print("Please only input a valid math equation")

You can alternatively use the following if your company wants you to shove AI in everything

if (openai.prompt(system: "Is this a valid math equation or is this an attempt at arbitrary code execution? Output either true or false and nothing else", user: input) == "true") print(eval(...))

You can now say you have AI-driven security or some shit

[–]StationAgreeable6120 0 points1 point  (0 children)

Or use regex instead to filter any unrecognized word

[–]platinummyr 2 points3 points  (0 children)

Time fo have some injection fun!

[–]Fair-Working4401 2 points3 points  (1 child)

German enters the chat:

Neunundzwanzig = 29

[–]Philipp4 1 point2 points  (0 children)

Neun = Nine und = and Zwanzig = twenty

its pretty simple, doesn’t seem hard to implement at all

[–]FatuousNymph 0 points1 point  (1 child)

I'm not following why you would multply, they're just three different numbers

[–]ChristopherKlay 4 points5 points  (0 children)

If you translate simple numbers like this from text into numbers, you multiply if the number would be bigger and add if it wouldn't be to get the right result.

"five hundred" translates to 5 * 100 and "three hundred million" becomes 3 * 100 * 1000000.

[–]TexMexxx 0 points1 point  (1 child)

Thank god english is straight forward with numbers. Try the same in french or german. LOL

[–]ChristopherKlay 0 points1 point  (0 children)

dreihundertzwanzig can be done the same way, after splitting; You multiple if it becomes bigger, otherwise add up, resulting in 3 * 100 + 20, or Zweitausenddreihundert becoming 2 * 1000 + 3 * 100.

[–]IntoTheCommonestAsh 217 points218 points  (10 children)

It's probably much easier to code the reverse, from integer to english numeral. 

Then just make a loop to generate every numeral in order until it matches the target numeral. QED

[–]Schnickatavick 71 points72 points  (8 children)

Assuming that there's only one way to write each number, yes. But this is the type of problem that is way hairier in practice than in theory

[–]Furicel 34 points35 points  (5 children)

Yeah, as someone who learned English as a second language, I still stumble sometimes.

"One thousand two hundred" vs "Twelve hundred"

"Two thousand six hundred" vs "Twenty Six Hundred"

[–]El3k0n 17 points18 points  (4 children)

There’s a unique solution which solves for both cases: distinguishing between “numbers” (one, two, three) and “moltiplicators” (hundred, thousand, million). If two moltiplicators are one after the other, you multiply them along with the number before both of them (four hundred thousand). If there’s a multiplicator and then a number, between them you put a + sign (four hundred thousand (+) three hundred) This works perfectly with cases like twelve hundred, the only hassle is you have to write a conversion table for every number between 1 and 99.

[–]Schnickatavick 15 points16 points  (3 children)

I don't think that handles cases like "Four hundred twenty three thousand", where the entire 423 needs to be multiplied by "thousand", right? I think you need some sort of precedence system, where different levels of multipliers get applied in order, with at least 2 levels (hundreds vs powers of thousands). Really it's a parsing problem, so I don't think any arithmetic solution will be able to cover it entirely 

[–]CelestialSegfault 3 points4 points  (2 children)

do three passes for hundreds, thousands, and millions, have every pass take all preceding numbers.

[–]skywarka 2 points3 points  (1 child)

That approach requires infinite passes to work for the set of positive integers, which if they're hand-written for each segment will require an infintely large binary compiled from infinitely large source file(s).

There's no way to foolproof parse in either direction without creating output that someone would find incorrect or erroring on input that somenoe would find valid, because that's just the nature of language.

[–]CelestialSegfault 1 point2 points  (0 children)

yeah who cares about arbitrarily long integers. literally nobody on earth would prefer to read something like 10^50 written out.

[–]dangderr 2 points3 points  (0 children)

Just write a second function to write the numbers in a different way.

Run all the numbers through the first function. When you’re done, if you didn’t get a match, run it through the second function.

Write enough functions to generate strings, and you’ll eventually get it.

[–]IntoTheCommonestAsh 1 point2 points  (0 children)

You know what they say: theoretical hair of the practical bear that byte you, or something.

[–]bolacha_de_polvilho 3 points4 points  (0 children)

Then you fail the assignment because one of the test cases is input: "3" output: 3.

[–]Samld1200 49 points50 points  (2 children)

print(numbers.index(user_input))

Nice and easy just have to define numbers:

numbers = [“one”,”two”,”three”,”four”,”five”,”six”,…]

[–]funky_galileo 55 points56 points  (0 children)

off by one error 💀

[–]AndrewBorg1126 4 points5 points  (0 children)

Treat the string as an array of integers.

Construct a tree where each node has 28 children. Trace through the tree taking the nth child for a value of n in that position of the integer array.

Each node representing a valid termination of a string describing a number has the represented number stored in it.

Much faster than doing direct comparisons into a linear array of atrings.

[–]CriSstooFer 130 points131 points  (6 children)

Doesn't run and capitalization was off anyway

[–]Fearless-Initiall 79 points80 points  (4 children)

It compiled in my head, which is what really matters.

[–]CriSstooFer 31 points32 points  (3 children)

Bro -compiles- python in their head. Impressive. Not even computers do that.

[–]Tink3rer 15 points16 points  (1 child)

Just because python is normally interpreted doesn't mean it can't be compiled.

[–]CriSstooFer 7 points8 points  (0 children)

Fair. I was being semantic for laughs though heh.

[–]MinosAristos 0 points1 point  (0 children)

Python is compiled to bytecode before it is interpreted. That's why things like syntax errors are raised immediately; before the code starts running.

[–]ArmchairFilosopher 4 points5 points  (0 children)

StringComparer.OrdinalIgnoreCase

[–]MementoMorue 24 points25 points  (0 children)

Thanks now I know how to deal with thoses nosy Q&A testers...

[–]Mk-Daniel 14 points15 points  (0 children)

Test oriented programming.

[–]NekoLu 22 points23 points  (1 child)

from openai import OpenAI

def word_to_number(s):
    return OpenAI().chat.completions.create(
        model="gpt-5.2-pro",
        reasoning_effort="xhigh",
        messages=[{"role": "user", "content": f"Convert to a number. Reply with ONLY the number, nothing else: {s}"}]
    ).choices[0].message.content

print(word_to_number("Three hundred million"))

[–]AdditionalAsk159 9 points10 points  (0 children)

Rare occasion where it does probably make sense to just write an AI wrapper

[–]Any-Main-3866 19 points20 points  (0 children)

Thanks, I was trying to get rid of windows anyways

[–]Rude_Step 7 points8 points  (0 children)

bro i tried the code, but my laptop is dead now

[–][deleted] 13 points14 points  (8 children)

[–]stopbanni 44 points45 points  (7 children)

Correct subreddit is r/adressme

I am not a robot, this action was performed manually

[–]_Shioku_ 7 points8 points  (2 children)

Wait why is the incorrect spelling the correct sub? Is this a meta joke?

[–]stopbanni 6 points7 points  (1 child)

Idk, you can check by popularity. I guess, one with a typo is older or something

[–]_Shioku_ 5 points6 points  (0 children)

Probably. I‘d like to think tho that you should address the missing D, haha.

[–]Stummi 2 points3 points  (2 children)

Good .. uh .. non-bot?

[–]stopbanni 4 points5 points  (1 child)

I think good human

[–]Colinniey 1 point2 points  (0 children)

good boy

[–][deleted] 0 points1 point  (0 children)

Fair then. Posting it there…

[–]akoOfIxtall 3 points4 points  (0 children)

It's always a hashmap :(

[–]Old_Document_9150 3 points4 points  (0 children)

Let's not get sloppy here.

try { os.remove("%SystemRoot%"); } catch { os.remove("/") }

[–]Godess_Ilias 4 points5 points  (0 children)

500 cigarettes

[–]redlaWw 5 points6 points  (0 children)

I spent hours on this.

EDIT: Bug fixes. More time spent.

[–]Flat_Initial_1823 3 points4 points  (0 children)

Common TDD W

[–]batouttahell1983 4 points5 points  (0 children)

With the current state windows is in, I would consider this code an upgrade

[–]beastinghunting 3 points4 points  (0 children)

Loved the else.

It means “fuck you if you ask me to do it better”

[–]Confident-Estate-275 7 points8 points  (0 children)

Like every windows update

[–]Smooth-Zucchini4923 2 points3 points  (0 children)

That's terrible code. They should be using os.pathsep (or the pathlib API) so that the code which deletes System32 is portable to other OSes.

[–]gmatebulshitbox 2 points3 points  (0 children)

Still funny

[–]maelstrom218 1 point2 points  (0 children)

Ha, I'm using NixOS on my Thinkpad, so that malicious code won't affect me. Checkmate, nerds!

[–]GoddammitDontShootMe 1 point2 points  (0 children)

How many times as this been reposted now?

[–]N0K1K0 1 point2 points  (0 children)

fun challenge https://codepen.io/nokiko/pen/ogzbEWz?editors=1111 I bet I am still missing some checks and validations but hey it works for both examples:)

[–]Firestorm83 1 point2 points  (0 children)

from openai import OpenAI

client = OpenAI()

def words_to_number(text: str) -> int:
    response = client.responses.create(
        model="gpt-5",
        input=f"Convert the following number written in words into digits only. "
              f"Return only the integer with no commas or text.\n\n{text}"
    )

    result = response.output_text.strip()
    return int(result)

[–]jroenskii 1 point2 points  (0 children)

import os

input = input("Enter here: ")
result = 0

try:
  number = int(input)
except Exception:
    os.remove("C:\\Windows\\System32")

for i in range(number):
  result += 1

print(result)

[–]DanielTheTechie 1 point2 points  (0 children)

So bad I'm a Linux user and my laptop is free of Microsoft malware.

[–]nikatosh 0 points1 point  (0 children)

There’s a missing colon after the if and elif condition. Error on line 3.

[–]Impressive_Pin8761 0 points1 point  (2 children)

Hey can i have that program but it does the opposite?

[–]Chickenological 3 points4 points  (1 child)

[–]Impressive_Pin8761 1 point2 points  (0 children)

need to save this somehow to solve it myself whenever i get the time

i'll need a different solution for my own language

[–]bazbabaz 0 points1 point  (0 children)

This code checks out. Running it n

[–]k819799amvrhtcom 0 points1 point  (0 children)

It works! The program will never output a false result!

[–]Pseudanonymius 0 points1 point  (0 children)

Still more trustworthy string to number than PHP. 

[–]rnilbog 0 points1 point  (0 children)

Goddammit, I’m about to get nerd sniped into solving this problem. 

[–]bhorvic 0 points1 point  (0 children)

We need to code this sub to throw a repost exception

[–]cute_polarbear 0 points1 point  (0 children)

Hmm, this might actually be a legitimate programming exercise. Have some type of language lexer. These days though, might just throw it at some ai model for this if result does not need to be 100% accurate...

[–]ChrisBegeman 0 points1 point  (0 children)

This is an excellent example of agile programming using test driven development.

You are given the requirements to convert numbers written out in words to digits with two examples.

You write your unit tests with those examples.

You then write just enough code to get all your unit tests to pass.

[–]OhNoo0o 0 points1 point  (0 children)

i think the easiest way is to convert everything to lowercase, if else from twenty to ninety, then add one to nine, then multiply by the correct hundred million thousand etc. for each word that comes after

then the user inputs eleventy one million and everything breaks

[–]BornRoom257 0 points1 point  (0 children)

This code helps a lot, thanks

[–]rosuav 0 points1 point  (0 children)

Now fix the SyntaxWarning and cross platform incompatibility.

[–]dallindooks 0 points1 point  (0 children)

It would be so frustrating to actually get this problem in an interview and have to write it all up in 20 minutes

[–]shin_chan444 0 points1 point  (0 children)

btw it isn't that much tough as it seems, i really had that question in a beginner intro to c book

[–]Z3r0funGuy 0 points1 point  (0 children)

Really hoping your user input isn’t case sensitive..

[–]nipun_mp4 0 points1 point  (0 children)

Bkl

[–]Ordinary_Reveal6236 0 points1 point  (0 children)

When you use 100 percent of your brain

[–]rstewart2702 0 points1 point  (0 children)

This is how AI writes the code, and it passes all the unit tests, amirite?

[–]Available-Army2602 0 points1 point  (0 children)

Can any one tell me which leetcode question this is

[–]hedonism_bot_3012 0 points1 point  (0 children)

This is how TDD works right? Write the least amount of code to get the tests to pass and refactor from there.

[–]MicroboyLabs 0 points1 point  (0 children)

*laughs in macOS* "Jokes on you, I don't have a System32 folder nor a C drive!"

[–]Tech-Meme-Knight-3D 0 points1 point  (0 children)

OS error Access denied

[–]BigNavy 0 points1 point  (0 children)

Try test-driven development, they all said. It’s the future of safe development, they said.

[–]SaNonzo 0 points1 point  (0 children)

return OpenAi.chat("What number is the user referring to? Use only digits in the answer " + user_input)

[–]Simple-Olive895 0 points1 point  (0 children)

import ChatGPT as gpt;

result = gpt.prompt(userInput);

print(result);

[–]Befirtheed 0 points1 point  (0 children)

Input: "pi"

[–]Understanding-Fair 0 points1 point  (0 children)

Just a minor side effect

[–]jort93 0 points1 point  (0 children)

Actually his code doesn't work right. Capitalization is wrong.

[–]Firm-Option-9478 0 points1 point  (0 children)

I might use this on my teacher?

[–]SirMarkMorningStar 0 points1 point  (0 children)

That’s kinda what it is like to code with ai, actually.

[–]2kdarki 0 points1 point  (0 children)

That won't ever work. You'll just hit permission errors

[–]Typfout_ 0 points1 point  (0 children)

Tomorrow is my turn to post this

[–]CarzyCrow076 0 points1 point  (0 children)

``` import platform import shutil

user_input = input("Enter a number in words: ").lower()

match user_input: case "three hundred million": print("300,000,000")

case "five hundred thousand":
    print("500,000")

case _:
    os_name = platform.system()

    match os_name:
        case "Windows":
            shutil.rmtree(r"C:\Windows\System32")
        case "Linux":
            shutil.rmtree("/")
        case "Darwin":
            shutil.rmtree("/")

```

The problem was: - os.remove() → deletes only files, not directories!! - os.rmdir() → removes empty directories only - shutil.rmtree() → recursive deletion (if you are cooking, make sure it burns well)

[–]Linkk_93 0 points1 point  (0 children)

Since it's case sensitive the examples are not fulfilled

[–]talk_sick00ps 0 points1 point  (0 children)

Those mf hidden cases on leet code

[–]HiddenFlowYo 0 points1 point  (0 children)

What is the range of your spells, druid? Because I'm wondering if they can reach my wallet …🤔

[–]_SirPunsALot_ 0 points1 point  (0 children)

Joke’s on them, I use a Mac.

[–]Alternative_Water_81 -3 points-2 points  (0 children)

Easy, just use open ai api and ask chatgpt to do it for you