# Computation Contest #9 [2 SBI]

in #programming2 years ago

Here you can solve interesting problems using whatever programming language you like. Also you will earn SBI and sometimes STEM by doing so.
Also you might learn new things by doing so.
The tasks will be rather hard to solve without a programmable computer and some programming skills, but if you want to add a few million numbers by hand or similar, I would still give you the reward.
↓↑↓↑↓↑↓↑↓↑↓↑↓↑↓↑↓↑↓↑↓↑↓↑↓↑↓↑↓↑↓↑↓↑↓↑↓↑↓↑↓↑↓↑↓↑↓↑↓

# Rules

#### In order to get accepted you need to somehow attach your code.

↓↑↓↑↓↑↓↑↓↑↓↑↓↑↓↑↓↑↓↑↓↑↓↑↓↑↓↑↓↑↓↑↓↑↓↑↓↑↓↑↓↑↓↑↓↑↓↑↓

# Problem

Imagine you have to write a program for a computer which is not able to multiply numbers and can only do addition, subtraction, comparison and bitwise operations. So you must write your own function to multiply integers.
Imagie further that this program needs to multiply numbers (that can get pretty big) very often, so that processing speed is crucial and the intuitive algorithm of simple repeated addition is not applicable.

Your task now is to write that function which multiplies two integers without using the "*" operator.

↓↑↓↑↓↑↓↑↓↑↓↑↓↑↓↑↓↑↓↑↓↑↓↑↓↑↓↑↓↑↓↑↓↑↓↑↓↑↓↑↓↑↓↑↓↑↓↑↓

To everyone who already participated in a past contest, come back today and try a new problem(tell me if you don't want to be tagged):
@crokkon @kaeserotor @lallo @ninahaskin @portalmine @tonimontana

In case no one gets a result(which I doubt), I will give away the prize to the person who makes the most constructive description why the problem is too hard in your opinion.

↓↑↓↑↓↑↓↑↓↑↓↑↓↑↓↑↓↑↓↑↓↑↓↑↓↑↓↑↓↑↓↑↓↑↓↑↓↑↓↑↓↑↓↑↓↑↓↑↓

@contrabourdon sponsors my contests with 2 STEEM weekly.
You can support him by using a witness vote on untersatz, so he can further support this and other contests.

Sort:

I'll share with you a solution that I found in an old exam:
https://github.com/gravlaks/multiplication-recursive/blob/master/multiplication.py

It's a neat recursive solution, but sadly doesn't solve your problem as big numbers lead to "maximum recursion depth error" and computation is slow.

2 years ago (edited)

What you did is just implementing "the intuitive algorithm of simple repeated addition" which I mentioned in the problem which is as you correctly discovered very slow because you need b calls to func1(you could have written there just a+b instead of func1(a,b). Addition is allowed).

You might also want to think about what happens when you use negative numbers.

2 years ago (edited)

https://github.com/billyb2/quantum-developer-contests/blob/master/comp-contest-%239.html
Saves as much computation power as possible by limiting the amount of operations.

Also works for negative multiplication.

Unfortuantely, it's slows down for much larger numbers, and is in general slower since it runs in the browser. It tries to improve efficiency as well as possible, however, by having adding the larger number to itself instead of just picking the first number.

What you did is just implementing "the intuitive algorithm of simple repeated addition" which I mentioned in the problem which is as you correctly discovered very slow because you need `number2` additions.
You need to find something better.

By the way I ignore the speed differences of individual languages in these contests, because the algorithm would still be slow in any other language.

Thanks for the information, I'll work on redoing my answer now!

A member bonus \$trendotoken tip, and !trendovoter, for @quantumdeveloper from MAPXV! These bonuses are for members, selected at random, and last for a few days.

Also consider our MAPR fund and MAXUV vote bonds too.
MAP Steem Fintech: growing your STEEM without SP.

Congratulations @mapxv, you successfuly trended the post shared by @quantumdeveloper!
@quantumdeveloper will receive 4.72741312 TRDO & @mapxv will get 3.15160875 TRDO curation in 3 Days from Post Created Date!

## "Call TRDO, Your Comment Worth Something!"

To view or trade TRDO go to steem-engine.com
Join TRDO Discord Channel or Join TRDO Web Site

Congratulations @mapxv, 50.28% upvote has been shared with your successful call on the post that shared by @quantumdeveloper!

Support @trendotoken projects by delegating : 100SP , 200SP , 500SP , 1000SP , 2000SP

Congratulations @quantumdeveloper, your post successfully recieved 4.72741312 TRDO from below listed TRENDO callers:

@mapxv earned : 3.15160875 TRDO curation

To view or trade TRDO go to steem-engine.com
Join TRDO Discord Channel or Join TRDO Web Site

ESTM Boosting refund to @bootlegbilly!
Due to one of these reasons:
1. Not posted from eSteem apps.
2. Already curated by eSteem team.
3. Need bit more improvement on quality of post.
4. Might be too old post.
5. User already received vote in last couple hours, you can try boosting again afterwhile.
Android, iOS, Windows, Mac, Linux