Weekly Challenges

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

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

Want to get involved? We're always looking for ideas and content for Weekly Challenges.

SUBMIT YOUR IDEA

Challenge #74: Build a Factorial Calculator

JoeM
Alteryx Alumni (Retired)

We are one week away from the challenge #75 milestone. Some users want to race this one to be the first to 75 and nab the first ever ‘Burgschrund Crevasse’ badge. I will plan to post the challenge on 6/26/2017 at 9:00 AM PST. The main contenders are  @SeanAdams, @NicoleJohnson, @LordNeilLord, and @estherb47 barring any other users catching up on a significant amount of challenges this week.

 

This week, we are going to slow it down and take a breather after our two-week long challenge #73 and shoot for something simpler. This week, the goal is to create a macro that calculates factorials. To find the exact formula, you can find it here: https://en.wikipedia.org/wiki/Factorial. Factorials are commonly used to calculate the multitude of ways a task can be completed – like how many possible results could come from shuffling  52 playing cards.

Factorials are usually represented by ‘n!’ – n being an integer. If we were looking for the factorial of 4, it would be represented as 4!. To calculate the factorial of 4, the equation is written as (4)*(3)*(2)*(1). Below are some example caculations.

1! = (1) = 1

2! = (2)*(1) = 2

3! = (3)*(2)*(1) = 6

4! = (4)*(3)*(2)*(1) = 24

NicoleJohnson
ACE Emeritus
ACE Emeritus

My solution!

 

Now I'm off to do some pre-race stretching for next week. And polish my out-of-office email so no one bothers me starting at 9am PST on Monday. :)

 

Spoiler
I ended up doing some things with converting to string because I was having a hard time with it cutting off my numbers when it got to a long length answer (I tested it with 22, and realized the last few numbers disappeared, so I re-evaluated...). I could be having a total brain block though. Am I missing an obvious field type that would let me have super-long numbers?

At any rate... it works. Especially for factorials 17! and lower. :)
weeklychallenge74.JPG

Cheers! NJ

alex
11 - Bolide

Here it is.

PhilipMannering
16 - Nebula
16 - Nebula

My solution below

Spoiler
Factorial Macro.png
And used in the workflow below
factorial use.png

I find it particularly difficult to keep all the input fields, keep the same input names and keep the same field order without a shed load of action tools. Any advice on this?

patrick_digan
17 - Castor
17 - Castor

Attached!

Spoiler
I went with the generate rows tool to generate all the numbers from 1 to n, followed by a multi-row tool to calculate the product. If I can get on my soap box, wouldn't it be great if the summarize tool could take a product? That would have eliminated the multi-row tool/sample combo. Feel free to star this great idea if you agree: https://community.alteryx.com/t5/Alteryx-Product-Ideas/Add-Product-to-Summarize-tool/idi-p/26682

Untitled.png
EDIT: @NicoleJohnson I now see that our solutions are nearly identical :)

 

LordNeilLord
15 - Aurora

A nice simple solution, pretty much the same as everyone else 

 

Spoiler
Weekly Challenge 74.png
patrick_digan
17 - Castor
17 - Castor

@PhilipMannering In regards to your action tools, I would make a couple tweaks to avoid this:

1) I would check the box on your macro input about show field map. This is a powerful option where whatever the field name that comes in from the workflow, it converts it to whatever field name is in the macro input. For this case, it would convert the fieldname "Number" to "vals".

2) I would add a select tool at the end, and then connect an action tool from the macro input to your select tool using the "update select with reverse field map" option. This is the way to change vals back to Number so that the user never knows that the fieldname was changed.

3) I would change your join tool so that your field is named vals instead of right_vals. For #2 to work, it has to find the field vals exactly to convert it back.

 

Now you can delete all the action tools and your interface as well:

Capture.PNG

Hope that helps!

Philip
12 - Quasar

My solution

 

Spoiler
Factorial.png
MinaGO
7 - Meteor

Hi all I've returned after my lack of internet hiatus (plus moving to TheInformationLab) :)
I think I like the elegance of other people's solutions more but here was how I solved it

Spoiler
Screenshot (34).pngScreenshot (32).png
Simona
7 - Meteor

Nice one! I rarely use the Generate rows tool but it was very helpful in this case. :) 

Spoiler
Below my workflow. I guess something to make it better could be to create an interface, but I made this litterally in 10 minutes.
Factorial macro.PNG