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

ITT post programming meme

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: 80
Thread images: 12

File: 1495489105657.png (311KB, 652x669px) Image search: [Google]
1495489105657.png
311KB, 652x669px
ITT post programming meme
>>
>>61224235
Best programming meme hehe
>>
 
for(int i = 1; i<b; i++)
a+= a;

>>

if(a == 1){
if(b == 2){
// do something here
}
}
>>
>>61227529
i<=b
>>
>>61227581
you right
i did i = 0 originally
>>
>>61227594
yeah we're so used to starting at 0 and going to 1 less than the end number since that's how arrays and stuff works ig
>>
>>61227580
It's funny how in some languages this is actually faster performance-wise
>>
>>61225018
worst programming meme ever
>>
File: 1432489523163.png (74KB, 800x600px) Image search: [Google]
1432489523163.png
74KB, 800x600px
Real code (tm)
>>
>>61224235
Name a language that combines spaces like that so I can avoid it
>>
>>61227769
It's probably a font
>>
>>61224235
That's actually a=b*a;
dumb fuckers hahaha
>>
>>61228008
dude...
first of all a *= b is nicer the point is that "she" could just have used a loop for that

this is bad baiting
>>
File: js.jpg (13KB, 300x169px) Image search: [Google]
js.jpg
13KB, 300x169px
>>61224235
const foo = (a, b) =>
a.toString()
.repeat(b)
.split('')
.reduce((t, x) => t + parseInt(x), 0)


How can brainlets even compete?
>>
>>61228203
H,How did you do that!?
>>
>>61227529
HAHAAHA LMAOIN @ UR LIFE
O(2^n) [n being the amount of digits of b] is not even close to good performance. Check this out:
int i = 0;
int m = 1;
int res = 0;
while(m>0){
if(m&b){
res = res + (a<<i);
}
i++;
m = m<<1;
}
printf("%d\n",res);
>>
File: disgust.jpg (70KB, 1280x720px) Image search: [Google]
disgust.jpg
70KB, 1280x720px
>>61227529
>>61228384
>imperative
>>
IMUL a,b
>>
>>61224235
html isn't programming language
>>
>>61224235
int Product(int a, int b) { return (int)(a / (1 / (double)b)));}
>>
>>61224235
why else if ladders are discouraged?
>>
>>61229162
This is amazing. Why does it work??
>>
>>61228203
>pointless, inefficient type conversions
>brainlet
>>
>>61229259
maths. its the same at multiplication. basic algebra. good answer though
>>
File: js1.jpg (9KB, 248x233px) Image search: [Google]
js1.jpg
9KB, 248x233px
>>61229312
const foo = (a, b) =>
new Array(b)
.fill(a)
.reduce((t, x) => t + x, 0)


Happy now?
>>
File: 1369686329876.jpg (23KB, 256x256px) Image search: [Google]
1369686329876.jpg
23KB, 256x256px
>>61224235
>>61227529
>>61228384

>imperattive sequential brainlets

#include <iostream>
int mult(int a, int b){
return (b == 1) ? a : a+mult(a,b-1);
}
int main(){
std::cout << mult(2,5) << std::endl;
}
>>
Should I feel bad about not understanding half of what's happening here? I've been programming for fun for about a year and am interested in going further. Learning java at school and python on the side.
Anything I should know or any books I should read?
>>
>>61229390
it's better, but now you're pointlessly allocating memory and still using a deadshit faggot language.

why is this guy the only one to just do a simple recursive answer
>>61229392
>>
  #include <iostream.h>
#include <string.h>

class string
{
private:
int size;
char *ptr;

string() : size(0), ptr(new char[1]) { ptr[0] = 0; }

string(const string &s) : size(s.size)
{
ptr = new char[size + 1];
strcpy(ptr, s.ptr);
}

~string()
{
delete [] ptr;
}

friend ostream &operator <<(ostream &, const string &);
string &operator=(const char *);
};

ostream &operator<<(ostream &stream, const string &s)
{
return(stream << s.ptr);
}

string &string::operator=(const char *chrs)
{
if (this != &chrs)
{
delete [] ptr;
size = strlen(chrs);
ptr = new char[size + 1];
strcpy(ptr, chrs);
}
return(*this);
}

int main()
{
string str;

str = "Hello World";
cout << str << endl;

return(0);
}
>>
File: 1497874326104.jpg (44KB, 400x300px) Image search: [Google]
1497874326104.jpg
44KB, 400x300px
>>61229498
>Should I feel bad about not understanding half of what's happening here?
Not really, we're just memeing to the extreme because it's fun to attempt this in retarded but difficult ways.

>Anything I should know or any books I should read?
Make things. Make lots of things. You won't learn much unless you try to make things. Then try to make everything that you make a little better each time you make something.

If you're just listening to a class or following tutorials, you aren't going to learn shit. Start a (small) project!
>>
File: 1491177344943.png (348KB, 493x512px) Image search: [Google]
1491177344943.png
348KB, 493x512px
https://rosettacode.org/wiki/Sorting_algorithms/Sleep_sort
>>
>>61229392
>>61229599
>le recursion meme
>>
>>61229392
>return (b == 1) ? a : a+mult(a,b-1);
>>61229599
>why
This answer hurts my tiny little pea brain. I can't into recursion.
>>
In Julia, assuming unsigned integers with wrapping addition and subtraction:
multiply(x,y) = if (0==y) 0 else
(0 - y&1)&x + multiply(x,y>>1) << 1
end


Using the underflow trick should speed it up since the processor will predict all branches except the last one.
>>
>>61230003
oh my god Julia is so gad damn awful
>>
File: js2.jpg (30KB, 550x309px) Image search: [Google]
js2.jpg
30KB, 550x309px
>>61229599
REEEEEEEEEEEEE
const foo = (a, b, t = 0) =>
b ? foo(a << 1, b >> 1, b & 1 ? t + a : t) : t


GOOD ENOUGH?
>>
>>61229390
>>61229392
>>61229629
>>61230003
>>61228384
>>61228742
>>61228203
>>61227529
>>61227580
How can I make that fancy white textbox?
>>
>>61230050
[ code ]
...
[ /code ]

without whitespaces in [ ]
>>
>>61230066
nigga
[]nigga
[ ]nigga
[][]nigga
nigga
>>
>>61229259
Here is the 3rd grade explanation that you should already know:

1/5, is one fifth.

1 / (1/5), basically saying "how many times does one fifth go into one", which we can easily see is 5 times.

So if we change 1, to 2 then

2 / (1/5) we are saying "how many times does 1/5th go into 2, which is 10".

We can see here that a = 2 and b = 5, and the result is 10.
>>
>>61230003
Or using higher order functions, for 64 bit unsigned, implicitly parallel:
multiply(x,y) = mapreduce(+,0,1:64) do i
(0-(y >> i&1)&x << i
end
>>
>>61230088
Wow you are a wizard. Thanks
>>
>>61229259
https://en.wikipedia.org/wiki/Multiplicative_inversehttps://en.wikipedia.org/wiki/Identity_element
If you can't understand then try khan's academy.

>muh pajeet
You are worse than pajeet
>>
DEFINE true = FALSE
DEFINE false = TRUE
>>
>>61230088
>how many times does one fifth go into one
This should probably say "how many times does one go into one fifth" but I get your point.
>>
>>61230123
Oops, forgot parentheses:
multiply(x,y) = mapreduce(+,0,1:64) do i
(0-(y >> i)&1)&x << i
end


Also, the do block is just sugar for
multiply(x,y) = mapreduce(i->(0-(y >> i)&1)&x << i ,+,0,1:64)


since passing a big lambda as the first argument to the higher order function is such a common pattern.
>>
>>61230144
>https://en.wikipedia.org/wiki/Multiplicative_inversehttps://en.wikipedia.org/wiki/Identity_element


https://en.wikipedia.org/wiki/Multiplicative_inverse
https://en.wikipedia.org/wiki/Identity_element
>>
>>61230166
This is very impressive stuff
>>
>>61230144
>>muh pajeet
>You are worse than pajeet
Programming =/= Mathematics. I've never, ever needed to know this for my work. Only one person posted a solution with division so... that says it all really. Thanks for the help though.
>>
>>61229162
>implying multiplication is not just reverse division
>implying left shift is different from right shift

yea no
>>
>>61230221
How the fresh fuck did you pass elementary shool though?
>>
>>61230144
But floats are not associative. Your answer will be less precise than an actual mul instruction.

Also, it doesn't work for rings that are not fields, like integers.
>>
>>61228761
it is, only declarative and not turing-complete
>>
>>61230279
I didn't. Who needs all the bullshit they teach there in programming?
>>
>>61230449
HTML + CSS is actually turing complete though.
>>
File: B8 17.png (52KB, 625x626px) Image search: [Google]
B8 17.png
52KB, 625x626px
>>61230497
And you were doing so well.
>>
>>61230497
Are you over 12?
>>
>>61230505
>HTML + CSS is actually turing complete though.
proof? You can't calculate anything with html or css.
>>
>>61230548
IIRC, you can make it show a rule 110 automaton, which is turing complete.
>>
>>61230574
...I've never thought about it.
>>
>>61227643
xD
This is more funny than post you replied to
>>
>>61227529
>a+= a;

2a
4a
8a
16a
...
>>
>>61229599
BECAUSE FUCKING RECURSIVITY ISNT """SIMPLE""".
What the fuck. His (>>61229392
) "solution" gives you a stack overflow for any b of big enough size.

Few LOC != Good Program
>>
>>61231435
I also posted a recursive solution and everyone ignored it and it made me sad because it took me some minutes >>61230039 Senpai, please notice me
>>
>>61230039
>>61231570
Yea I was going to answer you already.
I'm (>>61228384) btw.
Even though I hate recursivity I really like your implementation. It took me some time to figure out what you did. Its pretty awesome and if you look at the time it needs it is way better than >>61229392.

General assessment:
>>61228384 (me)
Time needed O(n)
RAM needed O(1)

>>61230039
Time needed O(n)
RAM needed O(n)

>>61229392
Time needed O(n^2)
RAM needed O(n^2)

n being the number of digits of b.
>>
>>61231765
>>>61229392
>Time needed O(n^2)
>RAM needed O(n^2)


Sry fucked up. Meant to say O(2^n). Its the exponential behaviour that makes it so fucking stupid.
>>
File: 1497879284665.jpg (111KB, 810x810px) Image search: [Google]
1497879284665.jpg
111KB, 810x810px
>>61231765
Thanks! Nice to see that someone else also took the bitwise approach. I try to avoid using loops, that's the reason I went with recursion after people didn't like my array based solutions. Though, the array/concatenation thing was a bit of a tongue-in-cheek nod to the solution in OP image.
>>
>>61229629
>private: EVERYTHING
?
>>
>>61231821
>>61231765

>discussing runtime performance for a staged extremely constructed problem

its not about performance. its about solving a problem in a creative and elegant way.
>>
>>61231765

>>61228384 (me)
>Time needed O(n)
???

also i see at least 2 logic errors and 3 compilation errors
>>
>>61230087
coding with klossy
>>
>>61229498
>I've been programming for fun for about a year
dude holy shit, how can you not understand what is basically verbose multiplication

>Anything I should know or any books I should read?

You just opened my eyes, this is why I can't draw... it's because I'm being retarded exactly like this... fuck, I think I can make it now
>>
>>61229634
this originated on /prog/... truly sad how we lost the only place on the internet where only EXPERT PROGRAMMERS would meet
>>
File: 1482613001880.jpg (216KB, 1280x720px) Image search: [Google]
1482613001880.jpg
216KB, 1280x720px
>>61232826
I know. I tried finding an archive of the original thread but I was lazy so I posted that instead.
The HN thread discussing it never fails to make me laugh, though. Especially this post https://news.ycombinator.com/item?id=2657736
>>
>>61232855
>archive
If you find a /prog/ archive, please let me know.
>>
>>61232893
https://archive.tinychan.org/read/prog/1295544154
There you go. I was really lazy but I'm better now.
>>
>>61232912
Looks like I have to fire up wget.
>>
>>61232615
>>Time needed O(n)
>???
?????????

>2 logic errors and 3 compilation errors
Which compiler do you use?
Also this obviously needs to be in a context where a and b is defined.
Also which logic errors?
>>
>>61232615
>>Time needed O(n)
Oh fuck you are right. My program is actually shit, because it moves the bitmask's bit over all 32 bits of an int.
Look at this >>61230039 implementation to see how I should have done it.
>>61232555
>staged extremely constructed problem
>The multiplier in my CPU grew on a tree.
Thread posts: 80
Thread images: 12


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