[Boards: 3 / a / aco / adv / an / asp / b / biz / c / cgl / ck / cm / co / d / diy / e / fa / fit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mu / n / news / o / out / p / po / pol / qa / r / r9k / s / s4s / sci / soc / sp / t / tg / toy / trash / trv / tv / u / v / vg / vp / vr / w / wg / wsg / wsr / x / y ] [Home]
4chanarchives logo
cringe
Images are sometimes not shown due to bandwidth/network limitations. Refreshing the page usually helps.

You are currently reading a thread in /g/ - Technology

Thread replies: 255
Thread images: 52
File: 1461082929678.png (311 KB, 652x669) Image search: [Google]
1461082929678.png
311 KB, 652x669
Can we get a coding cringe thread?
>>
File: 1464007851900.jpg (100 KB, 600x730) Image search: [Google]
1464007851900.jpg
100 KB, 600x730
>>
File: stupidbitch.png (151 KB, 766x664) Image search: [Google]
stupidbitch.png
151 KB, 766x664
>>
>>54737351
I see nothing wrong with that code.
>>
File: More_Women_In_Tech_Please.jpg (64 KB, 960x578) Image search: [Google]
More_Women_In_Tech_Please.jpg
64 KB, 960x578
>>
>>54737397
>t.pajeet
>>
>>54737397
>>>/out/

While there's nothing wrong with the code itself technically, the logic behind is terrible. Multiplication is just a series of additions.
>>
File: sc.jpg (226 KB, 869x1776) Image search: [Google]
sc.jpg
226 KB, 869x1776
>>54737397
I hope you're not serious
>>
>>54737406
That hurts to look at
>>
>>54737429
>>>/out/
>>
>>>/r9k/
>>
>>54737433
post more.
people being stupid gives me a raging boner.
>>
>>54737433
>comparing inverse square root to fucking max
I quit. The world is fucked and there is no way to unfuck it.
>>
File: whatrace.jpg (15 KB, 453x557) Image search: [Google]
whatrace.jpg
15 KB, 453x557
>>54737433
>shalom ayash
>>
>>54737433
>if(a > b && b < a)
literally triggered.
>>
>>54737374
WE
>>
>>54737466
>>54737479
Newfriends out
>>
>>54737494
WUZ
>>
>>54737433
Her code is advanced and well-documented. Code on the left is made by obviously incompetent person or so-called 'code monkey', who just write code, but doesn't understand what the code does.
>>
>>54737498
why?
>>
>>54737498
>a tweet from a month ago
>calling someone new when they get flustered
explain yourself, you nigger.
>>
>>54737433
What I find especially infuriating is that she removed the comments from the Quake code to make it more confusing.
>>
>>54737519
>her code is advanced

Thanks for more /g/ humor, friend!
>>
File: UWHgwot.jpg (267 KB, 1600x900) Image search: [Google]
UWHgwot.jpg
267 KB, 1600x900
>>
>>54737499
KANGZ
>>
>>54737543
I'm curious what he had almost finished with his minecraft PowerPoint.
>>
>>54737543
lost
>>
https://www.youtube.com/watch?v=SXmv8quf_xM
>>
>>54737560
Probably nothing. But if it was something, I am dying to see it
>>
File: devnull.jpg (181 KB, 778x1018) Image search: [Google]
devnull.jpg
181 KB, 778x1018
>>54737374
>>
>>54737573
Is it going to freeze my compute if do this now? It's obvious that the video was made many years ago that's why it is only so few people on google page, but now I think there should be more of them.
>>
>>54737397
Return a / (1 / b)
>>
>>54737709
Wouldn't work. These are integers.

You would use a for loop with repeated addition.
>>
File: kvpaw.gif (1 MB, 288x288) Image search: [Google]
kvpaw.gif
1 MB, 288x288
>>54737702
>>
>>54737522
>february was one month ago
So on top of being new you're retarded?
>>
>>54737742
>keeping up with the date
And that's how I know you're just a summerfag.
>>
>>54737351
>I can't code so I construct strawmen to laugh at to make myself feel better
>>
>>54737429
>While there's nothing wrong with the code itself technically
Well I guess “technically” you are a retard, then.
>>
>>54737406
W O M E N I N T E C H
>>
>>54737754
You're not even trying anymore.
>>
>>54737820
>implying you were
>>
>>54737433

Both code examples are shit.

The code on the right has too many comments and unnecessary parts, but it's totally valid.

The code on the left has no comments (which is a big nono) and also I hate it when people name their variables x,y,z,i,j,k...
If you just call it "diameter, x_axis, length" you can immediately understand what it's all about.

As for the girls comments, they are obviously baiting, shame on you guys for getting triggered so easily.
>>
>>54737397
>this weakass bait worked
>>
>>54737840
>but it's totally valid.
>>
>>54737840
>getting triggered
I like you :)
>>
>>54737840
>Both code examples are shit.
>fast inverse square root is shit
I know this is bait, but it still makes me mad.

>The code on the left has no comments
The comments were removed. There were comments in the original.

>and also I hate it when people name their variables x,y,z,i,j,k...
That's your problem. There is nothing wrong with the variable names. The variables there do not have intuitive interpretations. It's all mathematics and bit-twiddling.
>>
>>54737840
The code on the left had comments originally, the poster just removed them before posting
>>
>>54737833
Of course I was you dipshit, I've seen this fucking tweet posted here at least twice a day every single day, how come have you not seen it yet in 3+ months? Oh wait I know why, that's because you're digustingly new.
>>
>>54737560
formatted the cells to look like Steve
>>
>>54737433
>>54737459
>>54737466
>>54737479
>>54737519
>>54737530

you guys are aware this is fake right ?
>>
>>54737853
/g/ is one of the easier boards to troll. Not as easy as /v/ or /pol/, but still pretty easy.
>>
c = c + a
while b > 0

#TODO finish formatting loop
>>
>>54737433
Complete beginner here, what does the code on the left do and are those * and & pointers?
>>
>>54737911
I've seen it posted too. Doesn't make me any less angry every time I fucking see it you nigger. Or maybe it didn't occur to you that I don't browse the same nigger threads as you, faggot. Oh but wait, you're just a newfag, generalizing about how other people spend their time. Fuck off with your retardation you loose asshole'd nigger.
>>
>>54737911
>twice a day every day

hello 911
>>
File: 1438909485418.png (4 KB, 494x41) Image search: [Google]
1438909485418.png
4 KB, 494x41
>>54737351
>>
>>54737969
https://en.wikipedia.org/wiki/Fast_inverse_square_root#Overview_of_the_code
>>
>>54737969
https://en.wikipedia.org/wiki/Fast_inverse_square_root#Overview_of_the_code
>>
>>54738005
Col. Kek McKekkington
>>
>>54737786
The code will work fine, it's just a terrible way to implement it.
>>
>>54737374
GUYANA'S GOLDEN JUBILEE

GUYANA REPRESENTTTTT
>>
>>54737890
>There were comments in the original.
Maybe because of the "// what the fuck?"
>>
>>54737953
missed
b = b - 1
>>
>>54738071
>The code will work fine,
Product(20,20)
>>
>>54738071
b = 11

error : fuck that, above my pay grade
>>
>>54737969
int x = 5;
int *x_ptr = &x; // a pointer points to an address in memory, &x = "address of x"

*x_ptr = 10; // dereferencing a pointer, equivalent to x = 10
>>
>>54738071
>If the code produces the right answer, it's technically fine
cannot fabricate this excrement, famiglia
>>
>>54738113
exception argument would catch that
>>
>>54738071
never program in your life please.
>>
>>54737374
>tfw "built" a computer at that age too
>tfw i wasn't in the newspaper
the fuck, is it because spics are pretty much considered white?
>>
>>54738209
>>54738197
The code is fine, you guys are just sexist.
>>
>>54737351
Okay.
I get it if you want to do it this way, at least if you want work with your own data types where multiplication is not defined.
But.
But why,
The hell wouldnt you use a fucking recursion to do it?
Even a monkey would see that there is a obvious pattern to it and even a easy simple recursion or a while/for statement would do the job.

Seriously why is it the case that once someone touches a keyboard his brainactivity goes straight to 0?
>>
File: 2001aso1.png (938 KB, 1920x864) Image search: [Google]
2001aso1.png
938 KB, 1920x864
>>54737406
>>
>>54738227
He's testing signals, not soldering.
>>
>>54738226
>Seriously why is it the case that once someone touches a keyboard his brainactivity goes straight to 0?
Not true, normal programmers have no problems with this.
>>
>>54737387
1st Is this real?
2nd That can only be c++ right? Don't konw any other language with that kind of syntax. Which would mean it's plain wrong
>>
>>54738226
>>54738271
It's only women that suffer from this problem
>>
>>54737433
p sure this was shopped no?
>>
>>54737953
def multiply(a, b):
i = 0
c = 0
while i < b:
c = c + a
i+=1
print(c)
>>
>>54738301
Slow and doesn't work
>>
int product(int a, int b) {
if(b == 0) { return 0; }
if(b == 1) { return a; }
return a + product(a, b - 1);
}
>>
>>54737543
I'm now wondering about this.
Would it be a 10,000 slide slideshow of a dude cutting down a tree?
If so, topkek.
>>
>>54738328
Slow and doesn't work
>>
>>54738301
>multiply routine prints the result instead of returning it
>requires O(b) instead of O(log b) additions
0/10
>>
>>54737374
I "built" a computer at 11 by saving lunch money and doing chores and shit, I even bought a second hand CRT so I had more money for the PC.
And in those days computers weren't exactly like LEGO.
>>
>>54738290
Nah i have also seen it several times in university.
Yeah, there are still luckily people with common sense but the amount of people without any common sense is supprisingly high.
>>
>>54738328
Redundant b==1 case

>>54738301
>>54738328
Doesn't work for negative integers
>>
>>54738301#
>unnecessary variables
>printing
average python """programmer""" ladies and gentoomen
>>
>>54738328
why two base cases?
>>
>>54737499
WHIZKIDZ AN SHIET
>>
>>54738226
>his
>>
>>54738365
What's wrong with printing?
>>
>>54738413
It doesn't compose. You can't use this method in another method that requires multiplying things.
>>
>>54738301
>>54738328
multiply :: (Ord a, Integral a) => a -> a -> a
multiply a b
| b < 0 = - multiply a (-b)
| b == 0 = 0
| odd b = a + r + r
| even b = r + r
where r = multiply a (b `quot` 2)

-- Testing
propMul a b = a * b == multiply a b


λ import Test.QuickCheck
λ quickCheck propMul
+++ OK, passed 100 tests.
>>
lambda a,b: eval('+'.join([str(a) for x in range(b)]))
>>
>>54738350

I built my first computer when I was 9 and it was a 486.
>>
>>54738359
>doesnt work with negative integers

>>54738365
>just started programming
>mad that im a beginner
have to start somewhere clown
>>
>>54738453
>mac
Why am I not surprised.
>>
>>54738428
>Constructing a string at runtime, parsing and JIT compiling this
Jesus fucking christ, hats off for finding the worst possible fucking “solution”.

Also still doesn't work for negative b :^)

>>54738453
>doesnt work with negative integers
Now try multiply(2, -9)
>>
>>
>>54737543
>win10
>chrome
>skype
cringed
>>
>>54738426
QuickCheck can't write your tests for you, friend.

multiply 1 minBound :: Int
>>
>>54738466
you got me there friend, working on it.

>>54738460
>implying i only have one computer
>>
>>54738359
>>54738344
oproduct :: Integer -> Integer -> Integer ->Integer
oproduct _ 0 _ = 0
oproduct a b result | b < 0 = error "Thats not how it works"
| b == 1 = a + result
| otherwise = oproduct(a,(b-1),(result+a))

product :: Integer -> Integer -> Integer
product = oproduct(a,b, 0)
>>
>>54738365
>assembly master race
>>
>>54738522
compare i to absolute of b
>>
>>54738519
λ multiply 1 minBound == (1 * minBound :: Int)
True
>>
>>54738283
Actually, that shit is valid code. Not correct, but valid
>>
>>54737543
Why not just implement the JVM using Visual Basic bindings in powerpoint?
>>
>>54738548
It would always output “Block.” and then exit.
>>
>>54738490
Where did you see Win10? I only see Win7 here.
>>
>>54737429
it literally says do not multiply on the fucking top
>>
>>54738548
I know it would compile it just dosn't make any sense
>>
>>54737433
>this is the end of the program! see you guys later XD
cringe
>>
>>54738328
>>54738453
>>54738522

int product(int a, int b) { 
if(b == 0) { return 0; }
if(b == 1) { return a; }
if(b > 1) { return a + product(a, b - 1); }
if(b < 0) { return a + product(a, b + 1); }
}
>>
File: codez.png (76 KB, 426x598) Image search: [Google]
codez.png
76 KB, 426x598
never5get
>>
>>54737406
Explanation?
>>
>>54738729
product(5,-1) returns 5 for your code
>>
>>54737433
>^_^
>;D
>:D
>XD
If wish i could choke that bitch
>>
>>54737351
The best way to do this would be to just use a for loop, right?
>>
>>54738485
hackerman could hack that back in time & get the data
>>
>>54737953
>>54738301
>>54738328
>>54738426
>>54738428

Only right way to do it:

     sum := 0;
while y > 0 do begin
if ((y and 1) <> 0) then sum := sum + x;
x := x shl 1;
y := y shr 1;
end;
>>
>>54738789
yeah it also doesn't handle double negatives, dang it
>>
>>54738818
Loop or recursion depending on how you feel today
>>
>>54738570
it wouldn't output shit, senpai
>>
>>54738784
i'm gonna turn on the stove and you can learn first hand
>>
>have ocd
>go to one of those online-courses to learn basics of html, css and javascript
>every task involves something like: create a list of things, change titles to your own ones, tell about yourself with the code etc etc
>stuck with basic things for hours literally looking for good ideas for list entries
Why it has to be so over-complicated? I feel like the women are standing behind stupid tasks like when you need to make a list with favorite boys and girls names, or favorite celebrities. Why is this even allowed? Jesus.
>>
>>54738839
Doesn't work
>>
>>54738944
Seems more like genuine OCD. There's a perfect list already: natural numbers.
>>
>>54738839
Doesn't work. See >>54738426, that one works.
>>
>>54738974
I cannot put numbers as entries of ordered list named "Things I like:".
>>
>>54738978
Works for 4x as many values, but still not correct >>54738519
>>
>>54738999
Food, sleeping, the internet, video games, anime, sports, working out, talking with friends, texting friends, hanging out with friends, making new friends

Have you started the codecademy courses where you need to list city and state names yet? I'll start naming cities if you'll let me
>>
File: brianna.png (8 KB, 788x501) Image search: [Google]
brianna.png
8 KB, 788x501
>>54738570
>>54738911
You're both wrong. What it outputs or not depends on the value of ‘Gamergate’ and/or ‘Negative’.

If Gamergater is non-zero, it outputs "Block."
Otherwise, if Negative is non-zero, it outputs "Block"
Otherwise, it outputs nothing
>>
>>54739014
>>54738542
Works for me (tm)
>>
>>54739033
Not yet, I'm creating 'social networking profile' atm.
>>
>>54739039

Bool Operation with only one =
Nice try.
>>
>>54739065
>Bool Operation
What are you going on about?

My code is as close to an exact transliteration of >>54737387 as I could manage.
>>
File: IsMyLifeALie.png (1 KB, 132x78) Image search: [Google]
IsMyLifeALie.png
1 KB, 132x78
>>54739039
what c++ is that?
>>
>>54737351
public int Product(int a, int b) {
int sum = 0;
if (b < 0) {
a = -a;
b = -b;
}
for (int i = 0; i < b; i++)
sum += a;
}


Code-style aside, is there some something better? Took me about 5 mins. 4 min to realize and figure out the -b case.
>>
File: 1461630593102.png (63 KB, 400x250) Image search: [Google]
1461630593102.png
63 KB, 400x250
>>54739058
You can do this mate, but in case you get stuck again,
>Countries
United States, Canada, Mexico, Panama, Haiti, Jamaica, Peru
>States
Alabama, Alaska, Arizona, Arkansas, California, Colorado, Connecticut
>Cities
New York City, Los Angeles, Portland, Chicago, Denver, Cleveland, Miami, Tampa, Boston
>>
>>54737433
It's obviously shopped.

Also in 2016, that fast inverse square root is no longer optimal and anyone who uses it is obviously a retard who thinks it makes them some kind of elite hacker.
>>
>>54739082
λ g++ --version
g++ (Gentoo Hardened 5.3.0 p1.1, pie-0.6.5) 5.3.0
Copyright (C) 2015 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
>>
>>54739050
Are you not using a two's complement arch?

*Main> (minBound) :: Int
-9223372036854775808
*Main> (-minBound) :: Int
-9223372036854775808


It goes into an infinite loop on
b <  0 = - multiply a (-b)
>>
>>54739090
>Code-style aside, is there some something better? Took me about 5 mins. 4 min to realize and figure out the -b case.
You can turn your O(b) algorithm into an O(log b) algorithm using repeated doubling.
>>
>>54738784
She's holding the hot part. Like, melt through plastic like butter hot.
>>
>>54739065
Yeah really that was the first thing I noticed

It's legal compilable C because (Foo = 1) returns 1, which is true. It's a kinda common backdoor desu

If(someAuthetication = true)

Will always return true even if someAuthentication is false (assuming typedefs for true/false) since someAuthetication is being ASSIGNED true

How do I do code tags?
>>
>>54738951
>>54738978

What are the requirements?
>>
>>54737351
EASY.
function product(a, b) {
var xmlHttp = new XMLHttpRequest();
xmlHttp.open( "GET", 'http://api.wolframalpha.com/v2/query?appid=xxx&input=' + 'multiply' + a + 'by' + b, false ); //wolframalpha doesnt need spaces
xmlHttp.send( null );
return xmlHttp.responseText;
}
>>
>>54739161
That the code multiplies two integers.

You can't just limit yourself to numbers <= 10 like in OP's pic, or to positive numbers like in your code.
>>
>>54739090
$ cat Lol.java
class Lol {
public int Product(int a, int b) {
int sum = 0;
if (b < 0) {
a = -a;
b = -b;
}
for (int i = 0; i < b; i++)
sum += a;

return sum;
}
public static void main(String[] args) {
System.out.println(new Lol().Product(1, -2147483648));
}
}

$ java Lol
0


Expected: -2147483648
>>
>>54739178

Gotcha, gimme a minute.
>>
>>54738999
You don't like numbers?
>>
>>54739103
Oh oops, I was testing a changed version of the algorithm. You're right, the one I pasted goes into an infinite loop. Revised and added a test case.

This one is also more efficient by an inconsequential degree (skips redundant checks per iteration).

multiply :: (Ord a, Integral a) => a -> a -> a
multiply a b | b < 0 = - go (-b)
| otherwise = go b
where go 0 = 0
go b | odd b = a + r + r
| otherwise = r + r
where r = go (b `quot` 2)

-- Testing
propMul a b = a * b == multiply a b
propBound a = propMul a (minBound :: Int) && propMul a (maxBound :: Int)


λ import Test.QuickCheck
λ quickCheck propMul
+++ OK, passed 100 tests.
λ quickCheck propBound
+++ OK, passed 100 tests.
>>
>>54739161
>What are the requirements?
Produce the exact same result as * on every input
>>
>>54739111
Thanks. This one was harder.
public int Product(int a, int b) {
int sum = 0;
while (b > 0) {
if ((b & 1) == 1)
sum += a;
a <<= 1;
b >>= 1;
}
return sum;
}
>>
>multiplying numbers by adding in a loop when there is a just as short but only O(log(n)) solution
Are you dumb or just uneducated?
>>
>>54739243
-1 * -1 = 0

wtf is your release procedure
>>
>>54739243
Oh shit. Forgot negative ints...
>>
>>54739090
compare the execution of
Product(1,984639685) and Product(923862658, 1)
>>
def product(x, y)
x = x.to_i
y = y.to_i
z = 0

y.times do
z = z + x
end

return z
end

puts "This silly little program will multiply two numbers for you!"

puts "What is the first number?"
numone = gets.chomp

puts "What is the second number?"
numtwo = gets.chomp

puts "The result is #{product(numone, numtwo)}"
>>
>>54739222
>>54739178
>>54739200

Fixed:

     sum := 0;
if y < 0 then begin
y := -y;
x := -x;
end;
while y > 0 do begin
if ((y and 1) <> 0) then sum := sum + x;
x := x shl 1;
y := y shr 1;
end;
>>
>>54739169
at least this one always works
>>
File: 1419596337648.jpg (7 KB, 225x225) Image search: [Google]
1419596337648.jpg
7 KB, 225x225
>>54739169
You're hired
>>
npm install multiply


Boom done!
>>
>>54739291
See >>54739198 >>54739103 >>54738519 and try it with your type's smallest value
>>
File: 3u32uiu3.jpg (12 KB, 240x222) Image search: [Google]
3u32uiu3.jpg
12 KB, 240x222
>>54738670
hence you multiply in a loop you fucking retard
>>
File: 1314446463220.jpg (32 KB, 634x350) Image search: [Google]
1314446463220.jpg
32 KB, 634x350
>>54738466
lambda a,b: eval('+'.join(max((b, [str(a) for x in range(abs(b),abs(b)+abs(b))]), (0, [str(-a) for x in range(abs(b),abs(b)+abs(b))]))[1])+'-0')


There you go senpai
>>
>>54739316

I get 0. But you didn't mention that in the requirements.
>>
>>54737429
>While there's nothing wrong with the code itself technically,
hahaha

this produces horribly inefficient code when compiled
>>
>>54739065
>>54739082
newfags
>>
>>54739346

What's with all the one-liner autism ITT?
>>
>>54737351
>without using the operator *
multiply a b = truncate $ a / (1 % b)


smugpepe.png
>>
>>54739198
>>54739259
>>54739280
Shit. Can't really figure out how to handle negative ints in a elegant way without branching based on sign of one number.
>>54739243
>>
Hey again, >>54738328 here,
revised the code a bit:
int product (int a, int b) {
if (b == 0 || a == 0) { return 0; }
if (b < 0) { return b + product (a - 1, b); }
return a + product (a, b - 1);
}


I'm trying to figure out the case when both a and b are negative, without any sort of multiplication, including negation
>>
>>54739369
It's a cringe thread, and unmaintainable cryptic one-liners are cringeworthy.
>>
>>54739355
The code was supposed to multiply integers, to produce the same output as * and to work without restricting input.

This is Pajeet tier "vell sir u didnt give list of all integers" excuses. Surely you're better than that
>>
File: masterdebian-f7a6142c0f156696.png (1 MB, 1242x698) Image search: [Google]
masterdebian-f7a6142c0f156696.png
1 MB, 1242x698
>>54737351
It's not code but damn does it make me cringe.
>>
>>54739400
Maybe like this?
int product (int a, int b) {
if (b == 0 || a == 0) { return 0; }
if (b < 0) {
if (a > 0) return b + product (a - 1, b);
return b + product (a + 1, b);
}
return a + product (a, b - 1);
}
>>
>>54739425

It does produce the same output as *. I tested it.

You're complaining it doesn't work with the smallest value my type can take, but neither does *. Both produce 0. Try it yourself.
>>
>>54739455
Still not quite there yet, -5, -5 returns -25
>>
>>54739476
Make sure the other number isn't 0.

I don't have a Pascal compiler, but C, Java and Haskell agree that 1 * minValue == minValue.
>>
link lm and there you go
int multiply(int a, int b) {
return exp(log(a)+log(b));
}
>>
>>54739516

Wasn't trying with 1, was trying with 2. Sheeeit gotta fix that.
>>
>>54739454

Then you'll love this: http://terriblelinuxwallpaper.tumblr.com/
>>
a * b

What the fuck are you all even posting about?
>>
File: wtf.png (77 KB, 200x237) Image search: [Google]
wtf.png
77 KB, 200x237
>>54739516
>I don't have a Pascal compiler
>but I have Java and Haskell
>>
int product(int a,int b){int i,sum=0;if(a > 0 && b > 0){for(i=b;i>0;i--){sum+=a;}return sum;}if(a > 0 && b < 0){for(i=b;i<0;i++){sum+=a;}return -sum;}if(a<0 && b > 0){for(i=a;i<0;i++){sum+=b;}return -sum;}if(a < 0 && b < 0){for(i=a;i<0;i++){    sum+=b;}return -sum;}if(a == 0 || b == 0) return 0;}
>>
return x / (1 / y);[/return]
>>
>>54738839
I only know Powershell, but here's mine.
$p = 0
for ($i=0;$i -lt $args[1];$i++){
$p+=$args[0]
}
Write-Host $p
>>
>>54739595
>[/return]
topkek anon you should get some sleep
>>
>>54739595
damn I fucked that up
>>
>>54737351
>massive if structure checking constants
>not a switch
>not knowing how to use a for loop
how did this happen
>>
>>54737351
public int Product(int a, int b) {
int result = (int)Math.Pow((double)a,(double)b);
return result;
}
>>
>>54739537
This fails just as hard as most shit here
>>
def product(a, b)
# Checking the smaller one so as to iterate fewer times
arr = a.abs < b.abs ? [a, b] : [b, a]
# if the smaller one is negative then flip sign on both numbers
arr.map! { |x| 0 - x } if (arr[0] < 0)
ans = 0
while arr[0] > 0
ans += arr[1]
arr[0] - 1
end
end
>>
>>54737351
VBA up in this bitch

a = Cells(1, 1).Value
b = Cells(2, 1).Value
i = 0
j = 0
For i = 0 To Abs(b) - 1
If b > 0 Then j = j + a Else j = j - a
Next
MsgBox(j)
>>
>>54739387
{-# LANGUAGE TemplateHaskell #-}

import Harpy.CodeGenMonad
import Harpy.X86Assembler
import Foreign
import Control.Monad.Trans
import System.IO.Unsafe

mulAsm :: CodeGen e s ()
mulAsm = do ensureBufferSize 32
mov eax edi
imul InPlace eax esi
ret

callDecl "callMulAsm" [t|Int32 -> Int32 -> IO Int32|]

multiply :: Int32 -> Int32 -> Int32
multiply x y = unsafePerformIO $ do
(_, Right res) <- runCodeGen (mulAsm >> callMulAsm x y) () ()
return res


Maximum smugness
>>
>>54738197
It's pajeet trying to defend his own coding style
>>
>>54739572
>I can't read
>>
>>54737351
> implying girls know that a product is a string of addition
>>
>>54739657
ok, then.
Here you have the negative-proof version.
int multiply(int a, int b) {

if(a > 0 > b || b > 0 > a) {
return -exp(log(abs(a))+log(abs(b)));
}else{
return exp(log(abs(a))+log(abs(b)));
}
}
>>
Wouldn't dividing by the reciprocal of the second factor and returning 0 if its zero be the ideal solution for this?

Anyway, in the same vein as this, would raising a number to 1/2 using a programming language sensibly produce the square root of it without using any library functions?
>>
>>54739400 here again,
int product(int a, int b) {
if (b == 0 || a == 0) { return 0; }
if (a < 0 && b < 0) {
return -a + product (-a, -b - 1);
}
if (b < 0) { return b + product (a - 1, b); }
return a + product (a, b - 1);
}

I'm ashamed that I must use a negation operator in this function, because it is still, technically, multiplication. I tried to keep this function as pure as possible using only addition and subtraction
>>
>>54737387
That filename made me kek
>>
File: JPEG_20160525_204038.jpg (166 KB, 818x635) Image search: [Google]
JPEG_20160525_204038.jpg
166 KB, 818x635
>>
>>54739803
Only time that's ever “ideal” is if you care more about your code being short than you care about your code being correct or efficien
>>
File: 1463845790651.jpg (15 KB, 200x225) Image search: [Google]
1463845790651.jpg
15 KB, 200x225
>>54738078
Calm down, kid. You're making us look bad...
>>
>>54739803
you could also send a http get request to google for the string a & " times " b
>>
>>54739818
>negation is technically multiplication
negation is just bit inversion + addition
>>
>>54737374
This is fake. Get that reddit tier shit out of here.
>>
File: FROM_SCRATCH.jpg (91 KB, 882x587) Image search: [Google]
FROM_SCRATCH.jpg
91 KB, 882x587
>>54739852
Search it up nigger
>>
>>54737406
Looks like she's soldering some CPUs.
>>
>>54738835
nice kungfury reference anon
>>
>>54739873
CRINGE
>>
>>54738466
>using the smiley with a carat nose
>>
File: 1456622640774-pol.jpg (5 KB, 250x231) Image search: [Google]
1456622640774-pol.jpg
5 KB, 250x231
>>54737921
>Powerpoint
>talks about Excel
>>
You guys are doing it wrong.

long multiply(int a, int b) {
return a*b;
}
>>
>>54739387
Should be

multiply :: Integral a => a -> a -> a
multiply a b = truncate $ (a % 1) / (1 % b)
>>
>>54739209
>>54739727
> without using the * operator

multiply x y = product [x,y]
>>
>>54740063
>>54740087
Stronger condition: With no use of * in your function or any of the functions you call in it
>>
(defun multiply (x y) (/ x (/ 1 y)))
>>
>>54737351
Fight me:
#include <stdio.h>

int ass(int a) {
if (a >= 0) {
return a;
}
else {
return a + (-a) + (-a);
}
}

int product(int a, int b) {

int res = 0;
int aa = ass(a);
int bb = ass(b);

for (int i=0; i<bb; i++) {
res += aa;
}

if ((a < 0) && (b < 0))
return res;
if ((a < 0) || (b < 0))
return -res;
return res;
}

int main() {
printf("%d\n",product(0,0));
printf("%d\n",product(0,5));
printf("%d\n",product(5,0));
printf("%d\n",product(5,5));
printf("%d\n",product(-5,5));
printf("%d\n",product(5,-5));
printf("%d\n",product(-5,-5));
return 0;
}
>>
>>54740137
>return a + (-a) + (-a);
-a
>>
>>54739727
Love it.
>>
>>54739599
This must be a meme. Only know powershell?
>>
File: community.jpg (79 KB, 1280x720) Image search: [Google]
community.jpg
79 KB, 1280x720
lambda a,b: a.__mul__(b)
>>
sudo apt-get update && sudo apt-get install qalc
qalc 2*2 && screenfetch
>>
>>54740137
Include limits.h and try the product of INT_MAX * INT_MAX
>>
>>54740226
>zsh: no matches found: 2*2
>>
>>54740237
Did you try to turn off and on again?
>>
>>54738328
no need for b== cases
def product(a,b):
n=False
c=0
if b<0:
b /= -1
n=True
for i in xrange(0,a):
c+=b
if not n:
return c
else:
return c/-1
>>
>>54740146
It works. Try it for yourself.
>>
>>54740237
>what are
""
>>
>>54740231
It broke
$ time ./test 
1

real 0m4.117s
user 0m4.114s
sys 0m0.000s
>>
>>54739826
How is it not correct or efficient? Dividing by the reciprocal of the second factor is proven to be the same as multiplication except for the case of the second factor being zero, which is averted if you return zero as per the zero property of multiplication.

It will roughly compile down to the same optimized assembly code anyway. Why do more work and waste the benefits of having a compiler?
>>
>>54737374
>SLKJSLKJSJLKJ

What?
>>
>>54737479
JavaScript compatibility
>>
>>54737938
this
>>
>>54738426
import Test.QuickCheck
let mult a b = sum $ replicate a b
let propMul a b = a * b == mult a b
quickCheck propMul
*** Failed! Falsifiable (after 4 tests and 3 shrinks):
-1
1

Next try:
import Test.QuickCheck
let mult a b | a < 0 = - mult (-a) b | a == 0 = 0 | otherwise = sum $ replicate a b
let propMul a b = a * b == mult a b
quickCheck propMul
+++ OK, passed 100 tests.

Sum isn't cheating, right?
>>
>>54737374
The only cringe thing about this is that people think it's news. It's actually pretty cool that the kid is interested in this shit.
>>
>>54737351
Is it wrong that i use that exact same color scheme?
>>
>>54740471
Oh, + is allowed, folding should work too.
>>
File: image.jpg (43 KB, 640x453) Image search: [Google]
image.jpg
43 KB, 640x453
>>54737734
>repeated addition
Gee, if only there was some kind of basic mathematical operation that did this.
>>
>>54737734
what? it would always work, scum
>>
(defun multiply (x y)
(cond
((or (< x 0) (< y 0)) (- 0 (multiply (abs x) (abs y))))
((or (zerop x) (zerop y)) 0)
(t (+ x (multiply x (- y 1))))))
>>
>>54738485

I couldn't find any data on floppy drive coercivity online. But I expect it to not be so ridiculously low that it's affected by a very weak fridge magnet.
>>
>>54740522
The goal of the original argument was to make a program that didn't use the multiplication operator
>>
File: nico nico.png (668 KB, 599x763) Image search: [Google]
nico nico.png
668 KB, 599x763
>>54737351
int product(int a, int b)
{
int product = 0;
while (b--)
product += a;
return product;
}
>>
Are you a man If you cant code AND cant do a pull up ?
>>
>people itt unironically trying to beat master-class program from the first post and hardly trying to prove themselves that they are better than some random female
(YOU) are bad if (YOU) need to constantly prove opposite.
>>
>>54738782
kek
>>
>>54740656
I can probably do one.
>>
>>54739081
boolean
true/false logic
for checking if something is true or false in C++ you use == instead of =
>>
>>54740383
Tell that to >>54740226
>>
>>54740408
Because it requires integer <-> floating conversion to work properly, which also incurs rounding errors.
Thread replies: 255
Thread images: 52

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

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.
If a post contains personal/copyrighted/illegal content you can contact me at [email protected] with that post and thread number and it will be removed as soon as possible.
DMCA Content Takedown via dmca.com
All images are hosted on imgur.com, send takedown notices to them.
This is a 4chan archive - all of the content originated from them. If you need IP information for a Poster - you need to contact them. This website shows only archived content.