Communities

Writing
Writing
Codidact Meta
Codidact Meta
The Great Outdoors
The Great Outdoors
Photography & Video
Photography & Video
Scientific Speculation
Scientific Speculation
Cooking
Cooking
Electrical Engineering
Electrical Engineering
Judaism
Judaism
Languages & Linguistics
Languages & Linguistics
Software Development
Software Development
Mathematics
Mathematics
Christianity
Christianity
Code Golf
Code Golf
Music
Music
Physics
Physics
Linux Systems
Linux Systems
Power Users
Power Users
Tabletop RPGs
Tabletop RPGs
Community Proposals
Community Proposals
tag:snake search within a tag
answers:0 unanswered questions
user:xxxx search by author id
score:0.5 posts with 0.5+ score
"snake oil" exact phrase
votes:4 posts with 4+ votes
created:<1w created < 1 week ago
post_type:xxxx type of post
Search help
Notifications
Mark all as read See all your notifications »
Sandbox

Comments on Obligatory factorial challenge

Post

Obligatory factorial challenge

+3
−0

It looks like we don't have a simple factorial challenge yet, so here's one.

Task

Given a non-negative number, output the factorial of that number ($n!$). The factorial of a number can be defined as such:

$$f(0)=1$$ $$f(n)=n \times f(n-1)$$

Test cases

Input! = Output
0! = 1
1! = 1
2! = 2
3! = 6
4! = 24
5! = 120
6! = 720
10! = 3628800

Rules

  • The default rules for input and output apply.
  • This is [code-golf], so the shortest code in bytes wins!
  • Should I delete this draft or put it on hold? Razetime has pointed out that we don't want too many challenges similar to those Somewhere Else, but I thought this'd be a good challenge for beginners.
History
Why does this post require moderator attention?
You might want to add some details to your flag.

1 comment thread

Small note (3 comments)
Small note
Razetime‭ wrote over 2 years ago

It is generally a good idea to have different questions from what is already on the SE site, since unique content helps boost codidact on search engines. That being said, having more questions isn't necessarily a bad thing.

user‭ wrote over 2 years ago

That's true. I was going to go with the (n×"super") factorial question on SE that got closed, but I don't know if the author will let me repost that yet. I'll think up something to change it up a little.

Shaggy‭ wrote over 2 years ago

Razetime‭, while I mostly agree, given how much content we've already got on PPCG there is, inevitably, going to be quite a bit of crossover here. And, more specifically with catalogue questions like this that are common on all programming & golfing sites, I think they are something we should be adding here regardless.