Incremental Ranges!Analyzing Collatz-like sequencesFinding Collatz-like rules with many loopsGenerate The SUDSI SequenceThe Kimberling SequenceHow many integers contain a number in a specific rangeCompress a maximal discrepancy-2 sequenceA Euro-iginal SequenceThe Ever-Increasing GraphThe Jumping Up SequenceA function to take three integers and return a list of integers and alphabet-letters
Have powerful mythological heroes ever run away or been deeply afraid?
Short story written from alien perspective with this line: "It's too bright to look at, so they don't"
Humans meet a distant alien species. How do they standardize? - Units of Measure
You've spoiled/damaged the card
Will dual-learning in a glider make my airplane learning safer?
How can I grammatically understand "Wir über uns"?
Do adult Russians normally hand-write Cyrillic as cursive or as block letters?
Opposite of "Squeaky wheel gets the grease"
Did Darth Vader wear the same suit for 20+ years?
Applicants clearly not having the skills they advertise
When leasing/renting out an owned property, is there a standard ratio between monthly rent and the mortgage?
Does any lore text explain why the planes of Acheron, Gehenna, and Carceri are the alignment they are?
What's the most polite way to tell a manager "shut up and let me work"?
Unconventional Opposites
Why does a helium balloon rise?
Why use water tanks from a retired Space Shuttle?
If a problem only occurs randomly once in every N times on average, how many tests do I have to perform to be certain that it's now fixed?
Explain Ant-Man's "not it" scene from Avengers: Endgame
How can I make 20-200 ohm variable resistor look like a 20-240 ohm resistor?
How do I get a cleat that's stuck in a pedal, detached from the shoe, out?
GFCI Outlet in Bathroom, Lights not working
How can I offer a test ride while selling a bike?
Please help me identify this plane
Pros and cons of writing a book review?
Incremental Ranges!
Analyzing Collatz-like sequencesFinding Collatz-like rules with many loopsGenerate The SUDSI SequenceThe Kimberling SequenceHow many integers contain a number in a specific rangeCompress a maximal discrepancy-2 sequenceA Euro-iginal SequenceThe Ever-Increasing GraphThe Jumping Up SequenceA function to take three integers and return a list of integers and alphabet-letters
$begingroup$
Your task is to, given two positive integers, $x$ and $n$, return the first $x$ numbers in the incremental ranges sequence.
The incremental range sequence first generates a range from one to $n$ inclusive. For example, if $n$ was $3$, it would generate the list $[1,2,3]$. It then repeatedly appends the last $n$ values incremented by $1$ to the existing list, and continues.
An input of $n=3$ for example:
n=3
1. Get range 1 to n. List: [1,2,3]
2. Get the last n values of the list. List: [1,2,3]. Last n=3 values: [1,2,3].
3. Increment the last n values by 1. List: [1,2,3]. Last n values: [2,3,4].
4. Append the last n values incremented to the list. List: [1,2,3,2,3,4]
5. Repeat steps 2-5. 2nd time repeat shown below.
2nd repeat:
2. Get the last n values of the list. List: [1,2,3,2,3,4]. Last n=3 values: [2,3,4]
3. Increment the last n values by 1. List: [1,2,3,2,3,4]. Last n values: [3,4,5].
4. Append the last n values incremented to the list. List: [1,2,3,2,3,4,3,4,5]
Test cases:
n, x, Output
1, 49, [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49]
2, 100, [1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13,14,14,15,15,16,16,17,17,18,18,19,19,20,20,21,21,22,22,23,23,24,24,25,25,26,26,27,27,28,28,29,29,30,30,31,31,32,32,33,33,34,34,35,35,36,36,37,37,38,38,39,39,40,40,41,41,42,42,43,43,44,44,45,45,46,46,47,47,48,48,49,49,50,50,51]
3, 13, [1,2,3,2,3,4,3,4,5,4,5,6,5]
code-golf number sequence array
$endgroup$
add a comment |
$begingroup$
Your task is to, given two positive integers, $x$ and $n$, return the first $x$ numbers in the incremental ranges sequence.
The incremental range sequence first generates a range from one to $n$ inclusive. For example, if $n$ was $3$, it would generate the list $[1,2,3]$. It then repeatedly appends the last $n$ values incremented by $1$ to the existing list, and continues.
An input of $n=3$ for example:
n=3
1. Get range 1 to n. List: [1,2,3]
2. Get the last n values of the list. List: [1,2,3]. Last n=3 values: [1,2,3].
3. Increment the last n values by 1. List: [1,2,3]. Last n values: [2,3,4].
4. Append the last n values incremented to the list. List: [1,2,3,2,3,4]
5. Repeat steps 2-5. 2nd time repeat shown below.
2nd repeat:
2. Get the last n values of the list. List: [1,2,3,2,3,4]. Last n=3 values: [2,3,4]
3. Increment the last n values by 1. List: [1,2,3,2,3,4]. Last n values: [3,4,5].
4. Append the last n values incremented to the list. List: [1,2,3,2,3,4,3,4,5]
Test cases:
n, x, Output
1, 49, [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49]
2, 100, [1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13,14,14,15,15,16,16,17,17,18,18,19,19,20,20,21,21,22,22,23,23,24,24,25,25,26,26,27,27,28,28,29,29,30,30,31,31,32,32,33,33,34,34,35,35,36,36,37,37,38,38,39,39,40,40,41,41,42,42,43,43,44,44,45,45,46,46,47,47,48,48,49,49,50,50,51]
3, 13, [1,2,3,2,3,4,3,4,5,4,5,6,5]
code-golf number sequence array
$endgroup$
add a comment |
$begingroup$
Your task is to, given two positive integers, $x$ and $n$, return the first $x$ numbers in the incremental ranges sequence.
The incremental range sequence first generates a range from one to $n$ inclusive. For example, if $n$ was $3$, it would generate the list $[1,2,3]$. It then repeatedly appends the last $n$ values incremented by $1$ to the existing list, and continues.
An input of $n=3$ for example:
n=3
1. Get range 1 to n. List: [1,2,3]
2. Get the last n values of the list. List: [1,2,3]. Last n=3 values: [1,2,3].
3. Increment the last n values by 1. List: [1,2,3]. Last n values: [2,3,4].
4. Append the last n values incremented to the list. List: [1,2,3,2,3,4]
5. Repeat steps 2-5. 2nd time repeat shown below.
2nd repeat:
2. Get the last n values of the list. List: [1,2,3,2,3,4]. Last n=3 values: [2,3,4]
3. Increment the last n values by 1. List: [1,2,3,2,3,4]. Last n values: [3,4,5].
4. Append the last n values incremented to the list. List: [1,2,3,2,3,4,3,4,5]
Test cases:
n, x, Output
1, 49, [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49]
2, 100, [1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13,14,14,15,15,16,16,17,17,18,18,19,19,20,20,21,21,22,22,23,23,24,24,25,25,26,26,27,27,28,28,29,29,30,30,31,31,32,32,33,33,34,34,35,35,36,36,37,37,38,38,39,39,40,40,41,41,42,42,43,43,44,44,45,45,46,46,47,47,48,48,49,49,50,50,51]
3, 13, [1,2,3,2,3,4,3,4,5,4,5,6,5]
code-golf number sequence array
$endgroup$
Your task is to, given two positive integers, $x$ and $n$, return the first $x$ numbers in the incremental ranges sequence.
The incremental range sequence first generates a range from one to $n$ inclusive. For example, if $n$ was $3$, it would generate the list $[1,2,3]$. It then repeatedly appends the last $n$ values incremented by $1$ to the existing list, and continues.
An input of $n=3$ for example:
n=3
1. Get range 1 to n. List: [1,2,3]
2. Get the last n values of the list. List: [1,2,3]. Last n=3 values: [1,2,3].
3. Increment the last n values by 1. List: [1,2,3]. Last n values: [2,3,4].
4. Append the last n values incremented to the list. List: [1,2,3,2,3,4]
5. Repeat steps 2-5. 2nd time repeat shown below.
2nd repeat:
2. Get the last n values of the list. List: [1,2,3,2,3,4]. Last n=3 values: [2,3,4]
3. Increment the last n values by 1. List: [1,2,3,2,3,4]. Last n values: [3,4,5].
4. Append the last n values incremented to the list. List: [1,2,3,2,3,4,3,4,5]
Test cases:
n, x, Output
1, 49, [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49]
2, 100, [1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13,14,14,15,15,16,16,17,17,18,18,19,19,20,20,21,21,22,22,23,23,24,24,25,25,26,26,27,27,28,28,29,29,30,30,31,31,32,32,33,33,34,34,35,35,36,36,37,37,38,38,39,39,40,40,41,41,42,42,43,43,44,44,45,45,46,46,47,47,48,48,49,49,50,50,51]
3, 13, [1,2,3,2,3,4,3,4,5,4,5,6,5]
code-golf number sequence array
code-golf number sequence array
edited 9 hours ago
Giuseppe
18.6k31358
18.6k31358
asked 9 hours ago
Comrade SparklePonyComrade SparklePony
3,70611756
3,70611756
add a comment |
add a comment |
21 Answers
21
active
oldest
votes
$begingroup$
Python 2, 39 bytes
lambda n,x:[v/n+v%n+1for v in range(x)]
Try it online!
$endgroup$
$begingroup$
Also works in Python 3 with the replacement of/
with//
$endgroup$
– Nick Kennedy
8 hours ago
add a comment |
$begingroup$
Jelly, 4 bytes
Ḷd§‘
A dyadic Link accepting two positive integers, x
on the left and n
on the right, which yields a list of positive integers.
Try it online!
How?
Ḷd§‘ - Link: x, n e.g 13, 3
Ḷ - lowered range (x) [0,1,2,3,4,5,6,7,8,9,10,11,12]
d - divmod (n) [[0,0],[0,1],[0,2],[1,0],[1,1],[1,2],[2,0],[2,1],[2,2],[3,0],[3,1],[3,2],[4,0]]
§ - sums [0,1,2,1,2,3,2,3,4,3,4,5,4]
‘ - increment (vectorises) [1,2,3,2,3,4,3,4,5,4,5,6,5]
$endgroup$
2
$begingroup$
Wait... is that divmod? Clever! And I was struggling withp
...
$endgroup$
– Erik the Outgolfer
8 hours ago
add a comment |
$begingroup$
R, 33 bytes
function(n,x,z=1:x-1)z%%n+z%/%n+1
Try it online!
Ports Jonathan Allan's Python solution.
R, 36 bytes
function(n,x)outer(1:n,0:x,"+")[1:x]
Try it online!
My original solution; generates an $ntimes x$ matrix with each column as the increments, i.e., $1 ldots n, 2ldots n+1,ldots$, then takes the first $x$ entries (going down the columns).
$endgroup$
add a comment |
$begingroup$
05AB1E, 6 bytes
L<s‰O>
Port of @JonathanAllan's Jelly answer, so make sure to upvote him!
First input is $x$, second input is $n$.
Try it online or verify all test cases.
Explanation:
L # Push a list in the range [1, (implicit) input]
# i.e. 13 → [1,2,3,4,5,6,7,8,9,10,11,12,13]
< # Decrease each by 1 to the range [0, input)
# → [0,1,2,3,4,5,6,7,8,9,10,11,12]
s‰ # Divmod each by the second input
# i.e. 3 → [[0,0],[0,1],[0,2],[1,0],[1,1],[1,2],[2,0],[2,1],[2,2],[3,0],[3,1],[3,2],[4,0]]
O # Sum each pair
# → [0,1,2,1,2,3,2,3,4,3,4,5,4]
> # And increase each by 1
# → [1,2,3,2,3,4,3,4,5,4,5,6,5]
# (after which the result is output implicitly)
My own initial approach was 8 bytes:
LI∍εN¹÷+
First input is $n$, second input is $x$.
Try it online or verify all test cases.
Explanation:
L # Push a list in the range [1, (implicit) input]
# i.e. 3 → [1,2,3]
I∍ # Extend it to the size of the second input
# i.e. 13 → [1,2,3,1,2,3,1,2,3,1,2,3,1]
ε # Map each value to:
N¹÷ # The 0-based index integer-divided by the first input
# → [0,0,0,1,1,1,2,2,2,3,3,3,4]
+ # Add that to the value
# → [1,2,3,2,3,4,3,4,5,4,5,6,5]
# (after which the result is output implicitly)
$endgroup$
add a comment |
$begingroup$
Brain-Flak, 100 bytes
(<>)<>([()]<(())(()[()](<>))<>(()<>)(<>)(<>)([()]<(<>[](())[()]<>)>)>)
With comments and formatting:
# Push a zero under the other stack
(<>)<>
# x times
# x - 1
([()]<
# Let 'a' be a counter that starts at n
# Duplicate a and NOT
(())(()[()](<>))
# if a == 0
# Pop truthy
<>
# Reset n to a
(()<>)
# Push 0 to each
(<>)(<>)
# Pop falsy
# Decrement A, add one to the other stack, and duplicate that number under this stack
([()]<
(<>[](())<>)
>)
>)
Try it online!
$endgroup$
$begingroup$
Your "golfed" version doesn't work (and the formatted/commented version on TIO minifies to 100 bytes).
$endgroup$
– Nitrodon
4 hours ago
$begingroup$
@Nitrodon Whoops, not sure how that happened. Fixed now!
$endgroup$
– DJMcMayhem♦
4 hours ago
add a comment |
$begingroup$
Jelly, 5 bytes
+þẎḣ’
Try it online!
$endgroup$
add a comment |
$begingroup$
Ruby, 32 bytes
->n,x(0...x).mapi
Try it online!
$endgroup$
add a comment |
$begingroup$
Japt -m
, 12 7 bytes
Port of Jonathan's Python solution.
Takes x
as the first input.
%VÄ+UzV
Try it
$endgroup$
add a comment |
$begingroup$
Perl 6, 18 bytes
(1..*X+ ^*)[^$_]
Try it online!
Curried function f(x)(n)
.
Explanation
# Anonymous block
X+ # Cartesian product with addition
1..* # of range 1..Inf
^* # and range 0..n
( )[^$_] # First x elements
$endgroup$
add a comment |
$begingroup$
Perl 5 -na
, 43 bytes
@r=map$_..$_+$F[1]-1,1..$_;say"@r[0..$_-1]"
Try it online!
$endgroup$
add a comment |
$begingroup$
Octave, 25 bytes
@(n,x)((1:n)'+(0:x))(1:x)
Anonymous function that inputs numbers n``and
x`, and outputs a row vector.
Try it online!
$endgroup$
add a comment |
$begingroup$
MATL, 16 bytes
:i:"tQ]v!1e 2G:)
Try it online!
Explanation:
: % Push [1, 2... n]
i:" ] % For i in [1, x]:
t % Duplicate the first array
Q % Increment each number
v % Concatenate everything into 1 matrix
! % Transpose
1e % Reshape into 1 row
2G % Push x again
:) % And take the first x elements
$endgroup$
1
$begingroup$
10 bytes using broadcasting.
$endgroup$
– Giuseppe
3 hours ago
add a comment |
$begingroup$
J, 13 12 bytes
[$[:,1++/&i.
Try it online!
how
We take x
as the left arg, n
as the right. Let's take x = 8
and n = 3
for this example:
+/&i.
: Transform both args by creating integer rangesi.
, that is, the left arg becomes0 1 2 3 4 5 6 7
and the right arg becomes0 1 2
. Now we create an "addition table+/
from those two:0 1 2
1 2 3
2 3 4
3 4 5
4 5 6
5 6 7
6 7 8
7 8 91 +
: Add 1 to every element of this table:1 2 3
2 3 4
3 4 5
4 5 6
5 6 7
6 7 8
7 8 9
8 9 10[: ,
: Flatten it,
:1 2 3 2 3 4 3 4 5 4 5 6 5 6 7 6 7 8 7 8 9 8 9 10
[ $
: Shape it$
so it has the same number of elements as the original, untransformed left arg[
, ie,x
:1 2 3 2 3 4 3 4
$endgroup$
add a comment |
$begingroup$
Alchemist, 77 bytes
_->In_n+In_x
x+n+0y+0z->a+Out_a+Out_" "+m+y
y+n->n
y+0n->z
z+m+a->z+n
z+0m->a
Try it online!
Increments and outputs a counter n times, then subtracts n-1 before repeating.
$endgroup$
add a comment |
$begingroup$
Charcoal, 18 bytes
NθFN⊞υ⊕⎇‹ιθι§υ±θIυ
Try it online! Link is to verbose version of code. I had dreams of seeding the list with a zero-indexed range and then slicing it off again but that was actually 2 bytes longer. Explanation:
Nθ Input `n` into variable
N Input `x`
F Loop over implicit range
ι Current index
‹ Less than
θ Variable `n`
⎇ ι Then current index else
θ Variable `n`
± Negated
§υ Cyclically indexed into list
⊕ Incremented
⊞υ Pushed to list
Iυ Cast list to string for implicit output
$endgroup$
add a comment |
$begingroup$
APL+WIN, 29 23 bytes
x↑,(0,⍳⌊(x←⎕)÷n)∘.+⍳n←⎕
Prompts for n and x
Try it online! Courtesy of Dyalog Classic
$endgroup$
add a comment |
$begingroup$
JS, 54 bytes
f=(n,x)=>Array.from(Array(x),(_,i)=>i+1-(i/n|0)*(n-1))
Try it online!
New contributor
$endgroup$
add a comment |
$begingroup$
Haskell, 34 33 bytes
n#x=take x$do j<-[1..];[j..j+n-1]
Try it online!
$endgroup$
add a comment |
$begingroup$
JavaScript, 36 bytes
n=>g=x=>x?[...g(--x),1+x%n+x/n|0]:[]
Try It Online!
$endgroup$
$begingroup$
Usingalert
orprint
instead of return an Array may reduce this to 34 bytes:n=>g=x=>x&&print(g(--x)|1+x%n+x/n)
$endgroup$
– tsh
5 mins ago
add a comment |
$begingroup$
Perl 5, 39 bytes
say 1+int($_/$F[1])+$_%$F[1]for 0..$_-1
Try it online!
$endgroup$
add a comment |
$begingroup$
C (gcc), 49 44 bytes
Using recursion to save some bytes.
f(n,x)x&&printf("%d ",x%n+x/n+1,f(n,--x));
Try it online!
$endgroup$
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "200"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodegolf.stackexchange.com%2fquestions%2f186233%2fincremental-ranges%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
21 Answers
21
active
oldest
votes
21 Answers
21
active
oldest
votes
active
oldest
votes
active
oldest
votes
$begingroup$
Python 2, 39 bytes
lambda n,x:[v/n+v%n+1for v in range(x)]
Try it online!
$endgroup$
$begingroup$
Also works in Python 3 with the replacement of/
with//
$endgroup$
– Nick Kennedy
8 hours ago
add a comment |
$begingroup$
Python 2, 39 bytes
lambda n,x:[v/n+v%n+1for v in range(x)]
Try it online!
$endgroup$
$begingroup$
Also works in Python 3 with the replacement of/
with//
$endgroup$
– Nick Kennedy
8 hours ago
add a comment |
$begingroup$
Python 2, 39 bytes
lambda n,x:[v/n+v%n+1for v in range(x)]
Try it online!
$endgroup$
Python 2, 39 bytes
lambda n,x:[v/n+v%n+1for v in range(x)]
Try it online!
answered 8 hours ago
Jonathan AllanJonathan Allan
56k538178
56k538178
$begingroup$
Also works in Python 3 with the replacement of/
with//
$endgroup$
– Nick Kennedy
8 hours ago
add a comment |
$begingroup$
Also works in Python 3 with the replacement of/
with//
$endgroup$
– Nick Kennedy
8 hours ago
$begingroup$
Also works in Python 3 with the replacement of
/
with //
$endgroup$
– Nick Kennedy
8 hours ago
$begingroup$
Also works in Python 3 with the replacement of
/
with //
$endgroup$
– Nick Kennedy
8 hours ago
add a comment |
$begingroup$
Jelly, 4 bytes
Ḷd§‘
A dyadic Link accepting two positive integers, x
on the left and n
on the right, which yields a list of positive integers.
Try it online!
How?
Ḷd§‘ - Link: x, n e.g 13, 3
Ḷ - lowered range (x) [0,1,2,3,4,5,6,7,8,9,10,11,12]
d - divmod (n) [[0,0],[0,1],[0,2],[1,0],[1,1],[1,2],[2,0],[2,1],[2,2],[3,0],[3,1],[3,2],[4,0]]
§ - sums [0,1,2,1,2,3,2,3,4,3,4,5,4]
‘ - increment (vectorises) [1,2,3,2,3,4,3,4,5,4,5,6,5]
$endgroup$
2
$begingroup$
Wait... is that divmod? Clever! And I was struggling withp
...
$endgroup$
– Erik the Outgolfer
8 hours ago
add a comment |
$begingroup$
Jelly, 4 bytes
Ḷd§‘
A dyadic Link accepting two positive integers, x
on the left and n
on the right, which yields a list of positive integers.
Try it online!
How?
Ḷd§‘ - Link: x, n e.g 13, 3
Ḷ - lowered range (x) [0,1,2,3,4,5,6,7,8,9,10,11,12]
d - divmod (n) [[0,0],[0,1],[0,2],[1,0],[1,1],[1,2],[2,0],[2,1],[2,2],[3,0],[3,1],[3,2],[4,0]]
§ - sums [0,1,2,1,2,3,2,3,4,3,4,5,4]
‘ - increment (vectorises) [1,2,3,2,3,4,3,4,5,4,5,6,5]
$endgroup$
2
$begingroup$
Wait... is that divmod? Clever! And I was struggling withp
...
$endgroup$
– Erik the Outgolfer
8 hours ago
add a comment |
$begingroup$
Jelly, 4 bytes
Ḷd§‘
A dyadic Link accepting two positive integers, x
on the left and n
on the right, which yields a list of positive integers.
Try it online!
How?
Ḷd§‘ - Link: x, n e.g 13, 3
Ḷ - lowered range (x) [0,1,2,3,4,5,6,7,8,9,10,11,12]
d - divmod (n) [[0,0],[0,1],[0,2],[1,0],[1,1],[1,2],[2,0],[2,1],[2,2],[3,0],[3,1],[3,2],[4,0]]
§ - sums [0,1,2,1,2,3,2,3,4,3,4,5,4]
‘ - increment (vectorises) [1,2,3,2,3,4,3,4,5,4,5,6,5]
$endgroup$
Jelly, 4 bytes
Ḷd§‘
A dyadic Link accepting two positive integers, x
on the left and n
on the right, which yields a list of positive integers.
Try it online!
How?
Ḷd§‘ - Link: x, n e.g 13, 3
Ḷ - lowered range (x) [0,1,2,3,4,5,6,7,8,9,10,11,12]
d - divmod (n) [[0,0],[0,1],[0,2],[1,0],[1,1],[1,2],[2,0],[2,1],[2,2],[3,0],[3,1],[3,2],[4,0]]
§ - sums [0,1,2,1,2,3,2,3,4,3,4,5,4]
‘ - increment (vectorises) [1,2,3,2,3,4,3,4,5,4,5,6,5]
edited 7 hours ago
answered 8 hours ago
Jonathan AllanJonathan Allan
56k538178
56k538178
2
$begingroup$
Wait... is that divmod? Clever! And I was struggling withp
...
$endgroup$
– Erik the Outgolfer
8 hours ago
add a comment |
2
$begingroup$
Wait... is that divmod? Clever! And I was struggling withp
...
$endgroup$
– Erik the Outgolfer
8 hours ago
2
2
$begingroup$
Wait... is that divmod? Clever! And I was struggling with
p
...$endgroup$
– Erik the Outgolfer
8 hours ago
$begingroup$
Wait... is that divmod? Clever! And I was struggling with
p
...$endgroup$
– Erik the Outgolfer
8 hours ago
add a comment |
$begingroup$
R, 33 bytes
function(n,x,z=1:x-1)z%%n+z%/%n+1
Try it online!
Ports Jonathan Allan's Python solution.
R, 36 bytes
function(n,x)outer(1:n,0:x,"+")[1:x]
Try it online!
My original solution; generates an $ntimes x$ matrix with each column as the increments, i.e., $1 ldots n, 2ldots n+1,ldots$, then takes the first $x$ entries (going down the columns).
$endgroup$
add a comment |
$begingroup$
R, 33 bytes
function(n,x,z=1:x-1)z%%n+z%/%n+1
Try it online!
Ports Jonathan Allan's Python solution.
R, 36 bytes
function(n,x)outer(1:n,0:x,"+")[1:x]
Try it online!
My original solution; generates an $ntimes x$ matrix with each column as the increments, i.e., $1 ldots n, 2ldots n+1,ldots$, then takes the first $x$ entries (going down the columns).
$endgroup$
add a comment |
$begingroup$
R, 33 bytes
function(n,x,z=1:x-1)z%%n+z%/%n+1
Try it online!
Ports Jonathan Allan's Python solution.
R, 36 bytes
function(n,x)outer(1:n,0:x,"+")[1:x]
Try it online!
My original solution; generates an $ntimes x$ matrix with each column as the increments, i.e., $1 ldots n, 2ldots n+1,ldots$, then takes the first $x$ entries (going down the columns).
$endgroup$
R, 33 bytes
function(n,x,z=1:x-1)z%%n+z%/%n+1
Try it online!
Ports Jonathan Allan's Python solution.
R, 36 bytes
function(n,x)outer(1:n,0:x,"+")[1:x]
Try it online!
My original solution; generates an $ntimes x$ matrix with each column as the increments, i.e., $1 ldots n, 2ldots n+1,ldots$, then takes the first $x$ entries (going down the columns).
edited 7 hours ago
answered 9 hours ago
GiuseppeGiuseppe
18.6k31358
18.6k31358
add a comment |
add a comment |
$begingroup$
05AB1E, 6 bytes
L<s‰O>
Port of @JonathanAllan's Jelly answer, so make sure to upvote him!
First input is $x$, second input is $n$.
Try it online or verify all test cases.
Explanation:
L # Push a list in the range [1, (implicit) input]
# i.e. 13 → [1,2,3,4,5,6,7,8,9,10,11,12,13]
< # Decrease each by 1 to the range [0, input)
# → [0,1,2,3,4,5,6,7,8,9,10,11,12]
s‰ # Divmod each by the second input
# i.e. 3 → [[0,0],[0,1],[0,2],[1,0],[1,1],[1,2],[2,0],[2,1],[2,2],[3,0],[3,1],[3,2],[4,0]]
O # Sum each pair
# → [0,1,2,1,2,3,2,3,4,3,4,5,4]
> # And increase each by 1
# → [1,2,3,2,3,4,3,4,5,4,5,6,5]
# (after which the result is output implicitly)
My own initial approach was 8 bytes:
LI∍εN¹÷+
First input is $n$, second input is $x$.
Try it online or verify all test cases.
Explanation:
L # Push a list in the range [1, (implicit) input]
# i.e. 3 → [1,2,3]
I∍ # Extend it to the size of the second input
# i.e. 13 → [1,2,3,1,2,3,1,2,3,1,2,3,1]
ε # Map each value to:
N¹÷ # The 0-based index integer-divided by the first input
# → [0,0,0,1,1,1,2,2,2,3,3,3,4]
+ # Add that to the value
# → [1,2,3,2,3,4,3,4,5,4,5,6,5]
# (after which the result is output implicitly)
$endgroup$
add a comment |
$begingroup$
05AB1E, 6 bytes
L<s‰O>
Port of @JonathanAllan's Jelly answer, so make sure to upvote him!
First input is $x$, second input is $n$.
Try it online or verify all test cases.
Explanation:
L # Push a list in the range [1, (implicit) input]
# i.e. 13 → [1,2,3,4,5,6,7,8,9,10,11,12,13]
< # Decrease each by 1 to the range [0, input)
# → [0,1,2,3,4,5,6,7,8,9,10,11,12]
s‰ # Divmod each by the second input
# i.e. 3 → [[0,0],[0,1],[0,2],[1,0],[1,1],[1,2],[2,0],[2,1],[2,2],[3,0],[3,1],[3,2],[4,0]]
O # Sum each pair
# → [0,1,2,1,2,3,2,3,4,3,4,5,4]
> # And increase each by 1
# → [1,2,3,2,3,4,3,4,5,4,5,6,5]
# (after which the result is output implicitly)
My own initial approach was 8 bytes:
LI∍εN¹÷+
First input is $n$, second input is $x$.
Try it online or verify all test cases.
Explanation:
L # Push a list in the range [1, (implicit) input]
# i.e. 3 → [1,2,3]
I∍ # Extend it to the size of the second input
# i.e. 13 → [1,2,3,1,2,3,1,2,3,1,2,3,1]
ε # Map each value to:
N¹÷ # The 0-based index integer-divided by the first input
# → [0,0,0,1,1,1,2,2,2,3,3,3,4]
+ # Add that to the value
# → [1,2,3,2,3,4,3,4,5,4,5,6,5]
# (after which the result is output implicitly)
$endgroup$
add a comment |
$begingroup$
05AB1E, 6 bytes
L<s‰O>
Port of @JonathanAllan's Jelly answer, so make sure to upvote him!
First input is $x$, second input is $n$.
Try it online or verify all test cases.
Explanation:
L # Push a list in the range [1, (implicit) input]
# i.e. 13 → [1,2,3,4,5,6,7,8,9,10,11,12,13]
< # Decrease each by 1 to the range [0, input)
# → [0,1,2,3,4,5,6,7,8,9,10,11,12]
s‰ # Divmod each by the second input
# i.e. 3 → [[0,0],[0,1],[0,2],[1,0],[1,1],[1,2],[2,0],[2,1],[2,2],[3,0],[3,1],[3,2],[4,0]]
O # Sum each pair
# → [0,1,2,1,2,3,2,3,4,3,4,5,4]
> # And increase each by 1
# → [1,2,3,2,3,4,3,4,5,4,5,6,5]
# (after which the result is output implicitly)
My own initial approach was 8 bytes:
LI∍εN¹÷+
First input is $n$, second input is $x$.
Try it online or verify all test cases.
Explanation:
L # Push a list in the range [1, (implicit) input]
# i.e. 3 → [1,2,3]
I∍ # Extend it to the size of the second input
# i.e. 13 → [1,2,3,1,2,3,1,2,3,1,2,3,1]
ε # Map each value to:
N¹÷ # The 0-based index integer-divided by the first input
# → [0,0,0,1,1,1,2,2,2,3,3,3,4]
+ # Add that to the value
# → [1,2,3,2,3,4,3,4,5,4,5,6,5]
# (after which the result is output implicitly)
$endgroup$
05AB1E, 6 bytes
L<s‰O>
Port of @JonathanAllan's Jelly answer, so make sure to upvote him!
First input is $x$, second input is $n$.
Try it online or verify all test cases.
Explanation:
L # Push a list in the range [1, (implicit) input]
# i.e. 13 → [1,2,3,4,5,6,7,8,9,10,11,12,13]
< # Decrease each by 1 to the range [0, input)
# → [0,1,2,3,4,5,6,7,8,9,10,11,12]
s‰ # Divmod each by the second input
# i.e. 3 → [[0,0],[0,1],[0,2],[1,0],[1,1],[1,2],[2,0],[2,1],[2,2],[3,0],[3,1],[3,2],[4,0]]
O # Sum each pair
# → [0,1,2,1,2,3,2,3,4,3,4,5,4]
> # And increase each by 1
# → [1,2,3,2,3,4,3,4,5,4,5,6,5]
# (after which the result is output implicitly)
My own initial approach was 8 bytes:
LI∍εN¹÷+
First input is $n$, second input is $x$.
Try it online or verify all test cases.
Explanation:
L # Push a list in the range [1, (implicit) input]
# i.e. 3 → [1,2,3]
I∍ # Extend it to the size of the second input
# i.e. 13 → [1,2,3,1,2,3,1,2,3,1,2,3,1]
ε # Map each value to:
N¹÷ # The 0-based index integer-divided by the first input
# → [0,0,0,1,1,1,2,2,2,3,3,3,4]
+ # Add that to the value
# → [1,2,3,2,3,4,3,4,5,4,5,6,5]
# (after which the result is output implicitly)
answered 6 hours ago
Kevin CruijssenKevin Cruijssen
45.2k576227
45.2k576227
add a comment |
add a comment |
$begingroup$
Brain-Flak, 100 bytes
(<>)<>([()]<(())(()[()](<>))<>(()<>)(<>)(<>)([()]<(<>[](())[()]<>)>)>)
With comments and formatting:
# Push a zero under the other stack
(<>)<>
# x times
# x - 1
([()]<
# Let 'a' be a counter that starts at n
# Duplicate a and NOT
(())(()[()](<>))
# if a == 0
# Pop truthy
<>
# Reset n to a
(()<>)
# Push 0 to each
(<>)(<>)
# Pop falsy
# Decrement A, add one to the other stack, and duplicate that number under this stack
([()]<
(<>[](())<>)
>)
>)
Try it online!
$endgroup$
$begingroup$
Your "golfed" version doesn't work (and the formatted/commented version on TIO minifies to 100 bytes).
$endgroup$
– Nitrodon
4 hours ago
$begingroup$
@Nitrodon Whoops, not sure how that happened. Fixed now!
$endgroup$
– DJMcMayhem♦
4 hours ago
add a comment |
$begingroup$
Brain-Flak, 100 bytes
(<>)<>([()]<(())(()[()](<>))<>(()<>)(<>)(<>)([()]<(<>[](())[()]<>)>)>)
With comments and formatting:
# Push a zero under the other stack
(<>)<>
# x times
# x - 1
([()]<
# Let 'a' be a counter that starts at n
# Duplicate a and NOT
(())(()[()](<>))
# if a == 0
# Pop truthy
<>
# Reset n to a
(()<>)
# Push 0 to each
(<>)(<>)
# Pop falsy
# Decrement A, add one to the other stack, and duplicate that number under this stack
([()]<
(<>[](())<>)
>)
>)
Try it online!
$endgroup$
$begingroup$
Your "golfed" version doesn't work (and the formatted/commented version on TIO minifies to 100 bytes).
$endgroup$
– Nitrodon
4 hours ago
$begingroup$
@Nitrodon Whoops, not sure how that happened. Fixed now!
$endgroup$
– DJMcMayhem♦
4 hours ago
add a comment |
$begingroup$
Brain-Flak, 100 bytes
(<>)<>([()]<(())(()[()](<>))<>(()<>)(<>)(<>)([()]<(<>[](())[()]<>)>)>)
With comments and formatting:
# Push a zero under the other stack
(<>)<>
# x times
# x - 1
([()]<
# Let 'a' be a counter that starts at n
# Duplicate a and NOT
(())(()[()](<>))
# if a == 0
# Pop truthy
<>
# Reset n to a
(()<>)
# Push 0 to each
(<>)(<>)
# Pop falsy
# Decrement A, add one to the other stack, and duplicate that number under this stack
([()]<
(<>[](())<>)
>)
>)
Try it online!
$endgroup$
Brain-Flak, 100 bytes
(<>)<>([()]<(())(()[()](<>))<>(()<>)(<>)(<>)([()]<(<>[](())[()]<>)>)>)
With comments and formatting:
# Push a zero under the other stack
(<>)<>
# x times
# x - 1
([()]<
# Let 'a' be a counter that starts at n
# Duplicate a and NOT
(())(()[()](<>))
# if a == 0
# Pop truthy
<>
# Reset n to a
(()<>)
# Push 0 to each
(<>)(<>)
# Pop falsy
# Decrement A, add one to the other stack, and duplicate that number under this stack
([()]<
(<>[](())<>)
>)
>)
Try it online!
edited 4 hours ago
answered 8 hours ago
DJMcMayhem♦DJMcMayhem
40.8k12150317
40.8k12150317
$begingroup$
Your "golfed" version doesn't work (and the formatted/commented version on TIO minifies to 100 bytes).
$endgroup$
– Nitrodon
4 hours ago
$begingroup$
@Nitrodon Whoops, not sure how that happened. Fixed now!
$endgroup$
– DJMcMayhem♦
4 hours ago
add a comment |
$begingroup$
Your "golfed" version doesn't work (and the formatted/commented version on TIO minifies to 100 bytes).
$endgroup$
– Nitrodon
4 hours ago
$begingroup$
@Nitrodon Whoops, not sure how that happened. Fixed now!
$endgroup$
– DJMcMayhem♦
4 hours ago
$begingroup$
Your "golfed" version doesn't work (and the formatted/commented version on TIO minifies to 100 bytes).
$endgroup$
– Nitrodon
4 hours ago
$begingroup$
Your "golfed" version doesn't work (and the formatted/commented version on TIO minifies to 100 bytes).
$endgroup$
– Nitrodon
4 hours ago
$begingroup$
@Nitrodon Whoops, not sure how that happened. Fixed now!
$endgroup$
– DJMcMayhem♦
4 hours ago
$begingroup$
@Nitrodon Whoops, not sure how that happened. Fixed now!
$endgroup$
– DJMcMayhem♦
4 hours ago
add a comment |
$begingroup$
Jelly, 5 bytes
+þẎḣ’
Try it online!
$endgroup$
add a comment |
$begingroup$
Jelly, 5 bytes
+þẎḣ’
Try it online!
$endgroup$
add a comment |
$begingroup$
Jelly, 5 bytes
+þẎḣ’
Try it online!
$endgroup$
Jelly, 5 bytes
+þẎḣ’
Try it online!
answered 8 hours ago
Erik the OutgolferErik the Outgolfer
33.6k430106
33.6k430106
add a comment |
add a comment |
$begingroup$
Ruby, 32 bytes
->n,x(0...x).mapi
Try it online!
$endgroup$
add a comment |
$begingroup$
Ruby, 32 bytes
->n,x(0...x).mapi
Try it online!
$endgroup$
add a comment |
$begingroup$
Ruby, 32 bytes
->n,x(0...x).mapi
Try it online!
$endgroup$
Ruby, 32 bytes
->n,x(0...x).mapi
Try it online!
answered 7 hours ago
Value InkValue Ink
8,215731
8,215731
add a comment |
add a comment |
$begingroup$
Japt -m
, 12 7 bytes
Port of Jonathan's Python solution.
Takes x
as the first input.
%VÄ+UzV
Try it
$endgroup$
add a comment |
$begingroup$
Japt -m
, 12 7 bytes
Port of Jonathan's Python solution.
Takes x
as the first input.
%VÄ+UzV
Try it
$endgroup$
add a comment |
$begingroup$
Japt -m
, 12 7 bytes
Port of Jonathan's Python solution.
Takes x
as the first input.
%VÄ+UzV
Try it
$endgroup$
Japt -m
, 12 7 bytes
Port of Jonathan's Python solution.
Takes x
as the first input.
%VÄ+UzV
Try it
edited 7 hours ago
answered 9 hours ago
ShaggyShaggy
19.6k31768
19.6k31768
add a comment |
add a comment |
$begingroup$
Perl 6, 18 bytes
(1..*X+ ^*)[^$_]
Try it online!
Curried function f(x)(n)
.
Explanation
# Anonymous block
X+ # Cartesian product with addition
1..* # of range 1..Inf
^* # and range 0..n
( )[^$_] # First x elements
$endgroup$
add a comment |
$begingroup$
Perl 6, 18 bytes
(1..*X+ ^*)[^$_]
Try it online!
Curried function f(x)(n)
.
Explanation
# Anonymous block
X+ # Cartesian product with addition
1..* # of range 1..Inf
^* # and range 0..n
( )[^$_] # First x elements
$endgroup$
add a comment |
$begingroup$
Perl 6, 18 bytes
(1..*X+ ^*)[^$_]
Try it online!
Curried function f(x)(n)
.
Explanation
# Anonymous block
X+ # Cartesian product with addition
1..* # of range 1..Inf
^* # and range 0..n
( )[^$_] # First x elements
$endgroup$
Perl 6, 18 bytes
(1..*X+ ^*)[^$_]
Try it online!
Curried function f(x)(n)
.
Explanation
# Anonymous block
X+ # Cartesian product with addition
1..* # of range 1..Inf
^* # and range 0..n
( )[^$_] # First x elements
edited 6 hours ago
answered 6 hours ago
nwellnhofnwellnhof
7,70011129
7,70011129
add a comment |
add a comment |
$begingroup$
Perl 5 -na
, 43 bytes
@r=map$_..$_+$F[1]-1,1..$_;say"@r[0..$_-1]"
Try it online!
$endgroup$
add a comment |
$begingroup$
Perl 5 -na
, 43 bytes
@r=map$_..$_+$F[1]-1,1..$_;say"@r[0..$_-1]"
Try it online!
$endgroup$
add a comment |
$begingroup$
Perl 5 -na
, 43 bytes
@r=map$_..$_+$F[1]-1,1..$_;say"@r[0..$_-1]"
Try it online!
$endgroup$
Perl 5 -na
, 43 bytes
@r=map$_..$_+$F[1]-1,1..$_;say"@r[0..$_-1]"
Try it online!
answered 6 hours ago
XcaliXcali
5,920523
5,920523
add a comment |
add a comment |
$begingroup$
Octave, 25 bytes
@(n,x)((1:n)'+(0:x))(1:x)
Anonymous function that inputs numbers n``and
x`, and outputs a row vector.
Try it online!
$endgroup$
add a comment |
$begingroup$
Octave, 25 bytes
@(n,x)((1:n)'+(0:x))(1:x)
Anonymous function that inputs numbers n``and
x`, and outputs a row vector.
Try it online!
$endgroup$
add a comment |
$begingroup$
Octave, 25 bytes
@(n,x)((1:n)'+(0:x))(1:x)
Anonymous function that inputs numbers n``and
x`, and outputs a row vector.
Try it online!
$endgroup$
Octave, 25 bytes
@(n,x)((1:n)'+(0:x))(1:x)
Anonymous function that inputs numbers n``and
x`, and outputs a row vector.
Try it online!
answered 5 hours ago
Luis MendoLuis Mendo
76k889298
76k889298
add a comment |
add a comment |
$begingroup$
MATL, 16 bytes
:i:"tQ]v!1e 2G:)
Try it online!
Explanation:
: % Push [1, 2... n]
i:" ] % For i in [1, x]:
t % Duplicate the first array
Q % Increment each number
v % Concatenate everything into 1 matrix
! % Transpose
1e % Reshape into 1 row
2G % Push x again
:) % And take the first x elements
$endgroup$
1
$begingroup$
10 bytes using broadcasting.
$endgroup$
– Giuseppe
3 hours ago
add a comment |
$begingroup$
MATL, 16 bytes
:i:"tQ]v!1e 2G:)
Try it online!
Explanation:
: % Push [1, 2... n]
i:" ] % For i in [1, x]:
t % Duplicate the first array
Q % Increment each number
v % Concatenate everything into 1 matrix
! % Transpose
1e % Reshape into 1 row
2G % Push x again
:) % And take the first x elements
$endgroup$
1
$begingroup$
10 bytes using broadcasting.
$endgroup$
– Giuseppe
3 hours ago
add a comment |
$begingroup$
MATL, 16 bytes
:i:"tQ]v!1e 2G:)
Try it online!
Explanation:
: % Push [1, 2... n]
i:" ] % For i in [1, x]:
t % Duplicate the first array
Q % Increment each number
v % Concatenate everything into 1 matrix
! % Transpose
1e % Reshape into 1 row
2G % Push x again
:) % And take the first x elements
$endgroup$
MATL, 16 bytes
:i:"tQ]v!1e 2G:)
Try it online!
Explanation:
: % Push [1, 2... n]
i:" ] % For i in [1, x]:
t % Duplicate the first array
Q % Increment each number
v % Concatenate everything into 1 matrix
! % Transpose
1e % Reshape into 1 row
2G % Push x again
:) % And take the first x elements
answered 4 hours ago
DJMcMayhem♦DJMcMayhem
40.8k12150317
40.8k12150317
1
$begingroup$
10 bytes using broadcasting.
$endgroup$
– Giuseppe
3 hours ago
add a comment |
1
$begingroup$
10 bytes using broadcasting.
$endgroup$
– Giuseppe
3 hours ago
1
1
$begingroup$
10 bytes using broadcasting.
$endgroup$
– Giuseppe
3 hours ago
$begingroup$
10 bytes using broadcasting.
$endgroup$
– Giuseppe
3 hours ago
add a comment |
$begingroup$
J, 13 12 bytes
[$[:,1++/&i.
Try it online!
how
We take x
as the left arg, n
as the right. Let's take x = 8
and n = 3
for this example:
+/&i.
: Transform both args by creating integer rangesi.
, that is, the left arg becomes0 1 2 3 4 5 6 7
and the right arg becomes0 1 2
. Now we create an "addition table+/
from those two:0 1 2
1 2 3
2 3 4
3 4 5
4 5 6
5 6 7
6 7 8
7 8 91 +
: Add 1 to every element of this table:1 2 3
2 3 4
3 4 5
4 5 6
5 6 7
6 7 8
7 8 9
8 9 10[: ,
: Flatten it,
:1 2 3 2 3 4 3 4 5 4 5 6 5 6 7 6 7 8 7 8 9 8 9 10
[ $
: Shape it$
so it has the same number of elements as the original, untransformed left arg[
, ie,x
:1 2 3 2 3 4 3 4
$endgroup$
add a comment |
$begingroup$
J, 13 12 bytes
[$[:,1++/&i.
Try it online!
how
We take x
as the left arg, n
as the right. Let's take x = 8
and n = 3
for this example:
+/&i.
: Transform both args by creating integer rangesi.
, that is, the left arg becomes0 1 2 3 4 5 6 7
and the right arg becomes0 1 2
. Now we create an "addition table+/
from those two:0 1 2
1 2 3
2 3 4
3 4 5
4 5 6
5 6 7
6 7 8
7 8 91 +
: Add 1 to every element of this table:1 2 3
2 3 4
3 4 5
4 5 6
5 6 7
6 7 8
7 8 9
8 9 10[: ,
: Flatten it,
:1 2 3 2 3 4 3 4 5 4 5 6 5 6 7 6 7 8 7 8 9 8 9 10
[ $
: Shape it$
so it has the same number of elements as the original, untransformed left arg[
, ie,x
:1 2 3 2 3 4 3 4
$endgroup$
add a comment |
$begingroup$
J, 13 12 bytes
[$[:,1++/&i.
Try it online!
how
We take x
as the left arg, n
as the right. Let's take x = 8
and n = 3
for this example:
+/&i.
: Transform both args by creating integer rangesi.
, that is, the left arg becomes0 1 2 3 4 5 6 7
and the right arg becomes0 1 2
. Now we create an "addition table+/
from those two:0 1 2
1 2 3
2 3 4
3 4 5
4 5 6
5 6 7
6 7 8
7 8 91 +
: Add 1 to every element of this table:1 2 3
2 3 4
3 4 5
4 5 6
5 6 7
6 7 8
7 8 9
8 9 10[: ,
: Flatten it,
:1 2 3 2 3 4 3 4 5 4 5 6 5 6 7 6 7 8 7 8 9 8 9 10
[ $
: Shape it$
so it has the same number of elements as the original, untransformed left arg[
, ie,x
:1 2 3 2 3 4 3 4
$endgroup$
J, 13 12 bytes
[$[:,1++/&i.
Try it online!
how
We take x
as the left arg, n
as the right. Let's take x = 8
and n = 3
for this example:
+/&i.
: Transform both args by creating integer rangesi.
, that is, the left arg becomes0 1 2 3 4 5 6 7
and the right arg becomes0 1 2
. Now we create an "addition table+/
from those two:0 1 2
1 2 3
2 3 4
3 4 5
4 5 6
5 6 7
6 7 8
7 8 91 +
: Add 1 to every element of this table:1 2 3
2 3 4
3 4 5
4 5 6
5 6 7
6 7 8
7 8 9
8 9 10[: ,
: Flatten it,
:1 2 3 2 3 4 3 4 5 4 5 6 5 6 7 6 7 8 7 8 9 8 9 10
[ $
: Shape it$
so it has the same number of elements as the original, untransformed left arg[
, ie,x
:1 2 3 2 3 4 3 4
edited 43 mins ago
answered 7 hours ago
JonahJonah
3,3881019
3,3881019
add a comment |
add a comment |
$begingroup$
Alchemist, 77 bytes
_->In_n+In_x
x+n+0y+0z->a+Out_a+Out_" "+m+y
y+n->n
y+0n->z
z+m+a->z+n
z+0m->a
Try it online!
Increments and outputs a counter n times, then subtracts n-1 before repeating.
$endgroup$
add a comment |
$begingroup$
Alchemist, 77 bytes
_->In_n+In_x
x+n+0y+0z->a+Out_a+Out_" "+m+y
y+n->n
y+0n->z
z+m+a->z+n
z+0m->a
Try it online!
Increments and outputs a counter n times, then subtracts n-1 before repeating.
$endgroup$
add a comment |
$begingroup$
Alchemist, 77 bytes
_->In_n+In_x
x+n+0y+0z->a+Out_a+Out_" "+m+y
y+n->n
y+0n->z
z+m+a->z+n
z+0m->a
Try it online!
Increments and outputs a counter n times, then subtracts n-1 before repeating.
$endgroup$
Alchemist, 77 bytes
_->In_n+In_x
x+n+0y+0z->a+Out_a+Out_" "+m+y
y+n->n
y+0n->z
z+m+a->z+n
z+0m->a
Try it online!
Increments and outputs a counter n times, then subtracts n-1 before repeating.
answered 9 hours ago
NitrodonNitrodon
8,03621024
8,03621024
add a comment |
add a comment |
$begingroup$
Charcoal, 18 bytes
NθFN⊞υ⊕⎇‹ιθι§υ±θIυ
Try it online! Link is to verbose version of code. I had dreams of seeding the list with a zero-indexed range and then slicing it off again but that was actually 2 bytes longer. Explanation:
Nθ Input `n` into variable
N Input `x`
F Loop over implicit range
ι Current index
‹ Less than
θ Variable `n`
⎇ ι Then current index else
θ Variable `n`
± Negated
§υ Cyclically indexed into list
⊕ Incremented
⊞υ Pushed to list
Iυ Cast list to string for implicit output
$endgroup$
add a comment |
$begingroup$
Charcoal, 18 bytes
NθFN⊞υ⊕⎇‹ιθι§υ±θIυ
Try it online! Link is to verbose version of code. I had dreams of seeding the list with a zero-indexed range and then slicing it off again but that was actually 2 bytes longer. Explanation:
Nθ Input `n` into variable
N Input `x`
F Loop over implicit range
ι Current index
‹ Less than
θ Variable `n`
⎇ ι Then current index else
θ Variable `n`
± Negated
§υ Cyclically indexed into list
⊕ Incremented
⊞υ Pushed to list
Iυ Cast list to string for implicit output
$endgroup$
add a comment |
$begingroup$
Charcoal, 18 bytes
NθFN⊞υ⊕⎇‹ιθι§υ±θIυ
Try it online! Link is to verbose version of code. I had dreams of seeding the list with a zero-indexed range and then slicing it off again but that was actually 2 bytes longer. Explanation:
Nθ Input `n` into variable
N Input `x`
F Loop over implicit range
ι Current index
‹ Less than
θ Variable `n`
⎇ ι Then current index else
θ Variable `n`
± Negated
§υ Cyclically indexed into list
⊕ Incremented
⊞υ Pushed to list
Iυ Cast list to string for implicit output
$endgroup$
Charcoal, 18 bytes
NθFN⊞υ⊕⎇‹ιθι§υ±θIυ
Try it online! Link is to verbose version of code. I had dreams of seeding the list with a zero-indexed range and then slicing it off again but that was actually 2 bytes longer. Explanation:
Nθ Input `n` into variable
N Input `x`
F Loop over implicit range
ι Current index
‹ Less than
θ Variable `n`
⎇ ι Then current index else
θ Variable `n`
± Negated
§υ Cyclically indexed into list
⊕ Incremented
⊞υ Pushed to list
Iυ Cast list to string for implicit output
answered 8 hours ago
NeilNeil
84.6k845183
84.6k845183
add a comment |
add a comment |
$begingroup$
APL+WIN, 29 23 bytes
x↑,(0,⍳⌊(x←⎕)÷n)∘.+⍳n←⎕
Prompts for n and x
Try it online! Courtesy of Dyalog Classic
$endgroup$
add a comment |
$begingroup$
APL+WIN, 29 23 bytes
x↑,(0,⍳⌊(x←⎕)÷n)∘.+⍳n←⎕
Prompts for n and x
Try it online! Courtesy of Dyalog Classic
$endgroup$
add a comment |
$begingroup$
APL+WIN, 29 23 bytes
x↑,(0,⍳⌊(x←⎕)÷n)∘.+⍳n←⎕
Prompts for n and x
Try it online! Courtesy of Dyalog Classic
$endgroup$
APL+WIN, 29 23 bytes
x↑,(0,⍳⌊(x←⎕)÷n)∘.+⍳n←⎕
Prompts for n and x
Try it online! Courtesy of Dyalog Classic
edited 6 hours ago
answered 8 hours ago
GrahamGraham
2,75678
2,75678
add a comment |
add a comment |
$begingroup$
JS, 54 bytes
f=(n,x)=>Array.from(Array(x),(_,i)=>i+1-(i/n|0)*(n-1))
Try it online!
New contributor
$endgroup$
add a comment |
$begingroup$
JS, 54 bytes
f=(n,x)=>Array.from(Array(x),(_,i)=>i+1-(i/n|0)*(n-1))
Try it online!
New contributor
$endgroup$
add a comment |
$begingroup$
JS, 54 bytes
f=(n,x)=>Array.from(Array(x),(_,i)=>i+1-(i/n|0)*(n-1))
Try it online!
New contributor
$endgroup$
JS, 54 bytes
f=(n,x)=>Array.from(Array(x),(_,i)=>i+1-(i/n|0)*(n-1))
Try it online!
New contributor
New contributor
answered 6 hours ago
user2657799user2657799
1
1
New contributor
New contributor
add a comment |
add a comment |
$begingroup$
Haskell, 34 33 bytes
n#x=take x$do j<-[1..];[j..j+n-1]
Try it online!
$endgroup$
add a comment |
$begingroup$
Haskell, 34 33 bytes
n#x=take x$do j<-[1..];[j..j+n-1]
Try it online!
$endgroup$
add a comment |
$begingroup$
Haskell, 34 33 bytes
n#x=take x$do j<-[1..];[j..j+n-1]
Try it online!
$endgroup$
Haskell, 34 33 bytes
n#x=take x$do j<-[1..];[j..j+n-1]
Try it online!
edited 6 hours ago
answered 6 hours ago
niminimi
33.2k32491
33.2k32491
add a comment |
add a comment |
$begingroup$
JavaScript, 36 bytes
n=>g=x=>x?[...g(--x),1+x%n+x/n|0]:[]
Try It Online!
$endgroup$
$begingroup$
Usingalert
orprint
instead of return an Array may reduce this to 34 bytes:n=>g=x=>x&&print(g(--x)|1+x%n+x/n)
$endgroup$
– tsh
5 mins ago
add a comment |
$begingroup$
JavaScript, 36 bytes
n=>g=x=>x?[...g(--x),1+x%n+x/n|0]:[]
Try It Online!
$endgroup$
$begingroup$
Usingalert
orprint
instead of return an Array may reduce this to 34 bytes:n=>g=x=>x&&print(g(--x)|1+x%n+x/n)
$endgroup$
– tsh
5 mins ago
add a comment |
$begingroup$
JavaScript, 36 bytes
n=>g=x=>x?[...g(--x),1+x%n+x/n|0]:[]
Try It Online!
$endgroup$
JavaScript, 36 bytes
n=>g=x=>x?[...g(--x),1+x%n+x/n|0]:[]
Try It Online!
edited 6 hours ago
answered 6 hours ago
ShaggyShaggy
19.6k31768
19.6k31768
$begingroup$
Usingalert
orprint
instead of return an Array may reduce this to 34 bytes:n=>g=x=>x&&print(g(--x)|1+x%n+x/n)
$endgroup$
– tsh
5 mins ago
add a comment |
$begingroup$
Usingalert
orprint
instead of return an Array may reduce this to 34 bytes:n=>g=x=>x&&print(g(--x)|1+x%n+x/n)
$endgroup$
– tsh
5 mins ago
$begingroup$
Using
alert
or print
instead of return an Array may reduce this to 34 bytes: n=>g=x=>x&&print(g(--x)|1+x%n+x/n)
$endgroup$
– tsh
5 mins ago
$begingroup$
Using
alert
or print
instead of return an Array may reduce this to 34 bytes: n=>g=x=>x&&print(g(--x)|1+x%n+x/n)
$endgroup$
– tsh
5 mins ago
add a comment |
$begingroup$
Perl 5, 39 bytes
say 1+int($_/$F[1])+$_%$F[1]for 0..$_-1
Try it online!
$endgroup$
add a comment |
$begingroup$
Perl 5, 39 bytes
say 1+int($_/$F[1])+$_%$F[1]for 0..$_-1
Try it online!
$endgroup$
add a comment |
$begingroup$
Perl 5, 39 bytes
say 1+int($_/$F[1])+$_%$F[1]for 0..$_-1
Try it online!
$endgroup$
Perl 5, 39 bytes
say 1+int($_/$F[1])+$_%$F[1]for 0..$_-1
Try it online!
answered 1 hour ago
Kjetil S.Kjetil S.
66925
66925
add a comment |
add a comment |
$begingroup$
C (gcc), 49 44 bytes
Using recursion to save some bytes.
f(n,x)x&&printf("%d ",x%n+x/n+1,f(n,--x));
Try it online!
$endgroup$
add a comment |
$begingroup$
C (gcc), 49 44 bytes
Using recursion to save some bytes.
f(n,x)x&&printf("%d ",x%n+x/n+1,f(n,--x));
Try it online!
$endgroup$
add a comment |
$begingroup$
C (gcc), 49 44 bytes
Using recursion to save some bytes.
f(n,x)x&&printf("%d ",x%n+x/n+1,f(n,--x));
Try it online!
$endgroup$
C (gcc), 49 44 bytes
Using recursion to save some bytes.
f(n,x)x&&printf("%d ",x%n+x/n+1,f(n,--x));
Try it online!
edited 7 mins ago
answered 1 hour ago
ErikFErikF
1,35927
1,35927
add a comment |
add a comment |
If this is an answer to a challenge…
…Be sure to follow the challenge specification. However, please refrain from exploiting obvious loopholes. Answers abusing any of the standard loopholes are considered invalid. If you think a specification is unclear or underspecified, comment on the question instead.
…Try to optimize your score. For instance, answers to code-golf challenges should attempt to be as short as possible. You can always include a readable version of the code in addition to the competitive one.
Explanations of your answer make it more interesting to read and are very much encouraged.…Include a short header which indicates the language(s) of your code and its score, as defined by the challenge.
More generally…
…Please make sure to answer the question and provide sufficient detail.
…Avoid asking for help, clarification or responding to other answers (use comments instead).
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodegolf.stackexchange.com%2fquestions%2f186233%2fincremental-ranges%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown