Share your repls and programming experiences

← Back to all posts
#WEEKLY but different [[FIXED]]
h
Codemonkey51 (794)

Almost everyone did inverse division, but I did not I used no packages only default python and made my solution it is unique and not copied down hope you enjoy

UPDATE: it can now do float*float (this is the only place where I did double division) also put the bigger numbers in number 2 or it will give recursion error.

Commentshotnewtop
Scoder12 (642)

Only has 5 digits of precision:

Codemonkey51 (794)

That's because it remove trailing zeros or it would be 1.2345678900002 sometimes sorry about that @Scoder12

HahaYes (1032)

Wait what is this weekly thing

superwhiskers (39)

You are NOT ALLOWED to use the multiplication operator (*) or loops(for, while or any other that your prefered language may support, goto also counts as a loop).

this is illegal according to the rules. recursion or any similar construct in any language would count as a form of looping

raghavm (95)

@superwhiskers i disagree, recursion isn't technically a loop

Codemonkey51 (794)

I asked H (theDrone) said it was ok :) @raghavm

raghavm (95)

@Codemonkey51 Oh thats great! Mine is recursion too!

AmazingMech2418 (692)

@superwhiskers While recursion can emulate a loop, it is not a loop structure. The thing with goto does not include gosub (like in BASIC) which is the equivalent of functions in that sort of language. Additionally, if using JS, an interval is not a loop technically and same with requestAnimationFrame. Loop structures are not allowed, not necessarily loop emulations (recursion, intervals, animations, etc.), but a goto function is essentially a loop without being explicitly defined as a loop by going to a previous line and then reading from that line to the goto command, following the structure of a loop. However, recursion, intervals, and requestAnimationFrame are not following this structure, although it would be best to use recursion in this case due to the very close similarities between intervals and animation frames.

superwhiskers (39)

@AmazingMech2418

while yes, it isn't a loop, it is functionally equivalent in many ways. to further this argument, i would like to point out that there is something called tail-call optimization, which optimizes recursive functions into goto loops, which only highlights the similarities. if that isn't enough for you, i would also like to point out that it is extremely trivial to convert an imperative looping construct into a recursive definition, making it all more important that if you want to block looping, you cannot only disallow the common, imperative looping constructs.

Codemonkey51 (794)

It is still allowed you saw that theDrone7 said yes I and before that I asked about loops that was a no, while they may be equivalent they are still allowed @superwhiskers

Lord_Poseidon (158)

@superwhiskers Yeah. This is an oversight of some sort, probably, but @TheDrone7 said it was okay. (I don't think it should be)

qsa (3)

@Lord_Poseidon if you couldn't use recursion, it would sorta kill the competition since it would just encourage only doing double division. multiplication is a fundamentally iterative operation, and even division is implemented through repetition- at a low level it also uses loops to get a result. disallowing strict imperative loops (for, while, loop, goto) but allowing things like recursion encourage more creative and more varied solutions. someone who would just do a for loop to sum integers will have to think outside the box for this competition, which might lead to them learning about recursion. and if you can learn something from the weekly challenge, you've already benefitted, regardless of how well you do. so recursion is cool

Lord_Poseidon (158)

@qsa I totally understand. A solution may not be arrived at without looping/recursion of any kind. Recursion may not encourage more creativity as there's only so many ways you can add numbers. Blocking recursion might give even more diverse solutions out of the desire to be different from the inverse croud. Something like @PYer 's logarithm addition

That said. It is theoritically impossible to achieve multiplication without loops. This question is more about finding loopholes than writing algorithms smh

qsa (3)

@Lord_Poseidon lmao yeah it's not really an algorithm type question. you could do something like that if you wanted to i guess. and yeah there's obviously the easy way out w recursion, and you can just use recursion for any loop, does make it relatively easy for integers. log addition is clever, i approached the problem from a more technical standpoint than math

Lord_Poseidon (158)

@qsa @qsa cool! Can I see your submission? I went used python's map and some binary math stuff https://repl.it/@Lord_Poseidon/AgileSturdyGreenware

qsa (3)

@Lord_Poseidon that looks neat, i love how concise that python is. i went pretty heavy on the binary math lmao, made debugging a nightmare https://repl.it/@qsa/mulc
also if some value is like randomly 2x higher than it should be, lmk because that's happened a few times recently but i've caught all the bugs so far

Lord_Poseidon (158)

@qsa And I thought I went overboard... This is too arcane for my eyes.

AmazingMech2418 (692)

@Lord_Poseidon Blocking recursion, however, would eliminate the possibility of using a self-made string library for string multiplication to not use the multiplication operator.

Lord_Poseidon (158)

@AmazingMech2418 recursion does allow many possibilities.

Codemonkey51 (794)

Got thumbs up from H saying he knows that they can be used the same but it's still allowed @PYer

AtriDey (127)

I was just coding a program that works like this! Now I need a new loophole >:c

Scoder12 (642)

Doesn't work for 0.5 * 0.5

Codemonkey51 (794)

Yes it's broken rn I'm adding that rn @Scoder12

Codemonkey51 (794)

works now read the update @Scoder12

AmazingMech2418 (692)

Nice! However, I'd recommend using callback functions for modularity. Also, you can create your own method of float multiplication kind of like what I did in my submission (in JS though).

Codemonkey51 (794)

That's what I'm doing rn just need to figure out how to do decimal places in the first number :/ @AmazingMech2418

AmazingMech2418 (692)

@Codemonkey51 Use basic algorithms you likely learned in elementary school math classes...

Codemonkey51 (794)

Lol it's how I did it that makes it hard :/ @AmazingMech2418

AmazingMech2418 (692)

@Codemonkey51 Yeah... Look at the length of mine though... I used probably the easiest algorithm to use for decimal multiplication and it still ended up being 126 lines.

Codemonkey51 (794)

Lol I made a copy for testing also mine is: 50 rn but I need to add float float it can only do in float or float * int rn :( @AmazingMech2418

AmazingMech2418 (692)

@Codemonkey51 Yeah. Try using a string library.

Codemonkey51 (794)

Lol ok, I'll see after I do one last attempt :) @AmazingMech2418

AmazingMech2418 (692)

@Codemonkey51 Though, you'd have to make the library yourself. Kind of like what I did...

Codemonkey51 (794)

Lol well I almost have the answer I think :) @AmazingMech2418

AmazingMech2418 (692)

@Codemonkey51 By n9w, I'm guessing you mean now... LOL! Great job though!

DynamicSquid (2624)

Yeah, you get to see a lot of inverse division. I guess it's the easiest to do. Yours is actually pretty creative though, good job! I also tried to do something different, but I think yours is better :)

Codemonkey51 (794)

Mine is a bit broken rn tho :( @DynamicSquid

DynamicSquid (2624)

@Codemonkey51 no, it's still good though :)

Codemonkey51 (794)

I am almost done!!! Just like 4 or 5 more lines @DynamicSquid

Codemonkey51 (794)

Just found out it's broken :( @Codemonkey51

DynamicSquid (2624)

@Codemonkey51 :( hope you can fix it though!

DynamicSquid (2624)

@Codemonkey51 this is one reason I hate working with numbers in programming, it's so hard. you need to find a specific language if you really want to work with numbers

Codemonkey51 (794)

I'm using python and going the hard way (not double division) and all I need now is float*float @DynamicSquid

DynamicSquid (2624)

@Codemonkey51 i find it a little weird in python since in c++ you specify the data type, well good luck!

ChezCoder (1480)
Traceback (most recent call last):
  File "main.py", line 31, in <module>
    start()
  File "main.py", line 29, in start
    print(multiply(x,y))
  File "main.py", line 24, in multiply
    return(repeat(x,y,y))
  File "main.py", line 5, in repeat
    return(repeat(times-1,multiple+baseline,baseline))
NameError: name 'baseline' is not defined
CodingCactus (2784)

oof, might want to make it a float

CodingCactus (2784)

@Codemonkey51 erm it don't work with the decimals :(

Codemonkey51 (794)

It's hard bc I'm not using inverse division :( @CodingCactus

Codemonkey51 (794)

I hope to get more points for that :) @CodingCactus

CodingCactus (2784)

@Codemonkey51 is it called inverse division?
I'm pretty sure it is called dividing by the reciprocal

CodingCactus (2784)

I hope to get more points for that

Hopefully :)

DynamicSquid (2624)

@CodingCactus reciprocal - I like that word xD