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

H-How's my fizzbuzz guys? Am I ready to finally get a job?

This is a blue board which means that it's for everybody (Safe For Work content only). If you see any adult content, please report it.

Thread replies: 67
Thread images: 9

File: 1460623005667.png (37KB, 1127x685px) Image search: [Google]
1460623005667.png
37KB, 1127x685px
H-How's my fizzbuzz guys? Am I ready to finally get a job?

    public static void main(String[] args) {
for (int i = 1; i <= 50; i++) {
if (i % 3 == 0 && i % 5 == 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);
}
}
}
}
>>
>>59820488
>java
>>
>>59820488
LOL
>>
Well you know the modulus operator exists so I guess?
>>
>>59820488
>String[] args
>String
>Capital s
Why would they do that?
>>
File: image.jpg (513KB, 1000x597px) Image search: [Google]
image.jpg
513KB, 1000x597px
>>59820488
>"Sorry but the question was: write a program to sum all the primes under 2 million"
>"We'll call to let you know our decision, now please leave before we call security"
>>
>>59820555
Because you know it's an object that way?
>>
>>59820488
> 4 divisions per iteration
> Not using bbcode code blocks

Good job kid
>>
>>59820566
>"Sorry but the question was: write a program to sum all the primes under 2 million"
Not a question.
>>
>>59820488
Can't you just have if (!(i%3)) ? A non-zero integer should be true, at least in c.
>>
>>59820555
>MuH CamelCaSE
>>
>>59820653
I haven't used java in ages but I'm fairly sure you can't do integer conditions. Has to be a boolean/boolean operator
>>
>>59820653
java is such a trash language
>>
>>59820653
Strongly-type languages don't allow you to do that.
>>
#include <stdio.h>

int main()
{
for (int i = 0; i < 50; i++) {
if (i % 3 == 0)
printf("Fizz");
if (i % 5 == 0)
printf("Buzz");
else if (i % 3)
printf("%d", i);
putchar('\n');
}
}

fixd
>>
>>59820779
C is strongly typed though because all variables must have a type. Java is stronger-typed i guess.
>>
>>59820795
i probably should've put a return 0 after that for loop but w/e
>>
>>59820566
What's an prime number?
>>
>>59820816
Just because you have to declare types doesn't mean it's a strongly-typed language. C allows a lot of implicit casting, and performing actions on variables of inappropriate types is often allowed but causes undefined behavior.
>>
>>59820566

function sumit(prime)
if prime[0] > 2000000 begin return False end
if len(prime) <= 1 begin return prime[0] end
return prime[0] + sumit(prime[1:])

>>
File: job-interview.jpg (623KB, 3000x2000px) Image search: [Google]
job-interview.jpg
623KB, 3000x2000px
>>59820827
Don't worry about that, we'll train you.
>>
>>59820861
define strongly-typed
>>
>>59820795
>Average C baby
>"durr haha shoulda wrote it in C"
>proceeds to declare a side-effect only function as an int function
>>
>>59820884
Returns an error if you declare a function as an integer and it doesn't return an int.
>>
>>59820900
nice bait
>>
>>59820488
>if (i % 3 == 0 && i % 5 == 0)
replace with
if (i % 15) {
System.out.println("FizzBuzz");
}


nothing that is divisible by 3 AND 5 is not also divisible by the LCM (15)
>>
>>59820912
How is that bait? Did you not write a side-effect only function as a function with an integer return type? Do you not know what a side-effect is, C baby?
>>
>>59820940
In C, the main function is almost always an int so you can return error codes. I just forgot to put return 0 at the end.
>>
>>59820909
A run-time error? an error while compiling? Both cases are bad definitions that hold up for Java too and you may as well say statically/dynamically typed.
>>
>>59820921
compilation error u faggot

(i % 15 == 0)
>>
>>59820964
During the type checking phase of compilation, which is almost always ran on the abstract syntax tree. Are you retarded or something?
>>
>>59820955
You're just repeating what I said. Are you retarded? Your code is shit and you're a bad programmer. Don't explain to me why you're a shit programmer. Just stop being an elitist until you're elite.
>>
>>59820555
String is an object just like there is Integer and Array
>>
File: 2017-04-09-162623_1701x69_scrot.png (38KB, 1701x69px) Image search: [Google]
2017-04-09-162623_1701x69_scrot.png
38KB, 1701x69px
>>59821039
why are you so angry about this lmao
>>
>>59820884
>>59820861
C allows integer conditions because C has no primitive boolean. Low level code treats integers like booleans, ie if 0 the ZF (zero flag) is set, otherwise it's not. C++ allows it as an extension on C. Java doesn't allow it because it was designed with things like readability in mind.

But in C it's definitely not cast to anything because there's no primitive boolean to cast it to.
>>
So which is technically faster, using a conditional for mod 15, 5, and 3 causing three branching conditions, or using only mod 5 and 3 and printing a newline at the end?
>>
File: fizzbuzz.niggnog.png (5KB, 423x176px) Image search: [Google]
fizzbuzz.niggnog.png
5KB, 423x176px
Am i redy for a jawb goys???
>>
>>59821267
No because you started at 0.
>>
File: 4942842842024.jpg (116KB, 1300x866px) Image search: [Google]
4942842842024.jpg
116KB, 1300x866px
>>59821267
We'll call you at a later date to tell you our decision.
>>
>>59821324

is that chris pratt in the front?
>>
File: garrus.jpg (226KB, 2218x1551px) Image search: [Google]
garrus.jpg
226KB, 2218x1551px
I prefer mine:

#include <stdio.h>
#define LEFT_BRACE {
#define RIGHT_BRACE }
#define LEFT_BRACKET [
#define RIGHT_BRACKET ]
#define LEFT_PARENTHESIS (
#define RIGHT_PARENTHESIS )
#define SEMICOLON ;
#define COMMA ,
#define EQUALS =
#define IS_EQUAL_TO ==
#define IS_NOT_EQUAL_TO !=
#define IS_LESS_THAN <
#define IS_GREATER_THAN >
#define IS_LESS_THAN_OR_EQUAL_TO <=
#define IS_GREATER_THAN_OR_EQUAL_T >=
#define MODULUS %
#define INCREMENT ++
#define DECREMENT --
#define AND &&
#define OR ||

int main LEFT_PARENTHESIS RIGHT_PARENTHESIS
LEFT_BRACE
int i SEMICOLON
for LEFT_PARENTHESIS i EQUALS 0 SEMICOLON i IS_LESS_THAN_OR_EQUAL_TO 100 SEMICOLON i INCREMENT RIGHT_PARENTHESIS
LEFT_BRACE
if LEFT_PARENTHESIS i MODULUS 3 IS_NOT_EQUAL_TO 0 AND i MODULUS 5 IS_NOT_EQUAL_TO 0 RIGHT_PARENTHESIS
printf LEFT_PARENTHESIS "%d" COMMA i RIGHT_PARENTHESIS SEMICOLON
if LEFT_PARENTHESIS i MODULUS 3 IS_EQUAL_TO 0 RIGHT_PARENTHESIS
printf LEFT_PARENTHESIS "Fizz" RIGHT_PARENTHESIS SEMICOLON
if LEFT_PARENTHESIS i MODULUS 5 IS_EQUAL_TO 0 RIGHT_PARENTHESIS
printf LEFT_PARENTHESIS "Buzz" RIGHT_PARENTHESIS SEMICOLON

printf LEFT_PARENTHESIS " " RIGHT_PARENTHESIS SEMICOLON
RIGHT_BRACE

printf LEFT_PARENTHESIS "\n" RIGHT_PARENTHESIS SEMICOLON
return 0 SEMICOLON
RIGHT_BRACE
>>
>>59820900

By standard, the main function MUST return int. While some compilers may allow you to get away with only a warning for making main a void function, the fact remains that any other return type for main is invalid C.

Don't chastise programmers for following standard. You are the one who is in the wrong for thinking he should declare it in any other way.

>>59821242

The program is I/O bound. The cost of an extra conditional is negligible.
>>
>>59821027
Really re the original definition:

What if the function returns something that can be casted to an integer? For instance in C++ an object for which `operator int()` is defined. Or in C implicitly casting a string (a `const char*`) to an integral because you _can_ do that but idk why you'd want to.

Strong typing, to me, seems like a spectrum. You have cases like C++ (minus pointer garbage) where user defined implicit type conversions can happen. Or C, which might as well not have types, or OCaml, where God forbid you want to add an int and a float you need to use `float_of_int` and manually convert the type.
>>
>>59820921
Get the fuck out of this interview you fucking retard
>>
>>59821388
This. If you see void main a lot it's because Microsoft's extended version of C++ (Visual C++) allows you to do it and don't even bother to tell you it's wrong.
>>
>>59821242
(mod 3 and mod 5) is faster than mod 15. Most cases fall through to the else block, and in that case there's 2 divisions.

if you want to test it for yourself, replace the print calls with variable counters, change the limit from 50 to 5 million. and time it.

>>59821388
> program is I/O bound
(technically)
>>
>>59821826

>(technically)
You seem dismissive. Do you see I/O bound vs CPU bound as irrelevant for tuning the performance of a program?
>>
>>59820921
>replace with
>if (i % 15) {
Skip this entirely and append to string and print i if string is empty.
>>
>>59822043
> The cost of an extra conditional is negligible.
> You seem dismissive

he asked

> So which is technically faster, using a conditional for mod 15, 5, and 3 causing three branching conditions, or using only mod 5 and 3

Technically 2 divisions will always be faster than 3. Does replacing
 if (i % 3 == 0 && i % 5 == 0)

with
 if (i % 15 == 0)


change the amount of I/O?
>>
>>59822154

It doesn't change the amount of I/O at all. What I'm saying is that the cost difference between the two is minute compared to the cost of the I/O that is going to happen. While you should obviously be doing mod 15 instead of making two checks (if nothing else, it's less typing), there is no noticeable performance gain.
>>
>>59822200
ok stay with me here.

> doesn't change the amount of I/O at all

exactly. so take the I/O out.

    int i, a, b, c, d;
a = b = c = d = 0;

for (i = 1; i <= 50000000; ++i) {
// if (i % 15 == 0)
if (i % 3 == 0 && i % 5 == 0)
++a;
else if (i % 3 == 0)
++b;
else if (i % 5 == 0)
++c;
else
++d;
}

printf("%d %d %d %d\n", a, b, c, d);


i % 3 == 0 && i % 5 == 0 is faster because in the entire for block those conditions will be constant. they each only need to be checked once. even when compiling wth no optimization.

if you introduce i % 15, you now have 3 calculations. believe it or not the compiler won't pick up on what your trying to do (create a shorthand for i % 3 == 0 && i % 5 == 0), even with -O3 optimization. it will perform 3 seperate calculations per iteration (when i is not divisible by 3 or 5).

try it yourself.

i % 15 == 0

3333333 13333333 6666667 26666667

real 0m0.153s
user 0m0.152s
sys 0m0.000s

i % 3 == 0 && i % 5 == 0
3333333 13333333 6666667 26666667

real 0m0.125s
user 0m0.122s
sys 0m0.000s
>>
File: chromopepe.jpg (29KB, 600x482px) Image search: [Google]
chromopepe.jpg
29KB, 600x482px
how do i write inline code segments like u cool fellas
>>
>>59822200
the real bottleneck (besides I/O) is branch misprediction. Saying I/O is a bottleneck is kind of pointless becuase if one were concerned about performance you would create a string and print it once at the end of the program.
>>
>>59822350
https://www.phpbb.com/community/help/bbcode#f2r1
>>
>>59822368
>https://www.phpbb.com/community/help/bbcode#f2r1
til 4chan is php garbage
>>
>>59822154
>>59822331
That was not my question.
I was asking if it is better to do
if (i % 3 == 0) print("Fizz")
if (i % 5 == 0) print("Buzz")
print("\n")

thus forcing two branches every time vs the worst case of the previous if-else blocks.
>>
>>59822570
That would be slower. More branch misprediction.
>>
>>59820488
['Fizz'*(not i%3) + 'Buzz'*(not i%5) or i for i in range(1, 101)]

>copy'd from stackoverflow
>>
>work at a publishing house, media production, not even it
>boss comes in "hey anon, i don't have much time today, can you please do the job interview scheduled for 2pm?"
>"sure boss"
>get there, some cute girl is there
>do the job interview routine, all went well
>"just one more thing .... can you fizzbuzz?"
what have you done to me, /g/?
>>
>>59821231
NERD.
>>
>>59820566
Please stop trying to force this.
>>
>>59820488
~~~
50.times do |i|
out = ""
out += "Fizz" unless i%3
out += "Buzz" unless i%5
out += i.to_s if out==""
p out
end
>>
File: 1485038084900s.jpg (2KB, 125x125px) Image search: [Google]
1485038084900s.jpg
2KB, 125x125px
Real talk, if I can do all these pointless coding exercises on Leetcode and whatnot and explain why I'm doing what I'm doing, I should be fine at an entry level position right? I mean I have a degree too but these bullshit "let's just see if you can program at all" problems are really all they give you right?
>>
>>59826162
Honestly coding exercises are bullshit and are pointless on resume. They look better than nothing, but a company wants to see you're capable of managing a larger project, contributing to open source, extensions to existing software etc.
>>
If its dividabli with 3 print fiss
if not print buzz
else print fizzbuss
>>
>>59821380
Fucking hell anon
>>
>>59821380
max kek
Thread posts: 67
Thread images: 9


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

I'm aware that Imgur.com will stop allowing adult images since 15th of May. I'm taking actions to backup as much data as possible.
Read more on this topic here - https://archived.moe/talk/thread/1694/


If you need a post removed click on it's [Report] button and follow the instruction.
DMCA Content Takedown via dmca.com
All images are hosted on imgur.com.
If you like this website please support us by donating with Bitcoins at 16mKtbZiwW52BLkibtCr8jUg2KVUMTxVQ5
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.
This is a 4chan archive - all of the content originated from that site.
This means that RandomArchive shows their content, archived.
If you need information for a Poster - contact them.