Linked Questions

-3 votes
6 answers

Double Factorial [duplicate]

Challenge The objective is simple, in the shortest amount of bytes, write a function or program that takes a number and prints its double factorial. The input must be taken from stdin or a function ...
globby's user avatar
  • 1,190
149 votes
336 answers

Fibonacci function or sequence

The Fibonacci sequence is a sequence of numbers, where every number in the sequence is the sum of the two numbers preceding it. The first two numbers in the sequence are both 1. Here are the first ...
C. K. Young's user avatar
  • 4,937
167 votes
66 answers

Tips for golfing in C

What general tips do you have for golfing in C? I'm looking for ideas that can be applied to code golf problems in general that are at least somewhat specific to C (e.g. "remove comments" is not an ...
Casey's user avatar
  • 3,609
57 votes
154 answers

The vanilla factorial challenge

Task Given a non-negative integer \$n\$, evaluate the factorial \$n!\$. The factorial is defined as follows: $$ n!=\begin{cases}1 & n=0\\n\times(n-1)!&n>0\end{cases} $$ Rules All default I/...
Bubbler's user avatar
  • 77.1k
39 votes
41 answers

Repeated! Factorials!

Not to be confused with Find the factorial! Introduction The factorial of an integer n can be calculated by $$n!=n\times(n-1)\times(n-2)\times(...)\times2\times1$$...
Jitse's user avatar
  • 7,334
37 votes
30 answers

Factorials and never ending cycles!

As you may know it, the factorial of a positive integer n is the product of all the positive integers which are equal or smaller to ...
user avatar
29 votes
31 answers

Deranged !Combinatorics: Compute the Subfactorial

The subfactorial or rencontres numbers (A000166) are a sequence of numbers similar to the factorial numbers which show up in the combinatorics of permutations. In particular the nth subfactorial !n ...
Martin Ender's user avatar
20 votes
36 answers

Mathematical Combination

Write a program that takes an input such as: n,k which then computes: $$\binom n k = \frac {n!} {k!(n-k)!}$$ and then prints the result. A numerical example: ...
backus's user avatar
  • 325
27 votes
19 answers

Last non-zero digit of n!

Given an integer 1 ≤ N ≤ 1,000,000 as input, output the last non-zero digit of N!, where ! is the factorial (the product of all numbers from 1 to N, inclusive). This is OEIS sequence A008904. Your ...
fR0DDY's user avatar
  • 4,577
31 votes
14 answers

Array Escape - get out of there

One day you awake only to find yourself caught in an array. You try to just walk out of there, taking one index at the time, but it seems there are other rules: The array is completely filled with ...
Michael Kunst's user avatar
29 votes
15 answers

Tips for golfing in Swift

What are some tips for code-golfing in Swift? Its focus on safety seems to make it difficult to golf in, but that makes little tips and even more useful. Are there any features in Swift that may help ...
addison's user avatar
  • 1,073
23 votes
13 answers

Generalised multi-dimensional chess knight's moves

Multi-dimensional chess is an extension of normal chess that is played on an 8x8x8x8... "board". In normal 2D chess, a knight's move is a movement by a vector of \$ \begin{bmatrix} \pm 2 \\ \...
pxeger's user avatar
  • 23.9k
14 votes
15 answers

Am I a Pillai prime?

A Pillai prime is a prime number \$p\$ for which there exists some positive \$m\$ such that \$(m! + 1) \equiv 0 \:(\text{mod } p)\$ and \$p \not\equiv 1\:(\text{mod }m)\$. In other words, an ...
Mr. Xcoder's user avatar
  • 42.4k
13 votes
19 answers

How much candy can you eat?

Credit to Geobits in TNB for the idea A post without sufficient detail recently posited an interesting game: 2 children sit in front of an array of candy. Each piece of candy is numbered 1 to ...
Mayube's user avatar
  • 11.6k
33 votes
6 answers

Python workarounds for assignment in lambda

This is a tips question for golfing in Python. In Python golfing, it's common for a submission to be a function defined as a lambda. For example, ...
xnor's user avatar
  • 145k

15 30 50 per page