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

Anyone know the solution to this? Happened to see it while browsing

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: 23
Thread images: 1

File: grils.png (311KB, 652x669px) Image search: [Google]
grils.png
311KB, 652x669px
Anyone know the solution to this? Happened to see it while browsing through an old HDD.
>>
int result = 0;

while(b > 0)
{
result += a;
b--;
}

return result;
>>
int product(int a, int b) {
int res = 0;
while (b--)
res += a;
return res;
}
>>
>>60815603

Yeh this is what I thought of too, I just remember some anon in a previous thread using division in their solution
>>
public int product(int a, int b) {
return Math.multiplyExact(a, b);
}
>>
>>60815671
https://en.wikipedia.org/wiki/Two%27s_complement#Multiplication
>>
>>60815545
public int Product(int a, int b) {
return product(a, b);
}

private int product(int a, int b) {
return a * b;
}
>>
>>60815671
Wouldn't that just be a/(1/b) then?
>>
>>60815743
kek
>>
import Data.Bits

add :: Integer -> Integer -> Integer
add a 0 = a
add a b = add x y
where x = a `xor` b
y = (a .&. b) `shiftL` 1
>>
[Code] for I in range(b):
A=+1 [/code]
Print("A")
>>
>not just using a switch statement
public int Product(int a, int b) {
switch (b) {
case 1:
return a;
case 2:
return a+a;
case 3:
return a+a+a;
case 4:
return a+a+a+a;
case 5:
return a+a+a+a+a;
case 6:
return a+a+a+a+a+a;
case 7:
return a+a+a+a+a+a+a;
case 8:
return a+a+a+a+a+a+a+a;
case 9:
return a+a+a+a+a+a+a+a+a;
case 10:
return a+a+a+a+a+a+a+a+a+a;
default:
throw new IllegalArgumentException("The multiplier is too large.");
}
}
>>
>>60815655
Wait, wouldn't that loop forever or does b-- automagically stop when b reaches zero?
>>
>>60816450
There are no booleans in C. 0 is FALSE, and anything not 0 is TRUE. So,
while(b--)
would decrement b until it was 0.
>>
>>60816479
I mean, they're just as much booleans as C++/Java when you look under the hood. Even in other languages with dedicated bool types, they're still going to be byte aligned, so you still have at least a single byte integer, with some free compile time error checking
>>
>>60815743

Yeh that was it I think, thanks
>>
>>60815545
int mult(int x, int y){
int result = 0;
do{
result += (y & 1)? x : 0;
x <<= 1;
}while((y >>= 1) != 0);
return result;
}
>>
>>60815733
ho shit, had to do this shit all the time in uni
>>
>>60816801
Sorry you went to a shit uni anon.
>>
Looks like a lot of code here isn't handling integer overflow.
>>
>>60816933
>/g/
>good code
Pick only one.
>>
>>60816450
Jesus.
>>
>>60815655
> int b
> b = -1
Thread posts: 23
Thread images: 1


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