Jump to content
gdf

Life

Recommended Posts

While I appreciate good coffee, in reality I'm much more interested in quantity and cost than quality.  So day-to-day is whatever Folger's was on sale in a cheap drip pot.  I drink like 2 pots of coffee a day. 

Share this post


Link to post
Share on other sites

Had never heard of that before. Just did it in Notepad to see whether I could remember how to code at all.

 

For some reason part of my brain forgot about for loops, and so I used a less efficient while loop, but it seems some programming has stuck with me and my little program would indeed FizzBuzz accurately.

 

I wish I had time/reason to actually code regularly again.

 

Huh, this is really interesting to me. I have never considered myself as having anything but a rudimentary understanding of programming, but it seems so simple to me. Is hard for some people because of the nature of computer science education? I'm self-taught at programming so I don't really understand the wider culture of it. Is my solution reasonable? Maybe I'm missing something.

 

for (int i = 1; i < 101; i++) {
  String fizzbuzz = "";
  if (i % 3 == 0) fizzbuzz = "fizz";
  if (i % 5 == 0) fizzbuzz = fizzbuzz+"buzz";
 
  if (fizzbuzz == "") println(i);
  else println(fizzbuzz);
}

Share this post


Link to post
Share on other sites
if (fizzbuzz == "") println(i);

Should instead read (if this is Java):

 

if (fizzbuzz.equals("")) println(i);

But other than that it seems pretty reasonable.

 

Usually most implementations use 4 cases in an if/else if/else if/else format because it's easier to read, a little more intuitive to follow, and reduces the number of conditions you have to evaluate in some scenarios (instead of always checking all three conditions). It also means that, instead of appending to an immutable string, you can just directly print the correct string per each case, which is technically more efficient.

Share this post


Link to post
Share on other sites
if (fizzbuzz == "") println(i);

Should instead read (if this is Java):

 

if (fizzbuzz.equals("")) println(i);

But other than that it seems pretty reasonable.

 

Usually most implementations use 4 cases in an if/else if/else if/else format because it's easier to read, a little more intuitive to follow, and reduces the number of conditions you have to evaluate in some scenarios (instead of always checking all three conditions). It also means that, instead of appending to an immutable string, you can just directly print the correct string per each case, which is technically more efficient.

 

So more like this?

 

for (int i = 1; i < 101; i++) {

  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);
  
}

Then, is this device about seeing if someone understands how to code efficiently? Or is it just to weed out the people who are totally clueless?

 

edit: And I was using Processing which I think is a simplified version of Java.

Share this post


Link to post
Share on other sites

That looks right to me! It's mostly used as a way to screen candidates who can't code. There have been some discussions online whether or not it's an effective/fair way to screen candidates. It's pretty interesting.

 

I've seen some people talk about how it relies heavily on the modulus operator which some programmers might not be aware of (or might not use it often enough that it comes to mind - especially in a stressful situation like an interview). It's hard for me to imagine a situation like that, but I've also been exposed to it often enough that it comes to mind anytime I see the word "divisible".

 

It's interesting though, to think of ways you could try and solve the problem without directly using modulus. I'd probably write my own function that makes use of a while loop:

 

bool divisible(int num, int divis){
   while(num > 0){
      num -= divis; 
   }

   return num == 0; //return true only if num is divisible by divis
}

Share this post


Link to post
Share on other sites

I've learned that over the last few years my ability to straight up write code by hand in notepad correctly has gone the way of my spelling skills. I rely too much on tools to correct the misprints and suggest the particular commands I need.

 

Regarding the modulus operator, I rarely use it myself. Even in active coding, I've made one by hand instead of using the built in operator because I forget it exists.

 

if (Convert.ToInt32(x/3) == x/3) {

Share this post


Link to post
Share on other sites

Yeah, I would assume it's to test knowledge of useful, but perhaps fairly uncommon operators/tools like modulus or string concatenation (depending on your specific solution. The one I wrote in python used both.)

It also makes you actually think about the structure of your if/else if/else statements. You don't want to miss out on things that are multiples of 15, so if you're doing if/else if/else statements you want to put that first for example. (I just did 3 if statements, which I doubt is the most efficient way to do it, but it was how I was able to think through the problem.)

Plus it requires you to use a for/while loop, so it kind of hits all the big concepts of pretty much any programming language.

Share this post


Link to post
Share on other sites

Wow I can't even imagine living in a world without modulus.

Share this post


Link to post
Share on other sites

Wow I can't even imagine living in a world without modulus.

 

Agreed, there are so many random times that I need to filter out odd rows of a spreadsheet or something and use modulus to do that.

Share this post


Link to post
Share on other sites

To be fair, I mostly just script in PowerShell or noodle around in Unity on my spare time. I'm not really the person these tests are aimed at.

Share this post


Link to post
Share on other sites
if (fizzbuzz == "") println(i);

Should instead read (if this is Java):

 

if (fizzbuzz.equals("")) println(i);

 

What if I told you that in Oracle's and OpenJDK it does not matter. Yay string constant pool.

But if you want the best kind of correctness you would write:

 

 

if ("".equals(fizzbuzz)) println(i);

Share this post


Link to post
Share on other sites

What if I told you that in Oracle's and OpenJDK it does not matter. Yay string constant pool.

 

Huh, you learn something new everyday. Fascinating.

Share this post


Link to post
Share on other sites

Let the fun begin:
 

String s = "";
System.out.println("" == s);
System.out.println("" == "");
System.out.println("" == s + "");
System.out.println("" + "" == s + "");
System.out.println("" + "" == "" + "");

 
result:

true
true
false
false
true


 
and now we make
 

final String s = "";

 
result:

true
true
true
true
true

Share this post


Link to post
Share on other sites

A long-time Online Gaming Buddy of mine just got a job offer here in Dallas and I'm pretty excited to have another person to hang out with. U:

Share this post


Link to post
Share on other sites

if (fizzbuzz.equals("")) println(i);

Is madness. Everyone should just use Python.

if not fizzbuzz:

Best!

Share this post


Link to post
Share on other sites

I like that as shorthand but it doesn't really make... sense? Logically? Eh. There's also stuff like "if str.Empty()" in other languages and whatever.

Share this post


Link to post
Share on other sites

The Python one is a falsy check I imagine, which is like doing this in JavaScript (best):

if ( !fizzbuzz ) someFunction();

It uses coercion to determine values as true or false. An empty string would be falsy, as would a 0, as would a boolean false. Conversely, any string, any number, or a boolean true would be truthy.

Share this post


Link to post
Share on other sites

Yeah I get what it's doing and I would gladly use it in all languages, but it just seems kind of esoteric in nature. Someone new to programming would be like "what".

Share this post


Link to post
Share on other sites

I understand the point of FizzBuzz is that it's largely a check to see if you can take a task and break it down into components. So I need to do this if this happens, and this if this happens, and I need to set that up so that it'll go through these. This is the fundamental programming skill, the ability to express what you want to happen as a series of smaller steps, but that's a way of thinking that needs to be learned.

Share this post


Link to post
Share on other sites

Yeah the Python truthiness can look quite silly for a language that's all about readability. I was suggesting it as an overly clever answer that's actually impractical since it's less readable without particular benefit. Usually truthiness is mostly useful when the variable is not of a single defined type but you want to make sure it contains something.

Share this post


Link to post
Share on other sites

I also called my uncle. I haven't spoken to him in 6+ years, but I always respected him. I'm gonna be talking to him in person on the first. I want help with all the shit I've been struggling with. As expected, my parents haven't even told any of my other relatives that I'm gay, so that's gonna be a fun conversation. I know that I should ostensibly be feeling good about this, but it still feels wrong.

 

So a brief update on this:

 

We couldn't get the scheduling to work out, so I ended up coming out to him via email last night. I told him about all the shit my parents put me through, how my job situation has been, everything. I haven't received a response yet, and I've been feeling anxious and nauseous the entire time. You'd think this would get easier each time, but it really doesn't. All I can do is wait and hope it works out fo the best, but I'm having a hard time keeping my mind off of things.

 

Also, it's kind of a downer to see the last five years of your life summed up into only a few paragraphs.

Share this post


Link to post
Share on other sites

D:!

 

I hope it goes well for you. I am bad at words, but you're a cool person and you deserve good things, so I hope it goes well for you..

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×