cancel
Showing results for
Did you mean:
Announcement | Get certified today - take the Alteryx Designer Core and Advanced exams on-demand now!
Do you have the skills to make it to the top? Subscribe to our weekly challenges. Try your best to solve the problem, share your solution, and see how others tackled the same problem. We share our answer too.
Weekly Challenge
Do you have the skills to make it to the top? Subscribe to our weekly challenges. Try your best to solve the problem, share your solution, and see how others tackled the same problem. We share our answer too.
Unable to display your progress at this time. Please try again a little later, or contact an administrator if you continue to see this error.

## Challenge #74: Build a Factorial Calculator

Highlighted
Sr. Learning Strategy Manager

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

Pulsar

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. :)

Cheers! NJ

Bolide

Here it is.

Alteryx Certified Partner

My solution below

Spoiler

And used in the workflow below

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?

Aurora

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

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

Alteryx Certified Partner

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

Spoiler
Aurora

@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:

Hope that helps!

Quasar

My solution

Spoiler
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
Alteryx Certified Partner

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.