| Bytes | Lang | Time | Link |
|---|---|---|---|
| 019 | Raku Perl 6 rakudo | 240731T061736Z | bb94 |
| 029 | Haskell | 240731T020609Z | MaroonSp |
| 006 | Japt | 240730T220016Z | Shaggy |
| 015 | Desmos | 240118T144546Z | Joao-3 |
| 032 | Google Sheets | 240201T105853Z | z.. |
| 030 | Labyrinth | 240121T234347Z | Bubbler |
| 051 | Python | 240119T071004Z | Albert.L |
| 062 | Python 3.8 prerelease | 240118T135305Z | Gáb |
| 131 | Java 10 | 240118T102609Z | Kevin Cr |
| 054 | dc | 240118T153951Z | camelCas |
| 004 | Jelly | 240118T022319Z | Fmbalbue |
| 005 | APLDyalog Unicode | 240118T004349Z | Tbw |
| 041 | Perl 5 | 240117T233725Z | Kjetil S |
| 011 | Charcoal | 240118T100321Z | Neil |
| 044 | JavaScript Node.js | 240118T003551Z | l4m2 |
| 003 | Jelly | 240118T103749Z | Jonathan |
| 043 | Retina | 240118T100052Z | Neil |
| 013 | Wolfram Language Mathematica | 240118T094433Z | ZaMoC |
| 015 | PARI/GP | 240118T092417Z | alephalp |
| 009 | Uiua SBCS | 240118T083938Z | chunes |
| 005 | MathGolf | 240118T075910Z | Kevin Cr |
| 005 | 05AB1E | 240118T075535Z | Kevin Cr |
| 029 | Funge98 | 240118T040510Z | Alt Shif |
| 055 | Scala 3 | 240118T021844Z | 138 Aspe |
| 004 | Vyxal | 240118T011320Z | emanresu |
| 007 | J | 240118T001253Z | Bubbler |
| 046 | JavaScript V8 | 240117T235331Z | Arnauld |
| 170 | C gcc | 240117T231031Z | vengy |
Google Sheets, 32 bytes
=SORT(FACT(A1)+SEQUENCE(A1-1)+1)
Labyrinth, 30 bytes
?:} @\!
(:{+ ""
*; :=;;
#(;)
Introducing "small-loop-oriented programming" ;)
? program start; take n from stdin
let's say n = 4
[ 4 | ]
:} run in the order of :(:}
(: : dup [ 4 4 | ]
( decrement [ 4 3 | ]
: dup [ 4 3 3 | ]
} move to aux.stack [ 4 3 | 3 ]
loop until the top is 0 after `decrement`
[ 4 3 2 1 0 | 1 2 3 ]
*; run in the order of ;*#(
#( ; drop [ 4 3 2 1 | 1 2 3 ]
* mul [ 4 3 2 | 1 2 3 ]
# stack height [ 4 3 2 3 | 1 2 3 ]
( decrement [ 4 3 2 2 | 1 2 3 ]
loop until the top is 0 after `decrement`, i.e. stack height is 1
[ 24 0 | 1 2 3 ]
;) drop 0, and increment the factorial
[ 25 | 1 2 3 ]
{+ run in the order of :=+{
:= : dup [ 25 25 | 1 2 3 ]
= swap the tops [ 25 1 | 25 2 3 ]
+ add [ 26 | 25 2 3 ]
{ move from aux.stack [ 26 25 | 2 3 ]
loop until the top is 0 after `swap the tops`
[ 26 27 28 25 0 | 25 ]
;; drop twice [ 26 27 28 | 25 ]
\! run in the order of ""!\ (" is no-op)
"" ! pop and print as num
\ print a newline
loop until the top is zero, i.e. there is nothing left to print
@ end the program
Python, 51 bytes
f=lambda n:range((n<2or(f(n-1).stop-n)*n)-~n)[1-n:]
Returns a range object.
Original Python, 56 bytes
f=lambda n:[n*([*f(n-1),3][0]-2)+j+2for j in range(n-1)]
Python 3.8 (pre-release), 69 62 bytes
lambda n:[i-~math.factorial(n)for i in range(1,n)]
import math
Edit: changed math.prod to math.factorial, thanks to @l4m2
Java 10, 134 131 bytes
n->{var f=n.ONE;int N=n.intValue(),i=N;for(;i>1;)f=f.multiply(n.valueOf(i--));for(;i++<N;)System.out.println(f.add(n.valueOf(i)));}
-3 bytes thanks to @ceilingcat.
Input as a BigInteger, outputs on separated lines to STDOUT.
Explanation:
n->{ // Method with BigInteger as parameter and no return:
var f=n.ONE; // Start `f` with BigInteger 1
int N=n.intValue(), // Set `N` to the input-BigInteger as integer
i=N;for(;i>1;) // Loop `i` in the range [N,1):
f=f.multiply(n.valueOf(i)); // Multiply `f` by `i`
for(;i++<N;) // Loop `i` again, this time in the range (1,N]:
System.out.println( // Print with trailing newline:
f.add(n.valueOf(i)));} // `f` + `i`
dc, 56 54 bytes
[dlf*sf1-d0!=q]sq1sf?d1-sm[dlf2++p0=m1+dlm!=e]selqxlex
This solution isn't the most optimized, you could probably use less registers than I did here.
Jelly, 4 bytes
RḊ+!
Port of Vyxal answer.
-1 byte thanks to @emanresu A
Explanation:
RḊ+!
RḊ # [2 .. n]
+! # + n!
💎
Created with the help of Luminespire.
APL(Dyalog Unicode), 5 bytes SBCS
1↓⍳+!
A tacit function that takes an integer on the right and returns an array of n-1 composite numbers.
Explanation
! ⍝ factorial
+ ⍝ plus
⍳ ⍝ range
1↓ ⍝ drop the first
There are actually two other permutations of these five characters that produce the same result. See if you can find them. ;)
6 bytes, outputs full numbers under \$10^{34}\$
⍕1↓⍳+!
Try it!
This requires adding (⎕FR⎕PP)←1287 34 to the header to set the float and printing precision.
Charcoal, 11 bytes
≔…·²NθI⁺θΠθ
Try it online! Link is to verbose version of code.
≔…·²Nθ
Create a list from 2 up to n inclusive.
I⁺θΠθ
Vectorised add the list to its product.
Of course, the given formula is just an existence proof and there are usually lower runs. For instance, the LCM is readily proven to produce a run:
Nθ≔…·²θηW⌈﹪±θη≧⁺ιθI⁺θη
Try it online! Link is to verbose version of code. Or more efficiently:
Nθ≔…·²θηFη≔⌊Φ×⊖ηθ¬﹪κιθI⁺θη
Try it online! Link is to verbose version of code.
JavaScript (Node.js), 52 51 47 46 45 44 bytes
f=(n,i=n)=>--n&&f(n,g=i*n)>console.log(n-~g)
-1 byte from Arnauld/tsh
JavaScript (Node.js), 38 bytes by Mukundan314
f=(n,i=n)=>--n?[...f(n,g=i*n),n-~g]:[]
Jelly, 3 bytes
Ḋ+!
A monadic Link that accepts a positive integer, \$n\$, and yields a list of the \$n-1\$ consecutive integers.
How?
Ḋ+! - Link: integer, n
Ḋ - dequeue {n} -> [2, 3, 4, ..., n]
! - {n} factorial -> n!
+ - add (vectorises) -> [2+n!, 3+n!, 4+n!, ..., n+n!]
Retina, 43 bytes
.+
*
v`__+
$.&$*
L$`\d+
$$.($&*_$=
%~`^
.+¶
Try it online! Outputs the numbers in descending order. Explanation:
.+
*
Convert n to unary.
v`__+
$.&$*
Create an expression n*...*3*2* that evaluates to n! in unary.
L$`\d+
$$.($&*_$=
For each integer in that expression, create an expression that adds i and converts to decimal.
%~`^
.+¶
Evaluate each resulting expression.
MathGolf, 5 bytes
╒╞\!+
Explanation:
╒ # Push a list in the range [1, (implicit) input]
╞ # Remove the first value to make the range [2,input]
\ # Swap to push the (implicit) input
! # Take its factorial
+ # Add it to each value in the list
# (after which the entire stack is output implicitly as result)
05AB1E, 5 bytes
L¦¤!+
Try it online or verify all test cases.
Explanation:
L # Push a list in the range [1, (implicit) input]
¦ # Remove the first value to make the range [2,input]
¤ # Push the last item (without popping the list): the input
! # Take its factorial
+ # Add it to each value in the list
# (after which this list is output implicitly as result)
J, 7 bytes
!-<:$i:
Returns the list of numbers in reverse order. When given a bigint, outputs the exact numbers in bigint.
!-<:$i: input: n, a positive integer
i: [-n, -n+1, ..., n]
<: n-1
$ take first n-1 items from the list, i.e. [-n, ..., -2]
! n!
- n! - each item of [-n, ..., -2]
== [n!+n, n!+n-1, ..., n!+2]
J, 8 bytes
!+-.{.i:
Returns the list of numbers in the order given.
!+-.{.i: input: n, a positive integer
i: [-n, -n+1, ..., n]
-. 1-n
{. since 1-n is negative, take n-1 items from the end;
[2, ..., n]
!+ add n! to each item of the list
JavaScript (V8), 46 bytes
Prints the results in reverse order.
n=>{for(p=i=n;--i;)p*=i;while(--n)print(p-~n)}
JavaScript (ES11), 52 bytes
With BigInts.
n=>{for(p=i=n;--i;)p*=i;while(--n)console.log(p-~n)}
C (gcc), 170 bytes
Using The GNU Multiple Precision Arithmetic Library
f(n){mpz_t f,t;mpz_init(f);mpz_init(t);mpz_set_ui(f,1);for(int i=1;i<=n;mpz_mul_ui(f,f,i++));for(int i=2;i<=n;mpz_add_ui(t,f,i),mpz_out_str(stdout,10,t),puts(""),i++);}