lexi

i like breaking computers

  • it/its, #[deprecated] she/her
  • ./a.out

i like rust, nix, linux, infosec, webdev and i shitpost a lot. ctf player and so-called "security researcher". aroace, agender, nb, nd, disabled, &, ΘΔ :3 🏳️‍⚧️ 🟨⬜️🟪⬛️

picrew: #1322863


// 2021-09-28
for(i=1;i<101;i++)console.log([,,,"Fizz",,"Buzz"].map((v,n)=>i%n?'':v).join('')||i)
// 2022-07-18
for(i=0;++i<101;)console.log([,,,"Fizz",,"Buzz"].map((v,n)=>i%n?'':v).join('')||i)

how did i never think about optimizing the damn for loop lmao

(if youre OOTL what code golf/fizzbuzz is click read more)


Code golf:

Code golf is a type of recreational computer programming competition in which participants strive to achieve the shortest possible source code that solves a certain problem.


FizzBuzz:

(also available as a Tom Scott video)

Fizz buzz (often spelled FizzBuzz in this context) has been used as an interview screening device for computer programmers.

The player designated to go first says the number "1", and the players then count upwards in turn. However, any number divisible by three is replaced by the word fizz and any number divisible by five by the word buzz. Numbers divisible by 15 become fizz buzz. For example: 1, 2, Fizz, 4, Buzz, Fizz, 7, 8, Fizz, Buzz, 11, Fizz, 13, 14, Fizz Buzz, 16, 17, Fizz, 19, Buzz, Fizz, 22, 23, Fizz, Buzz, 26, Fizz, 28, 29, Fizz Buzz, 31, 32, Fizz, 34, Buzz, Fizz, ...

Writing a program to output the first 100 FizzBuzz numbers is a relatively trivial problem requiring little more than a loop and conditional statements. However, its value in coding interviews is to analyze fundamental coding habits that may be indicative of overall coding ingenuity.


You must log in to comment.

in reply to @lexi's post:

you can do .map instead of .forEach, but that would be the same length. theres just the slight caveat that that counts from 0 which is against the fizzbuzz rules lol

Array(100).fill().map((_,i)=>[,,,"Fizz",,"Buzz"].map((v,n)=>i%n?'':v).join('')||i)
for(i=0;++i<101;)console.log([,,,"Fizz",,"Buzz"].map((v,n)=>i%n?'':v).join('')||i)
a=[];for(i=0;++i<101;)a.push([,,,"Fizz",,"Buzz"].map((v,n)=>i%n?'':v).join('')||i);a

Reminds me of hardcoding fizzbuzz when it was the last question in a 5-hour exam for the month-long selection test I did for a programming college 💀

I was just too tired after all those hours/weeks to know how to do it, the day after I immediately realized it wasn't very complicated lol

It did get me accepted to the college though!!