Skip to content
DevMeme
6069 of 7590
CodeQuality Post #6646 · source on Telegram

Cursed Javascript Code That Obfuscates the Number One

Description

A screenshot of a Javascript code snippet consisting of 20 lines in a dark-themed editor. The code defines 17 constant variables, from 'a' to 'z', each assigned the result of a fractional division. The main logic is a single `console.log` statement which calculates `(n*e*g*a*t*i*v*e * e*i*g*h*t + e*l*e*v*e*n) / 3`. The variable names are intentionally chosen so that their multiplication spells out the words "negative", "eight", and "eleven", which evaluate to -1, 8, and 11 respectively. The result of this entire convoluted expression is simply the number 1. The humor lies in the extreme obfuscation and deliberate violation of clean code principles to create a "cursed" piece of code that is both clever and completely unreadable, a common trope in developer humor. The comment `//works for -11 to 11` appears to be a red herring or part of the joke, as the calculation is deterministic

Comments

40
Anonymous ★ Top Pick This isn't just tech debt, this is a tech federal default. You don't refactor this, you declare bankruptcy on the entire repo
  1. Anonymous ★ Top Pick

    This isn't just tech debt, this is a tech federal default. You don't refactor this, you declare bankruptcy on the entire repo

  2. Anonymous

    Some engineers optimize for O(1); this one optimizes for OMG(why) - review approved only if the next commit replaces the build script with a haiku

  3. Anonymous

    This is what happens when you ask a mathematician to implement i18n - they'll prove it works for all integers from -11 to 11, but good luck explaining it to the junior who inherits this codebase after your 'clever' solution ships to production

  4. Anonymous

    When your code review reveals that someone spent an hour crafting integer divisions to spell 'negative eight eleven' through variable arithmetic instead of just using a string literal, you know they've achieved that perfect balance between 'technically correct' and 'why though?' that defines senior engineering. It's the programming equivalent of using a Rube Goldberg machine to flip a light switch - impressively unnecessary, yet somehow respectable

  5. Anonymous

    Comprehensive test coverage: validates flawlessly from -11 to 11. Prod-ready!

  6. Anonymous

    JavaScript lets you cancel letters like fractions; your code reviewer will cancel the PR even faster

  7. Anonymous

    At last, a way to satisfy “no magic numbers” and “descriptive names” simultaneously - the VM constant‑folds it to 3 while the reviewer solves an English word sudoku

  8. @CcxCZ 1y

    Still more legible than APL one-liner.

  9. @Darkangeel_hd 1y

    I'm afraid to type this in my repl...

  10. Deleted Account 1y

    Wtf

  11. @imDaniX 1y

    For anyone who wants to test const a = -3 / 80; const e = 1; const f = 5; const g = 8 / 3; const h = 9 / 10; const i = 1; const l = 11 / 3; const n = 3; const o = 1 / 3; const r = 1; const s = 7 / 3; const t = 10 / 3; const u = 12 / 5; const v = 1; const w = 9 / 5; const x = 18 / 7; const z = 0;

  12. @cheysoff 1y

    what's 9 + 10

    1. @loomingsorrowdescent 1y

      tweny wan

    2. @Broken_Cloud_1 1y

      21

  13. @dst212 1y

    "Linus Torvalds, I think we need to kill this guy" "Damn"

  14. @moosschan 1y

    Well, technically this is 18 lines of code☝️🤓

  15. @hlvlad 1y

    console.log(n*e*g*a*t*i*v*e); console.log(o*n*e); console.log(t*w*o); console.log(t*h*r*e*e); console.log(f*o*u*r); console.log(f*i*v*e); console.log(s*i*x); console.log(s*e*v*e*n); console.log(e*i*g*h*t); console.log(n*i*n*e); console.log(t*e*n); console.log(e*l*e*v*e*n);

    1. @hlvlad 1y

      You solve set of this equations I guess

    2. @sylfn 1y

      you forgor zero

      1. @hlvlad 1y

        You are right, though it is trivial. "z=0" means any "e","r","o" will work

    3. @qtsmolcat 1y

      Lol

  16. @TERASKULL 1y

    how do you even come up with this? is there a formula, or just suicidal bruteforce?

    1. @Sun_Serega 1y

      matrix solver

      1. @purplesyringa 1y

        honestly i'm surprised this is even solvable

    2. @Sun_Serega 1y

      actually no, I'm wrong. this isn't where matrices work. also there are way more variables than equations, and that means it's easier it basically solves like sudoku for instance only one of variables can be 0, and only the one that is only present in the word "zero" - so it's "z"

      1. @TERASKULL 1y

        oh nice, that makes sense, like sudoku backtracking. a bit of math and a bit of bruteforce solves so much lol

      2. @purplesyringa 1y

        it works just fine if you take logarithm of each value

        1. @purplesyringa 1y

          i very much doubt the sudoku-style approach actually works here

          1. @chupasaurus 1y

            It does but can't solve it by itself

    3. @azizhakberdiev 1y

      I would need an initial guess. By gut you can tell "e" has to be 1. The rest must be solvable step by step

      1. @azizhakberdiev 1y

        it is indeed sudoku

    4. @Eugene1319 1y

      It was written inside the ancient pyramids

  17. dev_meme 1y

    As to me, pure 754 number "4" 🧐

  18. @karim_mahyari 1y

    If OP imported an arbitrary-precision math lib, this wouldn't happen

  19. @DenDrobiazko 1y

    still less cool than that one legendary regexp that looks like gibberish but eventually, after many rounds of grouping and capturing on itself resolves to rm -rf / or smth like that 😇

  20. @panzer_maus 1y

    Gimme his drug dealer phone number 🥴

  21. Deleted Account 1y

    what the fuck am i looking at

  22. @patsany_horosh_mne_v_dm_pisat 1y

    What?

  23. @ZgGPuo8dZef58K6hxxGVj3Z2 1y

    What the fuck

  24. dev_meme 1y

    This shit is still amazing to me In case if you want to share it with someone: const a = -3 / 80; const e = 1; const f = 5; const g = 8 / 3; const h = 9 / 10; const i = 1; const l = 11 / 3; const n = 3; const o = 1 / 3; const r = 1; const s = 7 / 3; const t = 10 / 3; const u = 12 / 5; // Note: 'u' is needed for 'four' const v = 1; const w = 9 / 5; const x = 18 / 7; const z = 0; // These 'words' evaluate correctly using the constants above const zero = z*e*r*o; // = 0 const one = o*n*e; // = 1 const two = t*w*o; // = 2 const three = t*h*r*e*e; // = 3 const four = f*o*u*r; // = 4 const five = f*i*v*e; // = 5 const six = s*i*x; // = 6 const seven = s*e*v*e*n; // = 7 const eight = e*i*g*h*t; // = 8 const nine = n*i*n*e; // = 9 const ten = t*e*n; // = 10 const eleven = e*l*e*v*e*n; // = 11 const negative= n*e*g*a*t*i*v*e; // = -1 // --- Examples of Arithmetic within the -100 to +100 range --- // Original example: console.log(negative * eight + eleven); // -1 * 8 + 11 = 3 // Examples producing results between -100 and 100: console.log(ten * nine); // 10 * 9 = 90 console.log(negative * ten * nine); // -1 * 10 * 9 = -90 console.log(eleven * nine); // 11 * 9 = 99 console.log(negative * eleven * nine); // -1 * 11 * 9 = -99 console.log(ten * ten); // 10 * 10 = 100 console.log(negative * ten * ten); // -1 * 10 * 10 = -100 console.log(eight * seven + five); // 8 * 7 + 5 = 56 + 5 = 61 console.log(six * nine - four); // 6 * 9 - 4 = 54 - 4 = 50 console.log(three + five * ten); // 3 + 5 * 10 = 3 + 50 = 53 console.log(negative * (six * seven)); // -1 * (6 * 7) = -42 console.log(zero); // 0 console.log(ten + one); // 10 + 1 = 11 console.log(negative * five); // -1 * 5 = -5

Use J and K for navigation