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.
alteryx Community

# 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

Alteryx

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

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.

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

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

a = int(data['Field1'].iloc[0])
b = int(data['Field2'].iloc[0])
df = pd.DataFrame(divmod(a,b)).T
result = pd.concat([data,df], axis=1,join='inner')
Alteryx.write(result,1)``````

Cheers!

Phil

8 - Asteroid
Spoiler

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

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?

Alteryx

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

Spoiler

12 - Quasar

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

Spoiler
Workflow:

Macro:
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/

8 - Asteroid
Spoiler
Solution Attached

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 😂

15 - Aurora

Great challenge!

Spoiler