[Boards: 3 / a / aco / adv / an / asp / b / biz / c / cgl / ck / cm / co / d / diy / e / fa / fit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mu / n / news / o / out / p / po / pol / qa / r / r9k / s / s4s / sci / soc / sp / t / tg / toy / trash / trv / tv / u / v / vg / vp / vr / w / wg / wsg / wsr / x / y ] [Home]
4chanarchives logo
>impying anyone on /g/ can fizzbuzz
Images are sometimes not shown due to bandwidth/network limitations. Refreshing the page usually helps.

You are currently reading a thread in /g/ - Technology

Thread replies: 56
Thread images: 7
File: 1464623074064.png (125 KB, 694x801) Image search: [Google]
1464623074064.png
125 KB, 694x801
>impying anyone on /g/ can fizzbuzz
>>
>>54832494
I dont see whats wrong with this code? someone explain?
>>
>>54833151
It's supposed to use loops. Not random ifs like the code on the pic
>>
>>54833151
the problem is that he hasnt done the 'fizzbuzz' bit baka
>>
File: Police brutality.webm (2 MB, 720x404) Image search: [Google]
Police brutality.webm
2 MB, 720x404
>>54833151
>>
>>54833254
holy fuck, that webm? did the cop get fired?
>>
>>54833254
does the cop have a dslr around his neck? did he confiscate it or did he show up to work like "this is a chance to practice my photography"?
>>
get on my level scrubs

#include <stdio.h>

int main()
{
int i = 1;

counter:
while (1)
{
printf("%d, ", i++);
if(i > 100) goto exit;
if(i % 3 == 0) goto fizzer;
if(i % 5 == 0) goto buzzer;
}

fizzer:
while (1)
{
printf("Fizz");
if(i++ % 5 == 0) goto buzzer;
printf(", ");
if(i > 100) goto exit;
if(i % 5 == 0) goto buzzer;
if(i % 5 && i % 3) goto counter;
}

buzzer:
while (1)
{
printf("Buzz, ");
if(++i > 100) goto exit;
if(i % 3 == 0) goto fizzer;
if(i % 5 && i % 3) goto counter;
}

exit:
return 0;
}
>>
File: received_1121789351178798.jpg (10 KB, 200x299) Image search: [Google]
received_1121789351178798.jpg
10 KB, 200x299
>>54833370

>goto

Look at him! Look at him and laugh!
>>
>>54833460

it just werks
>>
>>54833370
nice goto bait... next time post something more DRY
>>
>>54833514

i like my code like my bitches.... totally not DRY.
>>
>>54833151
It doesn't loop, so it prints "1\n" then skips all the else ifs and presumably exits
>>
>>54833531
I didn't catch that, could you say again?
>>
>>54833370
Get on MY level.
#include <stdio.h>

int main()
{
int i = 1;

counter:
printf("%d, ", i++);
if(i > 100) goto exit;
if(i % 3 == 0) goto fizzer;
if(i % 5 == 0) goto buzzer;
goto counter;

fizzer:
printf("Fizz");
if(i++ % 5 == 0) goto buzzer;
printf(", ");
if(i > 100) goto exit;
if(i % 5 == 0) goto buzzer;
if(i % 5 && i % 3) goto counter;
goto fizzer;

buzzer:
printf("Buzz, ");
if(++i > 100) goto exit;
if(i % 3 == 0) goto fizzer;
if(i % 5 && i % 3) goto counter;
goto buzzer;

exit:
return 0;
}
>>
>>54833571
Shouldn't i be 0?
>>
>>54833571

That is pretty neat, actually. Close to assembly-style..

Let's try to make it in OOP..

abstract class FizzBuzzOutput{
public abstract String envoke(int i);
}

class Fizzer extends FizzBuzzOutput{
public String evoke(){
return "fizz";
}
}

class Buzzer extends FizzBuzzOutput{
public String evoke(){
return "buzz";
}
}


class fizzBuzz{

public static void main(String[] args){
FizzBuzzOutput myFizzer = new Fizzer();
FizzBuzzOutput myBuzzer = new Buzzer();
String myOutput;
int i;

for (i = 0; i < 100; i++){
myOutput = "";
if (i % 3 == 0){
myOutput = myFizzer.evoke();
}
if (i % 5 == 0){
myOutput = myOutput + myBuzzer.evoke();
}
if (myOutput == ""){
myOutput = Integer.toString(i);
}

System.out.println(myOutput);
}
}
}
>>
>>54833987
>this is what fp fags actually believe about oop
>>
>>54833987

Ah well, it could be better. I'm to lazy right now, but it shoudl contain:

1) A "FizzBuzzOutput" subclass which returns only numbers (in String format).

2) An output class which gets an "FizzBuzzOutput" and uses the "evoke()" method and prints it to System.out.

3) The control logic lies within a specific object. It decides wether it gives the "Fizzer", the "Buzzer" or the "Numeric" to the output class.


I failed OOP, senpai..

;_;
>>
>>54833987
https://github.com/EnterpriseQualityCoding/FizzBuzzEnterpriseEdition
>>
>>54832494

#include <iostream>
#include <string>

int main() {
for(unsigned n=1; true; ++n) std::cout << (n%3 == 0 ? "fizz" : "") << (n%5 == 0 ? "buzz" : "") << (n%3 && n%5 ? std::to_string(n) :$
}
>>
>>54834134
#include <iostream>
#include <string>

int main() {
for(unsigned n=1; true; ++n) std::cout << (n%3 == 0 ? "fizz" : "") << (n%5 == 0 ? "buzz" : "") << (n%3 && n%5 ? std::to_string(n) : "") << std::endl;
}
>>
>>54834086

Hahaha, this is great!


I mean the guy overdoes it for the lulz, you would never use a "NewLineStringPrinterFactory".

But the general principle of choosing a strategy and passing objects arround is totally valid among OOP.
>>
>>54834179

Not only that, but the overengeneering of patterns is just great. It does make for awesome extensibility and maintainability, tho ;)

Check out these too (I do like Spring, tho):
docs.spring.io/spring/docs/2.5.x/javadoc-api/org/springframework/aop/config/SimpleBeanFactoryAwareAspectInstanceFactory.html
https://docs.spring.io/spring/docs/2.5.x/javadoc-api/org/springframework/aop/framework/AbstractSingletonProxyFactoryBean.html
>>
>>54834179
Also, check out the issues for additional lulz.
>>
File: dependency_management.png (300 KB, 1024x695) Image search: [Google]
dependency_management.png
300 KB, 1024x695
>>54834210

Yay, that's why so many people are making fun of OOP.

And the sad part is that if you actually use a higher level of OOP you will eventually end up with that level of abstraction..
>>
>>54834225

Thanks, made my day..
>>
include iostream

using namespace std
void main
(
cout << "1" << endl;
cout << "2" << endl;
cout << "Fizz" < endl;

return " I can keep going xd "
)
>>
>>54834481
>void function
>return
>>
File: webdevlol.png (229 KB, 537x783) Image search: [Google]
webdevlol.png
229 KB, 537x783
It works.
>>
File: ruby.png (166 KB, 1024x1024) Image search: [Google]
ruby.png
166 KB, 1024x1024
>>54832494

Out of the way guise, superior language coming through

(1..100).each do |i|
s = ""
s << "Fizz" if (i % 3 == 0)
s << "Buzz" if (i % 5 == 0)
puts (s.empty? ? i : s)
end


Or my super great one line version:

(1..100).each {|i| puts (s = "#{'Fizz' if (i % 3 == 0)}#{'Buzz' if (i % 5 == 0)}").empty? ? i : s  }
>>
>>54834515
>asked to do a programming task
>link to StackOverflow question/answer instead

webdevlol.png
>>
>>54833151
it's the
using namespace std;

never use namespace std
>>
>>54832494
for i in $(seq 1 100); do
if [ $((i % 15)) -eq 0 ]; then
printf 'FizzBuzz '
elif [ $((i % 3)) -eq 0 ]; then
printf 'Fizz '
elif [ $((i % 5)) -eq 0 ]; then
printf 'Buzz '
else
printf '%s ' "$i"
fi
done
>>
> using conditional logic
whichfizz = fn
(0, 0, _) -> "FizzBuzz"
(0, _, _) -> "Fizz"
(_, 0, _) -> "Buzz"
(_, _, n) -> n
end

fizzbuzz = fn (n) ->
whichfizz.(rem(n, 3), rem(n, 5), n)
end

IO.inspect Enum.map(1..100, fizzbuzz)
>>
>>54833254
I love that little smirk he gives.
>>
public class FizzBuzz {
public static void main(String[] args) {
for(int i= 1; i <= 100; i++) {
System.out.println(i % 15 != 0 ? i % 5 != 0 ? i % 3 != 0 ?
i : "Fizz" : "Buzz" : "FizzBuzz");
}
}
}


t. Panjeet
>>
>>54833987
>>54834060
>>54834086
>use oop to create a cluster fuck of useless code
>"hurr durr oop sucks"

You wouldn't use OOP for FizzBuzz.

But if you did, your abstract class or interface would be something you might actually want to extend in the future like TestValue.

You would then have a concrete TestFizzBuzz.

TestFizzBuzz would override some method that provides string output for reporting.

Now in the future you could have any number of classes that analyze a value and provide information about it in a report.

TestInteger output: "Value is 3 and is an integer."
TestCreditCard output: "Value is 3 and is not a credit card number."
TestDate output: "Value is 3 and is not a date."
TestFizzBuzz output: "Value is 3 and is fizz but is not buzz."

You don't abstract every fucking thing to end up with a 9,001 node class diagram. You abstract what might change or need to be extended in the project.

What are people being exposed to today in college or work that encourages them to use OOP to over engineer every god damn little problem?
>>
print("\n".join(["fizzbuzz" if not i%15 else "buzz" if not i%5 else "fizz" if not i%3 else str(i) for i in range(1,101)]))
>>
>>54835090
B-but it's a no-nonesense implementation.
It says so at the top of the page, sempai!
>>
>>54832494
>No Rust
fn main() {
for i in 1..100 {
if (i % 3 == 0) && (i % 5 == 0) {
println!("FizzBuzz");
} else if i % 3 == 0 {
println!("Fizz");
} else if i % 5 == 0 {
println!("Buzz");
} else {
println!("{}", i);
}
}
}


There's probably a much better way to do this but I don't know Rust and I'm tired af
>>
Clojure
(ns fizzbuzz.core)

(defn saysomething [input shouldmatch whattosay]
(if (integer? (/ x y) input shouldmatch)
(str whattosay)))

(defn fizz [x] (saysomething x 3 "fizz"))
(defn buzz [x] (saysomething x 5 "buzz"))

(defn fizzbuzz [x]
(let [output (str (fizz x) (buzz x))]
(if (clojure.string/blank? output)
x
output)))

(defn -main []
(println (map fizzbuzz (range 100))))
>>
>>54835195
>
        if (i % 3 == 0) && (i % 5 == 0) {

Why not using 15.
>>
>>54834833
Then you should go for std:: for each namespace? Genuine question.
>>
>>54834145
Interesting
>>
>>54832494
>tfw you can fizzbuzz and nothing else
>>
File: 1356636839165.png (561 KB, 768x768) Image search: [Google]
1356636839165.png
561 KB, 768x768
>>54834833
I prefer using:
#include <iostream>
using std::cout;
using std::cin;
using std::endl;


way cleaner
>>
>>54834738
>using ruby

print "\n".join(("fizz"*(i%3==0) + "buzz"*(i%5==0)).capitalize() or str(i) for i in xrange(1,101))
>>
>>54835496
(require '[clojure.core.match :refer [match]])

(doseq [n (range 1 101)]
(println
(match [(mod n 3) (mod n 5)]
[0 0] "FizzBuzz"
[0 _] "Fizz"
[_ 0] "Buzz"
:else n)))
>>
for (i in 1:100) {
if (i %% 3 == 0 && i %% 5 == 0) {
print("fizzbuzz")
}
else if (i %% 3 == 0) {
print("fizz")
}
else if (i %% 5 == 0) {print ("buzz")}
else {
print(i)
}
}


Took me some reading up on control structures again. I started out using multiple ifs, which produces multiple outputs for some numbers.
>>
>>54837006
Excuse the horrible formatting, forgot to adjust the second else-if statement.
>>
>>54833186
>>54833548
How is the biggest noob?
The idiot who asked the question.
The idiot who replied.
Or the idiot who replied to the reply to the idiotic question.

For fucks sake, can we stop doing these kind of thing.
>>
I don't understand why mine don't work :(
#include <stdio.h>

int main(void)
{
int i;
for (i=1; i < 101; i++)
{
if (i % 3)
{
printf("%s","Fizz");
}
else if (i % 5)
{
printf("%s","Buzz");
}
else if (i % 5 && i % 3)
{
printf("%s","Fizz Buzz");
} else {
printf("%d",i);
}
}
return 0;
}
>>
>>54837126
The last control statment is never reached because the first two will be true.

People seriously don't understand how else if works and it blows my mind.
>>
>>54837126
try this

#include <stdio.h>

int main(void)
{
int i;
for (i=1; i < 101; i++)
{
if (i % 5 && i % 3)
{
printf("%s","Fizz Buzz");
}
else if (i % 3)
{
printf("%s","Fizz");
}
else if (i % 5)
{
printf("%s","Buzz");
} else {
printf("%d",i);
}
}
return 0;
}


>>54837396
stop being mean to summerfags. They are the futur /g/tards.
>>
Atleast we know what the superior language is. Your guys' code looks like shit.
public static String fizzbuzz(int yourNumber){
String fizzbuzz = "";
if(yourNumber % 3 == 0){fizzbuzz = "fizz";}
if(yourNumber % 5 == 0){fizzbuzz += "buzz";}
return fizzbuzz;
}

Thread replies: 56
Thread images: 7

banner
banner
[Boards: 3 / a / aco / adv / an / asp / b / biz / c / cgl / ck / cm / co / d / diy / e / fa / fit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mu / n / news / o / out / p / po / pol / qa / r / r9k / s / s4s / sci / soc / sp / t / tg / toy / trash / trv / tv / u / v / vg / vp / vr / w / wg / wsg / wsr / x / y] [Home]

All trademarks and copyrights on this page are owned by their respective parties. Images uploaded are the responsibility of the Poster. Comments are owned by the Poster.
If a post contains personal/copyrighted/illegal content you can contact me at [email protected] with that post and thread number and it will be removed as soon as possible.
DMCA Content Takedown via dmca.com
All images are hosted on imgur.com, send takedown notices to them.
This is a 4chan archive - all of the content originated from them. If you need IP information for a Poster - you need to contact them. This website shows only archived content.