We've recently made an accessibility improvement to the community and therefore posts without any content are no longer allowed. Please use the spoiler feature or add a short message in the message body in order to submit your weekly challenge.

Weekly Challenge

Solve the challenge, share your solution and summit the ranks of our Community!

Also available in | Français | Português | Español | 日本語
IDEAS WANTED

We're actively looking for ideas on how to improve Weekly Challenges and would love to hear what you think!

Submit Feedback

Challenge #284: Division with Macros

AYXAcademy
Alteryx
Alteryx

A solution to last week's challenge can be found here.Image_284.PNG

 

This week's challenge was submitted by @patrick_digan  - Thanks for your submission!

 

It was inspired by this post where a user was trying to get the Mod function (Modulo) to work for big numbers.

 

For this challenge, you will have to create a macro to divide big numbers.

 

So let’s try to divide 1,234,567,890,109,876,543,210 by 1,234 and produce both the quotient and remainder.

 

Scratching your head already?!

 

Hint: It's not 1,000,460,202,682,230,000 with remainder -442

Maskell_Rascal
13 - Pulsar

Not sure how others will solve this with the limitations of the Mod function to Int64 within Alteryx, but I would just go with Python. So here is my one tool Python solution!

Spoiler
from ayx import Package
from ayx import Alteryx
import pandas as pd

data = Alteryx.read("#1")
a = int(data['Field1'].iloc[0])
b = int(data['Field2'].iloc[0])
df = pd.DataFrame(divmod(a,b)).T
df.columns = ['answer','remainder']
result = pd.concat([data,df], axis=1,join='inner')
Alteryx.write(result,1)
Maskell_Rascal_0-1631025390006.png

 

Cheers!

Phil

Spalders
8 - Asteroid
Spoiler
Spalders_0-1631028375698.png

 

Working with a macro (modified from the one referenced in the Post)

Kenda
15 - Aurora
15 - Aurora

Brutal, @patrick_digan brutal

 

Spoiler
I started going down a different route but I ended up with so many if statements it was getting too confusing so I started over after a peak at the linked post. Who would've thought I'd prefer long division on paper?

Kenda_0-1631037564891.png

 

TonyA
Alteryx
Alteryx

Didn't look at the other macro, just tried this from scratch. There has to be an easier way...

Spoiler
TonyA_0-1631039309835.png
TonyA_0-1631039507224.png

 

phottovy
12 - Quasar

Thank you to calculatorsoup for reminding me how to do long division:

 

Spoiler
Workflow:
284.png

Macro:
284_Macro.png
Qiu
17 - Castor

I feel I should get some credit for this one, since I actually provided solution to the original post. 😁

This is a rather mathmatical solution, I believe.

https://www.geeksforgeeks.org/how-to-compute-mod-of-a-big-number/

challenge_284-1.PNGchallenge_284-2.PNG

balajilolla
8 - Asteroid
Spoiler
Solution Attached

balajilolla_0-1631064225666.png

 

clmc9601
12 - Quasar

A clumsy but original solution. Thanks for the challenge!

 

@Qiu your solution is so elegant! Way to go.

 

 

 

Spoiler
With a little more work, I could convert this to an iterative macro to make it dynamic for larger numbers. It could split the incoming number into segments iteratively after every 15 characters instead of statically after the first 15 characters. It took me long enough to get the right answer that it felt like a win even without including a macro 😂 

Screen Shot 2021-09-07 at 9.02.48 PM.png

 

RolandSchubert
15 - Aurora
15 - Aurora

Great challenge! 

 

Spoiler
284.jpg