2018

>2018
>there are people who don't write fizzbuzz using recursion

Attached: 1512499722688.png (286x368, 197K)

Other urls found in this thread:

pastebin.com/F5k9KXkv
twitter.com/AnonBabble

>there are people who willing spend years of their lives learning to program instead of being a Chad fast-track executive that gets paid to boss them around

Attached: 9B0AD82A-107B-4FBA-B779-4CA8200C1A17.png (500x672, 313K)

Removing skeleton's curse

Fuck off OP. I literally just graduated with a 4.0 is computer science. Fizzbuzz is a meme and nobody cares that you can write some shitty program.
>using recursion
Haha so fucking funny shithead. That's not how recursion works. It's impossible to write fizzbuzz with recursion. Fuck off with the rest of the try hard shitters on the board thinking they're so smart for being able to solve trivia questions.

>adding recursive overhead when there is no need

????

Attached: 1470763693068.jpg (322x279, 50K)

>it's impossible to write fizzbuzz with recursion
i want neo/g/ to leave

int fizzbuzz_recursive(int i)
{
if(i > 100) {
return 1;
}

if((i % 15) == 0) {
printf("fizzbuzz\n");
} else if((i % 3) == 0) {
printf("fizz\n");
} else if((i % 5) == 0) {
printf("buzz\n");
}
else {
printf("%d\n", i);
}

return fizzbuzz_recursive(i + 1);
}

That's just a worse way of doing fizzbuzz. Don't use recursion when you don't have to, you're just pushing more data on and off the stack. There's no calculation ocurring before recalling the function; you're just calling it with i + 1 each time. It's idiotic, just call the function over and over again in a loop.

This. By using recursion for such a simple task you're just adding more function calls which slows the whole program.

the argument wasn't whether it was a good idea, it was whether it is doable

>Don't use recursion when you don't have to, you're just pushing more data on and off the stack
What college was your degree from?

except for the part where he's actually correct in this, the arguments and return address for the call are pushed to the stack on every invocation

who gives a fuck about the stack it's 2018 use recursion and actors everywhere

What college was your degree from where they have never even began to mention what a trivial optimization TCO is? Any good compiler will compile that recursive fizzbuzz to a loop. Even the bad ones will. Hell, many languages have TCO mandated.

n.b. the one exception here is tail call optimisation

>Intuitively, no space is needed for an active tail call because the continuation that is used in the tail call has the same semantics as the continuation passed to the procedure containing the call. Although an improper implementation might use a new continuation in the call, a return to this new continuation would be followed immediately by a return to the continuation passed to the procedure. A properly tail-recursive implementation returns to that continuation directly.

I really don't want to be confused with the guy who said it wasn't possible. That guy is orders of magnitude more idiotic than you guys who are definitely---despite saying otherwise now that you know you're wrong---arguing that recursion is better in this instance. The fact that someone gave him a cs degree makes me kind of depressed desu. There's really nothing you CAN'T do with recursion, even if it may be idiotic to do so.

>not programming bullshit for the sake of programming bullshit
Obviously an iterative solution is better but making the recursive implementation is fun.

I think you need to get a fresh perspective. read this book.

Attached: 1486500723332.jpg (1280x720, 128K)

legit taking retard pills today, I'm well aware of TCO but forgot to mention that it'd apply in this instance, see it's just generally best for people to be aware of potential pitfalls in instances where it can't be optimised out with TCO

Also
>writing a function that isn't reusable for different fizzbuzz maxes.
>not writing it in the way the compiler naturally optimises it to.

I'm not a cs major so I will likely be wrong about the finer points.

I don't see any reason why recursion is preferable here. Even if the function were made more reusable by adding a second parameter for the max to fizzbuzz up to, that parameter would be passed with each call. And obviously a wider-scope variable is an even poorer solution. Just slap a for loop in your function and call it once with a max as a parameter.

>I don't see any reason why recursion is preferable here.
It's not.

Am I genuinely autistic?
I get joy out of programming code that is robust, well-made, and safe. Looking back at my old, poorly-written code makes me sick to my stomach. I love spending hours contemplating different implementations and their pros and cons.
But I guess most people here just like taking piles of shit and slopping them together into a steaming pile and declaring their work done. "But look, this shit has corn in it! Corn! Bet you haven't seen that before!" Sorry, but it just doesn't appeal to me.

(defun fizzbuzz-rec (n &optional (res))
(cond
((equal n 0) res)
(t
(let ((ans))
(if (zerop (mod n 15))
(setf ans "FizzBuzz")
(if (zerop (mod n 3))
(setf ans "Fizz")
(if (zerop (mod n 5))
(setf ans "Buzz")
(setf ans n))))
(push ans res)
(fizzbuzz-rec (- n 1) res)))))

I think you're genuinely autistic
Someone appealed to authority with "muh 4.0 GPA degree!" and asserted something retarded, and was subsequently proven wrong

You might learn something interesting from implementing things in an unconventional way. Of course doing fizzbuzz recursively is pretty basic and boring.

see

But you're legit wrong. There is legitimately nothing wrong with even non tail call optimized recursion. This retarded fucking idea that you can never be tail recursive is so goddamn pervasive.

This isn't 1977 and we have more than 256 bytes of stack space for most applications. The stack pointer is larger than a byte.

You aren't being "aware" of pitfalls, you're just repeating this definitely outdated by now mantra that has persisted for legit 40 years.

>not writing it in the way the compiler naturally optimises it to.
That would mean, well, unrolling loops for one. You have no idea how unreadable compilers make code. Also protip your CPU optimizes assembly too.
>writing a function that isn't reusable for different fizzbuzz maxes
I hear a lot of professional fizzbuzzers like yourself repeat this. I recommend reading a book on agile or lean software development or something. You don't want to ADD additional requirements the customer didn't ask for. That's the waste of overprocessing.

>that parameter would be passed with each call
user that is such a trivial optimization. You're even implying that the code even is compiled to anything remotely resembling a function call.

t. webdev

Everyone gets enjoyment out of doing that, don't worry.
Taking novel approaches to old problems can result in both fun and, sometimes, innovation. It's a good exercise.

Sometimes it's just fun to do. "Ayy recurisive fizzbuzz. Dave, come take a look at this" and then you lose an afternoon worth of productivity coming up with different versions. It's just dumb fun for "smart" people.

Performance doesn't matter, aesthetics is what's actually important.
For loops are objectively hideous.

Attached: 1458945615421.png (861x758, 26K)

>having the function epilogue run a few thousand times because you've decided to implement things the retarded way rather than give any thought as to how to implement something is somehow novel now
>hurr you have 8MB of stack space, why not make use of it
you are the cancer killing this field

basically this

B-but my nodejs fizzbuzz package only uses 300MB ram. It's efficient!

I (the autist) am not that guy (the cs major who thought recursive fzbz was impossible)

Why?

>He doesn't know about tail call optimization.

Attached: smug_laugh.png (782x1021, 330K)

>responding to the beginning of a thread-long argument just so you could use an anime reaction image

>Remove important functionality because the "customer" didn't ask for it

Holy shit are you on the GNOME dev team? Wtf are you gonna do as soon as you want to fizzbuzz to 1000 instead of 100? Rewrite the function? Or tell the user to call the function ten times and "just add ten more to the results each time". That attitude is literally cancer and the way you suggest I read a book that it sounds like you never read is even more cancer.

Also I am not completely unfamiliar with assembly, and I obviously wasn't implying that you should write your fizzbuzz conditional jumps and mov ops.

The issue is that you're writing a function that is not reusable---so shouldn't even really be made into a function---and your writing it in a way that is optimized by good compilers to resemble the results of compiling code written in a more natural way. Most c++ compilers are good, but what if you wish to fizzbuzz in a different language with less optimization-happy compilers/interpreters? Yes, you are being aware of pitfalls, there is no reason to be willfully ignorant.

*one hundred more

(defun fizz-buzz(x)
(when (eq 1 x)
(write-line "1")
(return-from fizz-buzz))
(cond ((eq 0 (mod x 15)) (format t "~d: FizzBuzz~%" x))
((eq 0 (mod x 5 )) (format t "~d: Buzz~%" x))
((eq 0 (mod x 3 )) (format t "~d: Fizz~%" x))
(t (format t "~d ~%" x)))
(fizz-buzz (- x 1)))

learning clisp

Attached: sicp h2.jpg (2236x1600, 730K)

So did GCC, but not from the standard

I'm actually a graphics programmer. btw have a fizzbuzz:

(use srfi-1)
(define (fizzbuzz n)
(cond ((= (remainder n 15) 0) "FizzBuzz\\n")
((= (remainder n 5) 0) "Buzz\\n")
((= (remainder n 3) 0) "Fizz\\n")
(else "%d\\n")))
(with-output-to-file
"fizzbuzz.c"
(lambda ()
(display "
#include
char * precomp[] = {
")
(for-each (lambda (e) (printf "\"~A\", " (fizzbuzz e))) (iota 15))
(display "NULL };")
(display "
int main() {
int m = 100;
int x = -15;
while(x < m) {
x+=15;
")
(for-each (lambda (e) (printf "printf(precomp[~A],x+~A);\n" e e)) (iota 15))
(display "
}
int i = 0;
while(x < m) {
printf(precomp[i],x);
++i; ++x;
}
}
")

))


After all this thread you STILL don't know about TCO?

nice

>oh you have a new requirement customer? That will be easy because my code isn't a bloated pile of trash filled with shit you didn't pay for. Here you go!
Really dude? You keep your product conforming TO spec so it's easy to modify the spec.

was in reference to "There is legitimately nothing wrong with even non tail call optimized recursion"

There still literally is. The simple non-iterative implementation of MAP as in MAPCAR, MAP/REDUCE is much faster than the simple loop version. You have to reach into some very advanced techniques (unreadable code) to beat the non tail call optimized version.

Allow me to rephrase: The primary argument in that post was "don't go about implementing things recursively if the iterative solution is better"/"don't use the overabundance of resources available to you as an argument for doing something"
other than that we're in agreement

Jow Forums- art of fizzbuzz
here is the recursion abomination, I wonder how large a range of numbers this thing would work for before crashing

let RecursionMeme=function(n){
if(n===100){
console.log(n);
return 0;
}
else{
if(n%3===0 && n%5===0){
console.log("FizzBuzz");
RecursionMeme(n+1);
}
else if(n%3===0){
console.log("Fizz");
RecursionMeme(n+1);
}
else if(n%5===0){
console.log("Buzz");
RecursionMeme(n+1);
}
else{
console.log(n);
RecursionMeme(n+1);
}
}
}
RecursionMeme(1);

why would you do that when you could type 5 lines with a for loop and call it a day.

#include
int main()
{
for( int i = 1; i

>i=0
>iconditionals in a print statement

Attached: 1520694946097.jpg (365x517, 109K)

>uses lisp
>still can't into functional fizzbuzz
std::string fizzbuzz(int x){
auto what = [=](int n, std::string s, std::function f){
return x % n == 0 ? [=](std::string){ return s + f(""); } : f;
};
auto is = std::bind(what, 3, "fizz", std::placeholders::_1);
auto applicative = std::bind(what, 5, "buzz", std::placeholders::_1);
auto retard = [](auto s){ return s; };
return is(applicative(retard))(std::to_string(x));
}

int main(){
std::vector sepples(15);
std::iota(std::begin(sepples), std::end(sepples), 1);
for (auto i : sepples){
std::cout

why did you build 100 as the limit instead of passing it as an argument? certified idiot.

Alright sounds good. By the way have a fact check on my claim about map:
(use srfi-1)
(define (map f xs)
(if (null? xs)
'()
(cons (f (car xs)) (map f (cdr xs)))))
(define (map/shit f xs)
(let loop ((acc '()) (rem xs))
(if (null? rem)
(reverse acc)
(loop (cons (f (car rem)) acc) (cdr rem)))))
(define (map/great f xs)
(let ((ret (cons (f (car xs)) '())))
(let loop ((pair ret) (xs (cdr xs)))
(unless (null? xs)
(set-cdr! pair (cons (f (car xs)) '()))
(loop (cdr pair) (cdr xs))))
ret))

(define dat (iota 2000000))
(time (map (cut + 1) dat))
(time (map/shit (cut + 1) dat))
(time (map/great (cut + 1) dat))


>uses lisp
>doesn't use nonfunctional bits when appropriate

fugg forgot to post results
0.212s CPU time, 0.053s GC time (major), 4000000/1987073 mutations (total/tracked), 1/151 GCs (major/minor), maximum live heap: 91.79 MiB
0.35s CPU time, 0.105s GC time (major), 1/854 GCs (major/minor), maximum live heap: 91.79 MiB
0.135s CPU time, 1999999/763 mutations (total/tracked), 0/763 GCs (major/minor), maximum live heap: 91.79 MiB

because I don't care about being too fussy for the daily fizzbuzz thread
just imagine a second function parameter named limit and replace the first If with

if(n===(limit+1)){
return 0;
}

or something like that

My point was doing it in as few lines as possible you gimp

>uses lisp
>thinks functional is ever worse choice
Thankfully i never got the cancer that is lisp, i use Haskell primarily.

then why even use new lines you brainlet

So it would still be semi-readable you weirdo. If you wanna take out the new lines, go ahead

Sorry to burst your comfy gnome bubble, but being able to fizzbuzz up to a given value rather than 100 every single time is the FIRST FUCKING FEATURE anyone would want in fizzbuzz. In no way is it bloat.
Also I AM the customer, I want to fizzbuzz up to whatever goddam number I want. 1000! 10,000! Heck, I want you to slap an "unsigned" in front of that int and let me fizzbuzz up to 2^[whatever it is on my system]-1.

>javascript

OH NO NO NO

oh, and add in the second argument to all the recursive statements too otherwise it'll keep going till error, confused me for a bit why that as happening
it reached n=41117 at most by the way in case you're wondering, that's a lot of recursion

:3

Hopefully not with recursion

>writes 4 calls to RecursionMeme instead of one at the end of the first else

oh you have a new requirement customer? That will be easy because my code isn't a bloated pile of trash filled with shit you didn't pay for. Here you go mr customer! 1 fizzbuzz from 0 to something much larger than the age of the universe in nanoseconds. You'll receive the invoice tomorrow morning.
pastebin.com/F5k9KXkv

what, customer? We already made you a calculator app. What's that? You want to be able to do something with the calculator other than add 3 and 7? Well gotdam, why didn't ya tell us! We honestly thought you just wanted to only add 3 and 7 using this calculator. Thankfully our code is extremely "minimalist" so adding the functionality to add 4 and 7 as well will be very easy for us. What? You want to be able to add any arbitrary combination of numbers? You want the same with other common mathematical operations? Jesus, we're making a calculator not a fucking sage here!

>not writing a business contract first
you deserve to go out of business.

This is why you're a NEET and he's got a job. You want to squeeze as much money from customers as possible, while doing as little work as possible. What's not in the contract/spec doesn't get implemented, even if it's as trivial as calculator being able to work with arbitrary numbers.

>"please make a calculator"
>k here's a program that adds 2 and 7 every time
>"why"
>If I made a functioning calculator as per your request I'd somehow working as little as possible while extorting you, its for your own good
>"makes sense, thanks for the calculator, this was a good use of my money and I will be returning to you with more business"
>btw the calculator I gave you is recursive, that's what this thread is about

Can't go out of business if you're not in business

Attached: 3D27386D-78BA-4F79-A9E5-BA2F8CC09459.jpg (680x680, 78K)

oh you're right, how silly of me

Why should we even learn it anyway? '~'
I mean, it's not like we'll ever use it, it's just elitist discrimaover the tiny things

Attached: fizzbuzzed_0.png (1848x2018, 391K)

Procedures on trees are naturally recursive. even if you implement some of them without recursion you're still implicitly using it through some kind of data structure somewhere such as a zipper.