What percent of Jow Forums can solve this?

What percent of Jow Forums can solve this?

Attached: fizzbuzz.jpg (1920x1080, 74K)

Other urls found in this thread:

bit
projecteuler.net/problem=14
pastebin.com/ZsAMGbKa
twitter.com/SFWRedditGifs

100, hopefully.

/thread

for i in range(1, 100):
if (i % 15 == 0):
print('FizzBuzz')
elif (i % 3 == 0):
print('Fizz')
elif (i % 5 == 0):
print('Buzz')
else:
print(i)

>range(1,100)
fail

python ranges are retarded
i get it that they are meant as indexes for lists, but still

I don't think I could do that. Who do I look like, Steve Jobs? lol..

print(['Fizz'*(not i%3)+'Buzz'*(not i%5) or i for i in range(1,101)])

I did it in visual basic some time ago

It says to print the number and (fizz or buzz or fizzbuzz)

I'd say anyone who was taught basic programming in primary/elementary school

you only print numbers unless you are supposed to print a string.

Normally, sure. That's not what the image in the OP says to do though.

This is elementary logic. If you can't do this with a one-liner on your favorite shell, you're retarded:
$ for ((i=1;i

for (var i = 0; i < 100; i++) {
console.log((i % 15 === 0) ? 'FizzBuzz' : (i % 5 === 0) ? 'Buzz' : (i % 3 === 0) ? 'Fizz' : i)
}

npm install fizzbuzz

There, what do I win?

;.>>>.,;>.."Fizz"

for (var i = 1; i

without modulo (%), written in poo
for (int i = 0; 100 >= i; i++) {

if (i - (i / 3) * 3 == 0) {
System.out.print("Fizz ");
if (i - (i / 5) * 5 == 0) {
System.out.print("\bBuzz ");
}
}
else if (i - (i / 5) * 5 == 0) {
System.out.print("Buzz ");
}
else {
System.out.print(i + " ");
}

Attached: poo.png (482x149, 9K)

Not these retards.

> print('FizzBuzz')
Nigger, he said Fizz-buzz, not fizzbuzz.

fizzbuzz :: Int -> IO ()
fizzbuzz 101 = putStrLn ""
fizzbuzz x
|mod x 15 == 0 = do {putStrLn "FizzBuzz"; fizzbuzz(x+1)}
|mod x 3 == 0 = do {putStrLn "Fizz" ; fizzbuzz(x+1)}
|mod x 5 == 0 = do {putStrLn "Buzz" ; fizzbuzz(x+1)}
|otherwise = do {putStrLn (show x) ; fizzbuzz(x+1)}

Using division not much different from using modulo, modulo is just syntactic sugar. There's a better way to solve it without modulo and without cheating using division

messed up then indentation when pasting it, also changed to Fizz-Buzz
for (int i = 0; i

Attached: yo_dizz.jpg (640x512, 39K)

improved

fizzbuzz :: Int -> String
fizzbuzz 101 = ""
fizzbuzz x
|mod x 15 == 0 = "FizzBuzz /n" ++ fizzbuzz(x+1)
|mod x 3 == 0 = "Fizz /n" ++ fizzbuzz(x+1)
|mod x 5 == 0 = "Buzz /n" ++ fizzbuzz(x+1)
|otherwise = show x ++ " /n" ++ fizzbuzz(x+1)

the real question though, every "interview question" seems to avoid:

is 0 fizzbuzz?

If it was an actual interview I'd throw anyone out who writes one liners or overcomplicated solutions.
Solve this simple exercise in a simple easy to understandable way instead of writing unmaintainable code.

The exercise is defined for the numbers from 1 to 100.
Don't overcomplicate something which is simple.

>I would like to know more.
You have to stop thinking in CS terms and start taking about it as a math problem. What is a factor of n? A number that can be multiplied by some integer to produce n.
Now integer multiplication is just addition. So the first arbitrary factor x is (1 * x) = x1, the second factor x2 = (2 * x) = x + x and so on.

What this means is that the factors repeat in equal steps. So if you know the initial factors, which you know because they are given in the problem and are 3, 5 and 15, you just need to check against them in a stepwise fashion.

You start with three (one for 3, 5 and 15) counters all 0, and for each number you add 1 to each counter. If a counter is 15, print fizzbuzz and reset that counter. If a counter is 5, print buzz and reset that counter. And so on. The counters will go from 0 to 3, 0 to 5 and 0 to 15 and reset when they are equal to the corresponding factor, and you print fizz or whatever.

>There's a better way to solve it without modulo
define better.

Reposting from yesterday

Attached: Selection_224.png (691x1999, 240K)

Better as in solving it without modulo without cheating with division. Not better as in more performant or efficient, please contain your autism. What I meant was clear enough.

I see, thanks user

##mount&blade scripting """language"", basically a python tuples and array, jumbled together
fizzbuzz =
("fizzbuzz",
[
(store_script_param, ":input_size", 1),
(assign, ":mod_result", 0),
(try_for_range, ":i", 0, ":input_size"),
(try_begin),
(store_mod, ":mod_result", ":i", 15),
(eq, ":mod_result", 0),
(display_message,"@FizzBuzz"), #yes the engine cannot concat strings
(else_try),
(store_mod, ":mod_result", ":i", 3),
(eq, ":mod_result", 0),
(display_message,"@Fizz"),
(else_try),
(store_mod, ":mod_result", ":i", 5),
(eq, ":mod_result", 0),
(display_message,"@Buzz"),
(else_try),
(assign, reg0, ":i"),
(display_message,"@{reg0}"), #display anything that is store in register 0
(try_end),
(try_end)
]
)

#how to call?

# ...
# (blablablab),
(call_script, "script_fizzbuzz", 3000),

what is the absolute shortest code that can do this? And how can I find the absolute shortest code for any task?

a={};
for i=1, 100 do
a[i] = i
end

for i=3, 100, 3 do
a[i] = "fizz"
end

for i=5, 100, 5 do
a[i] = "buzz"
end

for i=15, 100, 15 do
a[i] = "fizzbuzz"
end

for i=1, 100 do
print(a[i])
end

$Range = 1..100
$Results = foreach ($Num in $Range) {
$Both = ((($Num % 3) -eq 0) -and (($Num % 5) -eq 0))
$Three = (($Num % 3) -eq 0)
$Five = (($Num % 5) -eq 0)
switch ($true) {
$Both {"$Num Fizz-Buzz"; break}
$Three {"$Num Fizz"}
$Five {"$Num Buzz"}
Default {$Num}
}
}
$Results -join ", "

What's the point of doing that.

just curious about minimalist shit like that

The image is wrong. You don't print the number AND fizz, buzz, or fizz-buzz. you print the number OR fizz, buzz, or fizzbuzz.
Well, naturally, all the solutions ITT are wrong. They mostly do fizz buzz correctly. but they don't do what was asked.

the shortest code would be a custom programming language made for the purpose of printing fizzbuzz, where you just run any program compiled in that language and it prints the result without any input from the user

if you mean existing languages, then you have to look for the one with the shortest map function, most likely a functional language
i use elixir and the map is called Enum.map, if some language has the same but called just "map" then that's the one you want to use for your fizzbuzz

"Minimalist" in code makes no sense.
You should always try to write code as maintanable as possible. However, I understand it when you give up a bit of it for performance.

In this case however, you just write shitty code.

well this one is correct

>muh maintainability
you do realize that's a meme spouted because pajeets can't into smart code, right? companies want code monkeys, not programmers

why do you think they use clever languages such as scala in finance and big data? because they have the money to hire competent programmers

now i'm not saying maintainability is bad, it's a tenant of good design, but i've seen people call even recursion bad because your average brainlet cs student has a difficult time with it

Kys JS fags

Fizz buzz is fucking easy

Inverse fizz buzz is an actual challenge

const mod = (x,y) => x >= y ? mod(x-y,y) : x


How did I do senpai

$ python3 -c "import fzzbzz; fzzbzz(100)"

char fb[] = {0,0,1,0,2,1,0,0,1,2,0,1,0,0,3};
for(int i = 0; i 1) ? (fb[(i-1)%15] == 3) ? "Fizz-Buzz" : "Buzz" :(fb[(i-1)%15]==1) ? "Fizz" : "");

Beautiful but I believe you can optimize it by checking if x == y and just returning 0 to save a few steps of recursion

public class fizzbuzz {
public static void main(String[] args) {
for (int i = 0; i < 100; i++) {
if (i % 15 == 0) {
System.out.println("FizzBuzz");
}
else if (i % 3 == 0) {
System.out.println("Fizz");
}
else if (i % 5 == 0) {
System.out.println("Buzz");
}
else {
System.out.println(i);
}
}
}

Attached: succ.png (1408x244, 26K)

I actually work in the IT departement in bank in Liechtenstein. Every piece of code is audited. If you can't argue with performance, not a line of code will pass audit.
It becomes a 'meme' the second you're out of money and start writing shit code because theres no time.

don't you losers get bored from doing the same shit over and over

I wrote a fizzbuzz java class.

You can just import it and then call it in a main. One word code, done

Of course I understand your point code audits are critical for any project of considerable size. I'm not talking about maintainable code I'm talking about the idea that anything that isn't OOP procedural code is bad and unmaintainable. It's not just about performance, sure you can write a C++ program that will do the same than a Scala or Elixir parallelized program, probably faster too, but you will need 5x the man months to do it.

It's not as black and white as something being more performant, there are many more variables to consider.

var array = [];
array[3] = array[6] = array[9] = array[12] = "Fizz
";
array[5] = array[10] = "Buzz
";
array[0] = "FizzBuzz
";
var str = "";

for( var i=1; i

bit DOT ly/2GNFnBa

Attached: 1522973743391.png (375x350, 147K)

>var array = [];
disgusting

perl -e 'say "Fizz"x!($_%3)."Buzz"x!($_%5)||$_ for 1..100'
Shortest I've been able to find.

What's wrong with that?

if !(i % 15)
corrected for you mate.

got you f@m


for(int y = 1; y

make it x < y/3 you don't need keep looping after that

>range(1, 100):
This would only go up to 99 range ins't inclusive for the right argument
We'll keep your resume and give you a call

>Better as in solving it without modulo without cheating with division
So the word you mean to say is 'different'

for (int i = 0; i < 101; i++)
{
if (i % 3 == 0 & i % 5 == 0)
Console.WriteLine("Fizzbuzz");
else if (i % 3 == 0)
Console.WriteLine("Fizz");
else if (i % 5 == 0)
Console.WriteLine("Buzz");
else
Console.WriteLine(i);
}

I'm not even good at programming and this is trivially easy

>trivially easy
>didn't actually follow the specifications in the OP
What website did you copy this from user?

I already knew what fizzbuzz was and didn't read the rest of OP

I hope you're not actually studying CS

import fizzbuzz
fizzbuzz()

Whats so hardto understand?

#include "stdafx.h"
#include
#include
#include

bool doYouWishToContinue() {
std::cout

Can anyone do it in ShaderToy though? Some mad bastard did a chip8 emulator so it must be possible.

I'll look for any opportunity to use malloc
#include
#include

int main(){

int i, j = 0;
int *ptr = malloc(100*sizeof(*ptr));

for(i = 0; i

Only the top 1%

Get on my level, scum.
;
; Fizzbuzz for 8086 processors running DOS
;

.model small
.stack 100h

.data

fizz db 'fizz','$'
buzz db 'buzz','$'
crlf db 13,10,'$'

.code

start:
mov ax, @data
mov ds, ax
mov cx, 1
xor ax, ax

test3:
xor dx, dx
mov ax, cx
mov bl, 3
div bl
cmp ah, 0
jne test5
mov dl, 1
push ax dx
call PrintFizz
pop dx ax

test5:
mov ax, cx
mov bl, 5
div bl
cmp ah, 0
jne do_crlf
mov dh, 1
push ax dx
call PrintBuzz
pop dx ax

do_crlf:
cmp dx, 0
jnz newline

mov ax, cx
mov bl, 10
div bl

push ax
cmp al, 0
jz print_units
mov dl, al
add dl, 48
mov ah, 2
int 21h
pop ax
print_units:
mov dl, ah
add dl, 48
mov ah, 2
int 21h

newline:
call PrintCRLF
inc cx
cmp cx, 100
jle test3

mov ax, 4c00h
int 21h

PrintFizz:
mov dx, OFFSET fizz
mov ah, 9
int 21h
ret

PrintBuzz:
mov dx, OFFSET buzz
mov ah, 9
int 21h
ret

PrintCRLF:
mov dx, OFFSET crlf
mov ah, 9
int 21h
ret

end start

What percent of Jow Forums can solve this?

projecteuler.net/problem=14

Attached: euler_14.png (783x400, 53K)

for i in range(1, 101):
if i % 3 == 0 and i % 5 == 0:
print(str(i) + ", Fizz-Buzz")
elif i % 3 == 0:
print(str(i) + ", Fizz")
elif i % 5 == 0:
print(str(i) + ", Buzz")

else:
print(i)


If this is giving you trouble, you ought to leave this board.

This. It's mostly a trick interviewers play to filter for the most advanced coders.

Attached: Screen Shot 2018-04-08 at 9.12.13 PM.png (1016x570, 81K)

>The only worth I can see in code is how much value it can bring to my boss's business
You are so cucked man.

I can solve it, it's easy. If something is too much harder, I can't solve it at all.
> t. introductory CS "c" grade, never went further with it, & dropped out of college

Managed to get the answer with this code. It runs real slow, but I'm not sure if it's my shitty code, my shitty computer, or maybe both.

recordNum = 0
recordSteps = 0

for i in range(1, 1000001):
print(i)
x = i
steps = 0
while True:
if x == 1:
print("Steps:", steps)

if steps > recordSteps:
recordSteps = steps
recordNum = i

break
elif x % 2 == 0:
x /= 2
steps += 1
elif x % 2 != 0:
x *= 3
x += 1
steps += 1

print(recordNum, recordSteps)


Also, confirmed demon

brute force

def collatz(x):
results = {}
for i in range(x, 1, -1):
results[i] = 0
num = i
while num > 1:
if num % 2 == 0:
num = num / 2
else:
num = 3 * num + 1
results[i] += 1
return max(results, key=results.get)

collatz(1000000)

Is there anyway besides creating a couple loops and if statements and going through every single number?

not testing because lol big computations in javascript

let SequenceCount=function(n,terms=0){
terms++;
if(n===1){
return terms;
}
else{
if(n%2==0){
return SequenceCount((n/2),terms);
}
else{
return SequenceCount((3*n+1),terms);
}
}
}

let winner=1;
for(i=1;iwinner){
winner=outcome;
}
}

When will fucking de/g/enerate students leave this place? I'm getting tired of this fizzbuzz bullshit.
YOU ARE NOT SUPPOSED TO FUCKING LEARN HOW TO DO A FUCKING FIZZBUZZ, YOU RETARDS. Were I to be a potential employer of your sorry ass, noticing you had wasted your time LEARNING FUCKING FIZZBUZZ would be a red flag for me no smaller than you failing to solve the very same fizzbuzz.

Yeah, it's a really simple exercise. That's the point.

oops, I think I screwed up the For Loop
winner needs to equal i when termsoutcome>function return

Fixed
Executed it, got 837799, browser slowed for several seconds but didn't crash

let SequenceCount=function(n,terms=0){
terms++;
if(n===1){
return terms;
}
else{
if(n%2==0){
return SequenceCount((n/2),terms);
}
else{
return SequenceCount((3*n+1),terms);
}
}
}

let winner=1;
let winnerterms=1
for(i=1;iwinnerterms){
winner=i;
winnerterms=outcome;
}
}
console.log(winner);

Save your results!!! Consider creating an empty array of one million values, and storing the length of the Collatz chain for that integer when you find it.

Then, if you are computing a later Collatz chain and you get to one of the previously integers, you know that the chain's remaining length is what you've already seen. That's dynamic programming.

sorry
*the integer corresponding to each array index
and
*the previously-seen integers,
I'm hopped up on ES

For the record, this is called memoization

I don't mean to brag but I've beaten you by a few orders of magnitude in time.

Entire code here pastebin.com/ZsAMGbKa

All the one million sequences are 100% parallelized, it runs in the blink of an eye.

Attached: Screen Shot 2018-04-09 at 01.17.32.png (845x758, 142K)

user, the point of the challenge is not to show off how many resources you can throw at the problem.

Attached: peep and mous.jpg (568x548, 30K)

t. single thread virgin
bow to the concurrent chad

>All the one million sequences are 100% parallelized

How's that? Can't have 1 million threads. I've never dove into Elixir or Erlang but plan to at some point.

Elixir processes aren't CPU threads, I guess fully parallelized isn't exactly the right word, but they are very lightweight. The thing is that erlang is extremely efficient at spawning "threads" (called processes). Switching between processes takes 20 nano seconds, while switching OS threads takes up to 1000 nano seconds. So for one erlang/elixir process you have the bang of about 50 OS threads. It's incredibly fast to parallelize your work. And because there are no side effects it's super easy as well, you don't have to care about mutexes, semaphores, etc.

How about the other 613 problems?

Attached: 1512054750360.png (1513x336, 25K)

Also I said elixir processes, but I should have said BEAM processes to be fair, all the concurrency takes place in the erlang virtual machine.

module Fizzbuzz where

fb :: Integer -> String
fb x
|(x `mod` 3 == 0)&&(x `mod` 5 == 0) = "FizzBuzz"
|(x `mod` 3 == 0) = "Fizz"
|(x `mod` 5 == 0) = "Buzz"
|otherwise = show x

main = print (map fb [1..100])