Want to get involved? We're always looking for ideas and content for Weekly Challenges.
SUBMIT YOUR IDEAA 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.
Scratching your head already?!
Hint: It's not 1,000,460,202,682,230,000 with remainder -442
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!
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)
Cheers!
Phil
Working with a macro (modified from the one referenced in the Post)
Brutal, @patrick_digan brutal
Didn't look at the other macro, just tried this from scratch. There has to be an easier way...
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/
A clumsy but original solution. Thanks for the challenge!
@Qiu your solution is so elegant! Way to go.