Chunk + Enumerate a list of digitsOutput all numbers below certain number containing certain digitsMake a numeric list converterOutput the Partial ProductsNested Header ListExpand shorthand increasing integer sequencesSplit a byte array into a bit arrayRuns of Digits in PiFind the numbers and calculate outputFill in an increasing sequence with as many numbers as possibleReorder a Master List Based on a Reordered Subset
Why did IBM make public the PC BIOS source code?
What is the farthest a camera can see?
Are there really no countries that protect Freedom of Speech as the United States does?
How would you translate this? バタコチーズライス
Installing Windows to flash BIOS, then reinstalling Ubuntu
A torrent of foreign terms
The cat ate your input again!
Clarification on Integrability
PhD advisor lost funding, need advice
Beginner in need of a simple explanation of the difference between order of evaluation and precedence/associativity
How do you deal with the emotions of not being the one to find the cause of a bug?
Can the IPA represent all languages' tones?
Corroded Metal vs Magical Armor, should it melt it?
Is there any way to stop a user from creating executables and running them?
Website error: "Walmart can’t use this browser"
Are there any other rule mechanics that could grant Thieves' Cant?
Are differences between uniformly distributed numbers uniformly distributed?
If you know the location of an invisible creature, can you attack it?
Does Nightpack Ambusher's second ability trigger if I cast spells during the end step?
How do I call a 6-digit Australian phone number with a US-based mobile phone?
Do Reform Jews believe in a theistic God?
Word for an event that will likely never happen again
How far did Gandalf and the Balrog drop from the bridge in Moria?
How can God warn people of the upcoming rapture without disrupting society?
Chunk + Enumerate a list of digits
Output all numbers below certain number containing certain digitsMake a numeric list converterOutput the Partial ProductsNested Header ListExpand shorthand increasing integer sequencesSplit a byte array into a bit arrayRuns of Digits in PiFind the numbers and calculate outputFill in an increasing sequence with as many numbers as possibleReorder a Master List Based on a Reordered Subset
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
$begingroup$
I have a list of decimal digits:
4, 4, 4, 7, 7, 9, 9, 9, 9, 2, 2, 2, 4, 4
The list of decimal digits are known as items. We can form "chunks" from these items by grouping together identical and adjacent numbers. I want to assign each chunk a unique number, starting from 1, and increasing by 1 in the order the chunks appear in the original list. So, the output for the given example would look like this:
1, 1, 1, 2, 2, 3, 3, 3, 3, 4, 4, 4, 5, 5
Input format
A list of digits (0-9) separated by a comma, then a space. Encoding: ASCII
Output format
A series of decimal numbers, separated by a delimiter. Your program must always use the same delimiter. The delimiter must be longer than 0 bits. Encoding: ASCII
Standard loopholes apply.
code-golf
$endgroup$
|
show 4 more comments
$begingroup$
I have a list of decimal digits:
4, 4, 4, 7, 7, 9, 9, 9, 9, 2, 2, 2, 4, 4
The list of decimal digits are known as items. We can form "chunks" from these items by grouping together identical and adjacent numbers. I want to assign each chunk a unique number, starting from 1, and increasing by 1 in the order the chunks appear in the original list. So, the output for the given example would look like this:
1, 1, 1, 2, 2, 3, 3, 3, 3, 4, 4, 4, 5, 5
Input format
A list of digits (0-9) separated by a comma, then a space. Encoding: ASCII
Output format
A series of decimal numbers, separated by a delimiter. Your program must always use the same delimiter. The delimiter must be longer than 0 bits. Encoding: ASCII
Standard loopholes apply.
code-golf
$endgroup$
4
$begingroup$
Any particular reason for the strict input and output format?
$endgroup$
– Unrelated String
8 hours ago
2
$begingroup$
@UnrelatedString Hmm, I shall loosen them.
$endgroup$
– noɥʇʎԀʎzɐɹƆ
8 hours ago
$begingroup$
Can the output start from 0 instead?
$endgroup$
– Embodiment of Ignorance
8 hours ago
2
$begingroup$
The IO is still rather strict. Can't you just say "input and output is as a list" and let the site defaults take care of it for you?
$endgroup$
– Jo King
2 hours ago
1
$begingroup$
Can we assume the list is non-empty?
$endgroup$
– Jo King
1 hour ago
|
show 4 more comments
$begingroup$
I have a list of decimal digits:
4, 4, 4, 7, 7, 9, 9, 9, 9, 2, 2, 2, 4, 4
The list of decimal digits are known as items. We can form "chunks" from these items by grouping together identical and adjacent numbers. I want to assign each chunk a unique number, starting from 1, and increasing by 1 in the order the chunks appear in the original list. So, the output for the given example would look like this:
1, 1, 1, 2, 2, 3, 3, 3, 3, 4, 4, 4, 5, 5
Input format
A list of digits (0-9) separated by a comma, then a space. Encoding: ASCII
Output format
A series of decimal numbers, separated by a delimiter. Your program must always use the same delimiter. The delimiter must be longer than 0 bits. Encoding: ASCII
Standard loopholes apply.
code-golf
$endgroup$
I have a list of decimal digits:
4, 4, 4, 7, 7, 9, 9, 9, 9, 2, 2, 2, 4, 4
The list of decimal digits are known as items. We can form "chunks" from these items by grouping together identical and adjacent numbers. I want to assign each chunk a unique number, starting from 1, and increasing by 1 in the order the chunks appear in the original list. So, the output for the given example would look like this:
1, 1, 1, 2, 2, 3, 3, 3, 3, 4, 4, 4, 5, 5
Input format
A list of digits (0-9) separated by a comma, then a space. Encoding: ASCII
Output format
A series of decimal numbers, separated by a delimiter. Your program must always use the same delimiter. The delimiter must be longer than 0 bits. Encoding: ASCII
Standard loopholes apply.
code-golf
code-golf
edited 8 hours ago
noɥʇʎԀʎzɐɹƆ
asked 8 hours ago
noɥʇʎԀʎzɐɹƆnoɥʇʎԀʎzɐɹƆ
4981 gold badge9 silver badges28 bronze badges
4981 gold badge9 silver badges28 bronze badges
4
$begingroup$
Any particular reason for the strict input and output format?
$endgroup$
– Unrelated String
8 hours ago
2
$begingroup$
@UnrelatedString Hmm, I shall loosen them.
$endgroup$
– noɥʇʎԀʎzɐɹƆ
8 hours ago
$begingroup$
Can the output start from 0 instead?
$endgroup$
– Embodiment of Ignorance
8 hours ago
2
$begingroup$
The IO is still rather strict. Can't you just say "input and output is as a list" and let the site defaults take care of it for you?
$endgroup$
– Jo King
2 hours ago
1
$begingroup$
Can we assume the list is non-empty?
$endgroup$
– Jo King
1 hour ago
|
show 4 more comments
4
$begingroup$
Any particular reason for the strict input and output format?
$endgroup$
– Unrelated String
8 hours ago
2
$begingroup$
@UnrelatedString Hmm, I shall loosen them.
$endgroup$
– noɥʇʎԀʎzɐɹƆ
8 hours ago
$begingroup$
Can the output start from 0 instead?
$endgroup$
– Embodiment of Ignorance
8 hours ago
2
$begingroup$
The IO is still rather strict. Can't you just say "input and output is as a list" and let the site defaults take care of it for you?
$endgroup$
– Jo King
2 hours ago
1
$begingroup$
Can we assume the list is non-empty?
$endgroup$
– Jo King
1 hour ago
4
4
$begingroup$
Any particular reason for the strict input and output format?
$endgroup$
– Unrelated String
8 hours ago
$begingroup$
Any particular reason for the strict input and output format?
$endgroup$
– Unrelated String
8 hours ago
2
2
$begingroup$
@UnrelatedString Hmm, I shall loosen them.
$endgroup$
– noɥʇʎԀʎzɐɹƆ
8 hours ago
$begingroup$
@UnrelatedString Hmm, I shall loosen them.
$endgroup$
– noɥʇʎԀʎzɐɹƆ
8 hours ago
$begingroup$
Can the output start from 0 instead?
$endgroup$
– Embodiment of Ignorance
8 hours ago
$begingroup$
Can the output start from 0 instead?
$endgroup$
– Embodiment of Ignorance
8 hours ago
2
2
$begingroup$
The IO is still rather strict. Can't you just say "input and output is as a list" and let the site defaults take care of it for you?
$endgroup$
– Jo King
2 hours ago
$begingroup$
The IO is still rather strict. Can't you just say "input and output is as a list" and let the site defaults take care of it for you?
$endgroup$
– Jo King
2 hours ago
1
1
$begingroup$
Can we assume the list is non-empty?
$endgroup$
– Jo King
1 hour ago
$begingroup$
Can we assume the list is non-empty?
$endgroup$
– Jo King
1 hour ago
|
show 4 more comments
19 Answers
19
active
oldest
votes
$begingroup$
APL (dzaima/APL), 7 bytesSBCS
Anonymous tacit prefix function. Prints space-separated.
+1,2≠/
Try it online!
2≠/
pair-wise inequality
1,
prepend 1
+
cumulative sum
$endgroup$
add a comment |
$begingroup$
Python 2, 44 bytes
l=input()
n=0
for i in l:n+=i!=l;l=i;print n
Try it online!
$endgroup$
add a comment |
$begingroup$
JavaScript (ES6), 30 bytes
a=>a.map(p=n=>i+=p!=(p=n),i=0)
Try it online!
$endgroup$
add a comment |
$begingroup$
Jelly, 6 5 bytes
ŒɠµJx
Try it online!
Saved one byte thanks to UnrelatedString!
Inputs and outputs as array's (with opening/closing brackets)
How it works
ŒɠµJx - Main link, takes one argument: [7, 7, 5, 5, 5, 1]
Œɠ - Get the lengths of consecutive elements: [2, 3, 1]
µ - Call these lengths A
J - range(length(A)) [1, 2, 3]
x - Repeat each element by the corresponding value in A: [1, 1, 2, 2, 2, 3]
$endgroup$
$begingroup$
5 bytes
$endgroup$
– Unrelated String
8 hours ago
1
$begingroup$
@UnrelatedString all these new-fangled atoms!
$endgroup$
– caird coinheringaahing
8 hours ago
add a comment |
$begingroup$
Perl 5, 27 bytes
s/d/$i+=$&!=$l;$l=$&;$i/ge
Try it online!
$endgroup$
add a comment |
$begingroup$
Octave / MATLAB, 25 bytes
@(x)cumsum([1 ~~diff(x)])
Try it online!
$endgroup$
add a comment |
$begingroup$
Wolfram Language (Mathematica), 29 bytes
Join@@(i=1;0#+i++&/@Split@#)&
Try it online!
$endgroup$
add a comment |
$begingroup$
Jelly, 5 bytes
nƝÄŻ‘
Try it online!
I initially aimed for a 4-byter (the same program but without the Ż
) but then quickly realized that a 1 had to be prepended every time due to an oversight... Even though there is another 5-byter in Jelly, I'll actually keep this because it uses a different method.
For each pair of neighbouring items of the input list $L$, test if $L_ine L_i+1, forall 1le i<|L|$ and save these results in a list. Then take the cumulative sum of this list and increment them by 1 to match the chunk indexing system. TL;DR. Whenever we encounter different neighbouring items, we increment the chunk index by 1.
$endgroup$
add a comment |
$begingroup$
Python 3.8 (pre-release), 41 bytes
lambda l,n=0:[n:=n+(l!=(l:=x))for x in l]
Try it online!
Praise the magic walrus :=
of assignment expressions.
Python 2, 42 bytes
n=0
for x in input():n+=x!=id;id=x;print n
Try it online!
$endgroup$
$begingroup$
Hmm, how long would this be in Pyth?
$endgroup$
– noɥʇʎԀʎzɐɹƆ
5 hours ago
add a comment |
$begingroup$
Haskell, 40 bytes
f(a:t)=1:map(+sum[1|a/=t!!0])(f t)
f e=e
Try it online!
$endgroup$
add a comment |
$begingroup$
Japt v2.0a0, 9 bytes
£T±A¦(A=X
Try it
$endgroup$
add a comment |
$begingroup$
Add++, 23 bytes
D,f,@*,BGd€bL$bLRz€¦XBF
Try it online!
How it works
D,f,@*, - Define a function, f, that takes one argument: [7 7 5 5 5 1]
BG - Group neighbouring elements together: [[[7 7] [5 5 5] [1]]]
d - Duplicate: [[[7 7] [5 5 5] [1]] [[7 7] [5 5 5] [1]]]
€bL - Get the length of each: [[[7 7] [5 5 5] [1]] [2 3 1]]
$bLR - Length, then range of length: [[2 3 1] [1 2 3]]
z - Zip together: [[2 1] [3 2] [1 3]]
€¦X - Reduce each by repetition: [[1 1] [2 2 2] [3]]
BF - Flatten: [1 1 2 2 2 3]
- Due to the * in the function definition,
return the whole stack: [1 1 2 2 2 3]
$endgroup$
add a comment |
$begingroup$
Japt, 8 7 bytes
ä¦Ug)åÄ
Try it
$endgroup$
add a comment |
$begingroup$
Retina 0.8.2, 34 bytes
bd+b(?<=(b(3|(d+))D*)*)
$#3
Try it online! Explanation:
bd+b
Match each number in turn.
(?<=(...)*)
Start looking backwards for as many matches as possible. (The next entries will be in right-to-left order as that's how lookbehind works.)
D*
Skip the separators.
(3|(d+))
Try to match the same number as last time, but failing that, just match any number, but remember that we had to match a new number.
b
Ensure the whole number is matched.
$#3
Count the number of new numbers.
$endgroup$
add a comment |
$begingroup$
05AB1E, 5 bytes
¥Ā.¥>
Try it online!
$endgroup$
add a comment |
$begingroup$
Stax, 10 bytes
▓ª2ªmD?Ä╧╖
Run and debug it
The output uses space as a delimiter. The input follows the precise specifications using commas as separators, and now enclosing braces.
$endgroup$
add a comment |
$begingroup$
C (gcc), 62 61 bytes
This is one of the few entries I've done where a complete program is shorter than a function submission!
On the first pass, I don't care about the previous value, so I get to rely on the fact that argv
is a pointer to somewhere and is extremely unlikely to be between [0..9]!
s;main(i,j)for(;~scanf("%d,",&i);j=i)printf("%d ",s+=j!=i);
Try it online!
$endgroup$
add a comment |
$begingroup$
Perl 6, 21 bytes
+<<[+] $,
Try it online!
Anonymous code block that takes a list and returns a list. This works by comparing whether each pair of adjacent elements are not equal, than taking the cumulative sum of the list.
$endgroup$
add a comment |
$begingroup$
Haskell, 46 43 bytes
scanl(+)1.map fromEnum.(zipWith(/=)=<<tail)
Try it online!
Anonymous pointfree function that takes a list and returns a list
$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%2f189932%2fchunk-enumerate-a-list-of-digits%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
19 Answers
19
active
oldest
votes
19 Answers
19
active
oldest
votes
active
oldest
votes
active
oldest
votes
$begingroup$
APL (dzaima/APL), 7 bytesSBCS
Anonymous tacit prefix function. Prints space-separated.
+1,2≠/
Try it online!
2≠/
pair-wise inequality
1,
prepend 1
+
cumulative sum
$endgroup$
add a comment |
$begingroup$
APL (dzaima/APL), 7 bytesSBCS
Anonymous tacit prefix function. Prints space-separated.
+1,2≠/
Try it online!
2≠/
pair-wise inequality
1,
prepend 1
+
cumulative sum
$endgroup$
add a comment |
$begingroup$
APL (dzaima/APL), 7 bytesSBCS
Anonymous tacit prefix function. Prints space-separated.
+1,2≠/
Try it online!
2≠/
pair-wise inequality
1,
prepend 1
+
cumulative sum
$endgroup$
APL (dzaima/APL), 7 bytesSBCS
Anonymous tacit prefix function. Prints space-separated.
+1,2≠/
Try it online!
2≠/
pair-wise inequality
1,
prepend 1
+
cumulative sum
answered 7 hours ago
AdámAdám
29.5k2 gold badges79 silver badges212 bronze badges
29.5k2 gold badges79 silver badges212 bronze badges
add a comment |
add a comment |
$begingroup$
Python 2, 44 bytes
l=input()
n=0
for i in l:n+=i!=l;l=i;print n
Try it online!
$endgroup$
add a comment |
$begingroup$
Python 2, 44 bytes
l=input()
n=0
for i in l:n+=i!=l;l=i;print n
Try it online!
$endgroup$
add a comment |
$begingroup$
Python 2, 44 bytes
l=input()
n=0
for i in l:n+=i!=l;l=i;print n
Try it online!
$endgroup$
Python 2, 44 bytes
l=input()
n=0
for i in l:n+=i!=l;l=i;print n
Try it online!
edited 7 hours ago
answered 7 hours ago
Erik the OutgolferErik the Outgolfer
35.5k4 gold badges30 silver badges110 bronze badges
35.5k4 gold badges30 silver badges110 bronze badges
add a comment |
add a comment |
$begingroup$
JavaScript (ES6), 30 bytes
a=>a.map(p=n=>i+=p!=(p=n),i=0)
Try it online!
$endgroup$
add a comment |
$begingroup$
JavaScript (ES6), 30 bytes
a=>a.map(p=n=>i+=p!=(p=n),i=0)
Try it online!
$endgroup$
add a comment |
$begingroup$
JavaScript (ES6), 30 bytes
a=>a.map(p=n=>i+=p!=(p=n),i=0)
Try it online!
$endgroup$
JavaScript (ES6), 30 bytes
a=>a.map(p=n=>i+=p!=(p=n),i=0)
Try it online!
answered 8 hours ago
ArnauldArnauld
89.8k7 gold badges104 silver badges366 bronze badges
89.8k7 gold badges104 silver badges366 bronze badges
add a comment |
add a comment |
$begingroup$
Jelly, 6 5 bytes
ŒɠµJx
Try it online!
Saved one byte thanks to UnrelatedString!
Inputs and outputs as array's (with opening/closing brackets)
How it works
ŒɠµJx - Main link, takes one argument: [7, 7, 5, 5, 5, 1]
Œɠ - Get the lengths of consecutive elements: [2, 3, 1]
µ - Call these lengths A
J - range(length(A)) [1, 2, 3]
x - Repeat each element by the corresponding value in A: [1, 1, 2, 2, 2, 3]
$endgroup$
$begingroup$
5 bytes
$endgroup$
– Unrelated String
8 hours ago
1
$begingroup$
@UnrelatedString all these new-fangled atoms!
$endgroup$
– caird coinheringaahing
8 hours ago
add a comment |
$begingroup$
Jelly, 6 5 bytes
ŒɠµJx
Try it online!
Saved one byte thanks to UnrelatedString!
Inputs and outputs as array's (with opening/closing brackets)
How it works
ŒɠµJx - Main link, takes one argument: [7, 7, 5, 5, 5, 1]
Œɠ - Get the lengths of consecutive elements: [2, 3, 1]
µ - Call these lengths A
J - range(length(A)) [1, 2, 3]
x - Repeat each element by the corresponding value in A: [1, 1, 2, 2, 2, 3]
$endgroup$
$begingroup$
5 bytes
$endgroup$
– Unrelated String
8 hours ago
1
$begingroup$
@UnrelatedString all these new-fangled atoms!
$endgroup$
– caird coinheringaahing
8 hours ago
add a comment |
$begingroup$
Jelly, 6 5 bytes
ŒɠµJx
Try it online!
Saved one byte thanks to UnrelatedString!
Inputs and outputs as array's (with opening/closing brackets)
How it works
ŒɠµJx - Main link, takes one argument: [7, 7, 5, 5, 5, 1]
Œɠ - Get the lengths of consecutive elements: [2, 3, 1]
µ - Call these lengths A
J - range(length(A)) [1, 2, 3]
x - Repeat each element by the corresponding value in A: [1, 1, 2, 2, 2, 3]
$endgroup$
Jelly, 6 5 bytes
ŒɠµJx
Try it online!
Saved one byte thanks to UnrelatedString!
Inputs and outputs as array's (with opening/closing brackets)
How it works
ŒɠµJx - Main link, takes one argument: [7, 7, 5, 5, 5, 1]
Œɠ - Get the lengths of consecutive elements: [2, 3, 1]
µ - Call these lengths A
J - range(length(A)) [1, 2, 3]
x - Repeat each element by the corresponding value in A: [1, 1, 2, 2, 2, 3]
edited 8 hours ago
answered 8 hours ago
caird coinheringaahingcaird coinheringaahing
7,6363 gold badges31 silver badges86 bronze badges
7,6363 gold badges31 silver badges86 bronze badges
$begingroup$
5 bytes
$endgroup$
– Unrelated String
8 hours ago
1
$begingroup$
@UnrelatedString all these new-fangled atoms!
$endgroup$
– caird coinheringaahing
8 hours ago
add a comment |
$begingroup$
5 bytes
$endgroup$
– Unrelated String
8 hours ago
1
$begingroup$
@UnrelatedString all these new-fangled atoms!
$endgroup$
– caird coinheringaahing
8 hours ago
$begingroup$
5 bytes
$endgroup$
– Unrelated String
8 hours ago
$begingroup$
5 bytes
$endgroup$
– Unrelated String
8 hours ago
1
1
$begingroup$
@UnrelatedString all these new-fangled atoms!
$endgroup$
– caird coinheringaahing
8 hours ago
$begingroup$
@UnrelatedString all these new-fangled atoms!
$endgroup$
– caird coinheringaahing
8 hours ago
add a comment |
$begingroup$
Perl 5, 27 bytes
s/d/$i+=$&!=$l;$l=$&;$i/ge
Try it online!
$endgroup$
add a comment |
$begingroup$
Perl 5, 27 bytes
s/d/$i+=$&!=$l;$l=$&;$i/ge
Try it online!
$endgroup$
add a comment |
$begingroup$
Perl 5, 27 bytes
s/d/$i+=$&!=$l;$l=$&;$i/ge
Try it online!
$endgroup$
Perl 5, 27 bytes
s/d/$i+=$&!=$l;$l=$&;$i/ge
Try it online!
answered 7 hours ago
Kjetil S.Kjetil S.
7072 silver badges5 bronze badges
7072 silver badges5 bronze badges
add a comment |
add a comment |
$begingroup$
Octave / MATLAB, 25 bytes
@(x)cumsum([1 ~~diff(x)])
Try it online!
$endgroup$
add a comment |
$begingroup$
Octave / MATLAB, 25 bytes
@(x)cumsum([1 ~~diff(x)])
Try it online!
$endgroup$
add a comment |
$begingroup$
Octave / MATLAB, 25 bytes
@(x)cumsum([1 ~~diff(x)])
Try it online!
$endgroup$
Octave / MATLAB, 25 bytes
@(x)cumsum([1 ~~diff(x)])
Try it online!
answered 7 hours ago
Luis MendoLuis Mendo
77.7k8 gold badges95 silver badges303 bronze badges
77.7k8 gold badges95 silver badges303 bronze badges
add a comment |
add a comment |
$begingroup$
Wolfram Language (Mathematica), 29 bytes
Join@@(i=1;0#+i++&/@Split@#)&
Try it online!
$endgroup$
add a comment |
$begingroup$
Wolfram Language (Mathematica), 29 bytes
Join@@(i=1;0#+i++&/@Split@#)&
Try it online!
$endgroup$
add a comment |
$begingroup$
Wolfram Language (Mathematica), 29 bytes
Join@@(i=1;0#+i++&/@Split@#)&
Try it online!
$endgroup$
Wolfram Language (Mathematica), 29 bytes
Join@@(i=1;0#+i++&/@Split@#)&
Try it online!
answered 6 hours ago
RomanRoman
6151 silver badge6 bronze badges
6151 silver badge6 bronze badges
add a comment |
add a comment |
$begingroup$
Jelly, 5 bytes
nƝÄŻ‘
Try it online!
I initially aimed for a 4-byter (the same program but without the Ż
) but then quickly realized that a 1 had to be prepended every time due to an oversight... Even though there is another 5-byter in Jelly, I'll actually keep this because it uses a different method.
For each pair of neighbouring items of the input list $L$, test if $L_ine L_i+1, forall 1le i<|L|$ and save these results in a list. Then take the cumulative sum of this list and increment them by 1 to match the chunk indexing system. TL;DR. Whenever we encounter different neighbouring items, we increment the chunk index by 1.
$endgroup$
add a comment |
$begingroup$
Jelly, 5 bytes
nƝÄŻ‘
Try it online!
I initially aimed for a 4-byter (the same program but without the Ż
) but then quickly realized that a 1 had to be prepended every time due to an oversight... Even though there is another 5-byter in Jelly, I'll actually keep this because it uses a different method.
For each pair of neighbouring items of the input list $L$, test if $L_ine L_i+1, forall 1le i<|L|$ and save these results in a list. Then take the cumulative sum of this list and increment them by 1 to match the chunk indexing system. TL;DR. Whenever we encounter different neighbouring items, we increment the chunk index by 1.
$endgroup$
add a comment |
$begingroup$
Jelly, 5 bytes
nƝÄŻ‘
Try it online!
I initially aimed for a 4-byter (the same program but without the Ż
) but then quickly realized that a 1 had to be prepended every time due to an oversight... Even though there is another 5-byter in Jelly, I'll actually keep this because it uses a different method.
For each pair of neighbouring items of the input list $L$, test if $L_ine L_i+1, forall 1le i<|L|$ and save these results in a list. Then take the cumulative sum of this list and increment them by 1 to match the chunk indexing system. TL;DR. Whenever we encounter different neighbouring items, we increment the chunk index by 1.
$endgroup$
Jelly, 5 bytes
nƝÄŻ‘
Try it online!
I initially aimed for a 4-byter (the same program but without the Ż
) but then quickly realized that a 1 had to be prepended every time due to an oversight... Even though there is another 5-byter in Jelly, I'll actually keep this because it uses a different method.
For each pair of neighbouring items of the input list $L$, test if $L_ine L_i+1, forall 1le i<|L|$ and save these results in a list. Then take the cumulative sum of this list and increment them by 1 to match the chunk indexing system. TL;DR. Whenever we encounter different neighbouring items, we increment the chunk index by 1.
edited 6 hours ago
answered 6 hours ago
Mr. XcoderMr. Xcoder
33.4k7 gold badges62 silver badges204 bronze badges
33.4k7 gold badges62 silver badges204 bronze badges
add a comment |
add a comment |
$begingroup$
Python 3.8 (pre-release), 41 bytes
lambda l,n=0:[n:=n+(l!=(l:=x))for x in l]
Try it online!
Praise the magic walrus :=
of assignment expressions.
Python 2, 42 bytes
n=0
for x in input():n+=x!=id;id=x;print n
Try it online!
$endgroup$
$begingroup$
Hmm, how long would this be in Pyth?
$endgroup$
– noɥʇʎԀʎzɐɹƆ
5 hours ago
add a comment |
$begingroup$
Python 3.8 (pre-release), 41 bytes
lambda l,n=0:[n:=n+(l!=(l:=x))for x in l]
Try it online!
Praise the magic walrus :=
of assignment expressions.
Python 2, 42 bytes
n=0
for x in input():n+=x!=id;id=x;print n
Try it online!
$endgroup$
$begingroup$
Hmm, how long would this be in Pyth?
$endgroup$
– noɥʇʎԀʎzɐɹƆ
5 hours ago
add a comment |
$begingroup$
Python 3.8 (pre-release), 41 bytes
lambda l,n=0:[n:=n+(l!=(l:=x))for x in l]
Try it online!
Praise the magic walrus :=
of assignment expressions.
Python 2, 42 bytes
n=0
for x in input():n+=x!=id;id=x;print n
Try it online!
$endgroup$
Python 3.8 (pre-release), 41 bytes
lambda l,n=0:[n:=n+(l!=(l:=x))for x in l]
Try it online!
Praise the magic walrus :=
of assignment expressions.
Python 2, 42 bytes
n=0
for x in input():n+=x!=id;id=x;print n
Try it online!
answered 5 hours ago
xnorxnor
97.8k19 gold badges201 silver badges461 bronze badges
97.8k19 gold badges201 silver badges461 bronze badges
$begingroup$
Hmm, how long would this be in Pyth?
$endgroup$
– noɥʇʎԀʎzɐɹƆ
5 hours ago
add a comment |
$begingroup$
Hmm, how long would this be in Pyth?
$endgroup$
– noɥʇʎԀʎzɐɹƆ
5 hours ago
$begingroup$
Hmm, how long would this be in Pyth?
$endgroup$
– noɥʇʎԀʎzɐɹƆ
5 hours ago
$begingroup$
Hmm, how long would this be in Pyth?
$endgroup$
– noɥʇʎԀʎzɐɹƆ
5 hours ago
add a comment |
$begingroup$
Haskell, 40 bytes
f(a:t)=1:map(+sum[1|a/=t!!0])(f t)
f e=e
Try it online!
$endgroup$
add a comment |
$begingroup$
Haskell, 40 bytes
f(a:t)=1:map(+sum[1|a/=t!!0])(f t)
f e=e
Try it online!
$endgroup$
add a comment |
$begingroup$
Haskell, 40 bytes
f(a:t)=1:map(+sum[1|a/=t!!0])(f t)
f e=e
Try it online!
$endgroup$
Haskell, 40 bytes
f(a:t)=1:map(+sum[1|a/=t!!0])(f t)
f e=e
Try it online!
answered 3 hours ago
xnorxnor
97.8k19 gold badges201 silver badges461 bronze badges
97.8k19 gold badges201 silver badges461 bronze badges
add a comment |
add a comment |
$begingroup$
Japt v2.0a0, 9 bytes
£T±A¦(A=X
Try it
$endgroup$
add a comment |
$begingroup$
Japt v2.0a0, 9 bytes
£T±A¦(A=X
Try it
$endgroup$
add a comment |
$begingroup$
Japt v2.0a0, 9 bytes
£T±A¦(A=X
Try it
$endgroup$
Japt v2.0a0, 9 bytes
£T±A¦(A=X
Try it
answered 8 hours ago
Embodiment of IgnoranceEmbodiment of Ignorance
4,8861 silver badge30 bronze badges
4,8861 silver badge30 bronze badges
add a comment |
add a comment |
$begingroup$
Add++, 23 bytes
D,f,@*,BGd€bL$bLRz€¦XBF
Try it online!
How it works
D,f,@*, - Define a function, f, that takes one argument: [7 7 5 5 5 1]
BG - Group neighbouring elements together: [[[7 7] [5 5 5] [1]]]
d - Duplicate: [[[7 7] [5 5 5] [1]] [[7 7] [5 5 5] [1]]]
€bL - Get the length of each: [[[7 7] [5 5 5] [1]] [2 3 1]]
$bLR - Length, then range of length: [[2 3 1] [1 2 3]]
z - Zip together: [[2 1] [3 2] [1 3]]
€¦X - Reduce each by repetition: [[1 1] [2 2 2] [3]]
BF - Flatten: [1 1 2 2 2 3]
- Due to the * in the function definition,
return the whole stack: [1 1 2 2 2 3]
$endgroup$
add a comment |
$begingroup$
Add++, 23 bytes
D,f,@*,BGd€bL$bLRz€¦XBF
Try it online!
How it works
D,f,@*, - Define a function, f, that takes one argument: [7 7 5 5 5 1]
BG - Group neighbouring elements together: [[[7 7] [5 5 5] [1]]]
d - Duplicate: [[[7 7] [5 5 5] [1]] [[7 7] [5 5 5] [1]]]
€bL - Get the length of each: [[[7 7] [5 5 5] [1]] [2 3 1]]
$bLR - Length, then range of length: [[2 3 1] [1 2 3]]
z - Zip together: [[2 1] [3 2] [1 3]]
€¦X - Reduce each by repetition: [[1 1] [2 2 2] [3]]
BF - Flatten: [1 1 2 2 2 3]
- Due to the * in the function definition,
return the whole stack: [1 1 2 2 2 3]
$endgroup$
add a comment |
$begingroup$
Add++, 23 bytes
D,f,@*,BGd€bL$bLRz€¦XBF
Try it online!
How it works
D,f,@*, - Define a function, f, that takes one argument: [7 7 5 5 5 1]
BG - Group neighbouring elements together: [[[7 7] [5 5 5] [1]]]
d - Duplicate: [[[7 7] [5 5 5] [1]] [[7 7] [5 5 5] [1]]]
€bL - Get the length of each: [[[7 7] [5 5 5] [1]] [2 3 1]]
$bLR - Length, then range of length: [[2 3 1] [1 2 3]]
z - Zip together: [[2 1] [3 2] [1 3]]
€¦X - Reduce each by repetition: [[1 1] [2 2 2] [3]]
BF - Flatten: [1 1 2 2 2 3]
- Due to the * in the function definition,
return the whole stack: [1 1 2 2 2 3]
$endgroup$
Add++, 23 bytes
D,f,@*,BGd€bL$bLRz€¦XBF
Try it online!
How it works
D,f,@*, - Define a function, f, that takes one argument: [7 7 5 5 5 1]
BG - Group neighbouring elements together: [[[7 7] [5 5 5] [1]]]
d - Duplicate: [[[7 7] [5 5 5] [1]] [[7 7] [5 5 5] [1]]]
€bL - Get the length of each: [[[7 7] [5 5 5] [1]] [2 3 1]]
$bLR - Length, then range of length: [[2 3 1] [1 2 3]]
z - Zip together: [[2 1] [3 2] [1 3]]
€¦X - Reduce each by repetition: [[1 1] [2 2 2] [3]]
BF - Flatten: [1 1 2 2 2 3]
- Due to the * in the function definition,
return the whole stack: [1 1 2 2 2 3]
answered 7 hours ago
caird coinheringaahingcaird coinheringaahing
7,6363 gold badges31 silver badges86 bronze badges
7,6363 gold badges31 silver badges86 bronze badges
add a comment |
add a comment |
$begingroup$
Japt, 8 7 bytes
ä¦Ug)åÄ
Try it
$endgroup$
add a comment |
$begingroup$
Japt, 8 7 bytes
ä¦Ug)åÄ
Try it
$endgroup$
add a comment |
$begingroup$
Japt, 8 7 bytes
ä¦Ug)åÄ
Try it
$endgroup$
Japt, 8 7 bytes
ä¦Ug)åÄ
Try it
edited 7 hours ago
answered 7 hours ago
ShaggyShaggy
20.9k3 gold badges20 silver badges71 bronze badges
20.9k3 gold badges20 silver badges71 bronze badges
add a comment |
add a comment |
$begingroup$
Retina 0.8.2, 34 bytes
bd+b(?<=(b(3|(d+))D*)*)
$#3
Try it online! Explanation:
bd+b
Match each number in turn.
(?<=(...)*)
Start looking backwards for as many matches as possible. (The next entries will be in right-to-left order as that's how lookbehind works.)
D*
Skip the separators.
(3|(d+))
Try to match the same number as last time, but failing that, just match any number, but remember that we had to match a new number.
b
Ensure the whole number is matched.
$#3
Count the number of new numbers.
$endgroup$
add a comment |
$begingroup$
Retina 0.8.2, 34 bytes
bd+b(?<=(b(3|(d+))D*)*)
$#3
Try it online! Explanation:
bd+b
Match each number in turn.
(?<=(...)*)
Start looking backwards for as many matches as possible. (The next entries will be in right-to-left order as that's how lookbehind works.)
D*
Skip the separators.
(3|(d+))
Try to match the same number as last time, but failing that, just match any number, but remember that we had to match a new number.
b
Ensure the whole number is matched.
$#3
Count the number of new numbers.
$endgroup$
add a comment |
$begingroup$
Retina 0.8.2, 34 bytes
bd+b(?<=(b(3|(d+))D*)*)
$#3
Try it online! Explanation:
bd+b
Match each number in turn.
(?<=(...)*)
Start looking backwards for as many matches as possible. (The next entries will be in right-to-left order as that's how lookbehind works.)
D*
Skip the separators.
(3|(d+))
Try to match the same number as last time, but failing that, just match any number, but remember that we had to match a new number.
b
Ensure the whole number is matched.
$#3
Count the number of new numbers.
$endgroup$
Retina 0.8.2, 34 bytes
bd+b(?<=(b(3|(d+))D*)*)
$#3
Try it online! Explanation:
bd+b
Match each number in turn.
(?<=(...)*)
Start looking backwards for as many matches as possible. (The next entries will be in right-to-left order as that's how lookbehind works.)
D*
Skip the separators.
(3|(d+))
Try to match the same number as last time, but failing that, just match any number, but remember that we had to match a new number.
b
Ensure the whole number is matched.
$#3
Count the number of new numbers.
answered 6 hours ago
NeilNeil
87.1k8 gold badges46 silver badges183 bronze badges
87.1k8 gold badges46 silver badges183 bronze badges
add a comment |
add a comment |
$begingroup$
05AB1E, 5 bytes
¥Ā.¥>
Try it online!
$endgroup$
add a comment |
$begingroup$
05AB1E, 5 bytes
¥Ā.¥>
Try it online!
$endgroup$
add a comment |
$begingroup$
05AB1E, 5 bytes
¥Ā.¥>
Try it online!
$endgroup$
05AB1E, 5 bytes
¥Ā.¥>
Try it online!
answered 6 hours ago
Mr. XcoderMr. Xcoder
33.4k7 gold badges62 silver badges204 bronze badges
33.4k7 gold badges62 silver badges204 bronze badges
add a comment |
add a comment |
$begingroup$
Stax, 10 bytes
▓ª2ªmD?Ä╧╖
Run and debug it
The output uses space as a delimiter. The input follows the precise specifications using commas as separators, and now enclosing braces.
$endgroup$
add a comment |
$begingroup$
Stax, 10 bytes
▓ª2ªmD?Ä╧╖
Run and debug it
The output uses space as a delimiter. The input follows the precise specifications using commas as separators, and now enclosing braces.
$endgroup$
add a comment |
$begingroup$
Stax, 10 bytes
▓ª2ªmD?Ä╧╖
Run and debug it
The output uses space as a delimiter. The input follows the precise specifications using commas as separators, and now enclosing braces.
$endgroup$
Stax, 10 bytes
▓ª2ªmD?Ä╧╖
Run and debug it
The output uses space as a delimiter. The input follows the precise specifications using commas as separators, and now enclosing braces.
edited 5 hours ago
answered 8 hours ago
recursiverecursive
7,77115 silver badges30 bronze badges
7,77115 silver badges30 bronze badges
add a comment |
add a comment |
$begingroup$
C (gcc), 62 61 bytes
This is one of the few entries I've done where a complete program is shorter than a function submission!
On the first pass, I don't care about the previous value, so I get to rely on the fact that argv
is a pointer to somewhere and is extremely unlikely to be between [0..9]!
s;main(i,j)for(;~scanf("%d,",&i);j=i)printf("%d ",s+=j!=i);
Try it online!
$endgroup$
add a comment |
$begingroup$
C (gcc), 62 61 bytes
This is one of the few entries I've done where a complete program is shorter than a function submission!
On the first pass, I don't care about the previous value, so I get to rely on the fact that argv
is a pointer to somewhere and is extremely unlikely to be between [0..9]!
s;main(i,j)for(;~scanf("%d,",&i);j=i)printf("%d ",s+=j!=i);
Try it online!
$endgroup$
add a comment |
$begingroup$
C (gcc), 62 61 bytes
This is one of the few entries I've done where a complete program is shorter than a function submission!
On the first pass, I don't care about the previous value, so I get to rely on the fact that argv
is a pointer to somewhere and is extremely unlikely to be between [0..9]!
s;main(i,j)for(;~scanf("%d,",&i);j=i)printf("%d ",s+=j!=i);
Try it online!
$endgroup$
C (gcc), 62 61 bytes
This is one of the few entries I've done where a complete program is shorter than a function submission!
On the first pass, I don't care about the previous value, so I get to rely on the fact that argv
is a pointer to somewhere and is extremely unlikely to be between [0..9]!
s;main(i,j)for(;~scanf("%d,",&i);j=i)printf("%d ",s+=j!=i);
Try it online!
edited 2 hours ago
answered 2 hours ago
ErikFErikF
1,6192 silver badges7 bronze badges
1,6192 silver badges7 bronze badges
add a comment |
add a comment |
$begingroup$
Perl 6, 21 bytes
+<<[+] $,
Try it online!
Anonymous code block that takes a list and returns a list. This works by comparing whether each pair of adjacent elements are not equal, than taking the cumulative sum of the list.
$endgroup$
add a comment |
$begingroup$
Perl 6, 21 bytes
+<<[+] $,
Try it online!
Anonymous code block that takes a list and returns a list. This works by comparing whether each pair of adjacent elements are not equal, than taking the cumulative sum of the list.
$endgroup$
add a comment |
$begingroup$
Perl 6, 21 bytes
+<<[+] $,
Try it online!
Anonymous code block that takes a list and returns a list. This works by comparing whether each pair of adjacent elements are not equal, than taking the cumulative sum of the list.
$endgroup$
Perl 6, 21 bytes
+<<[+] $,
Try it online!
Anonymous code block that takes a list and returns a list. This works by comparing whether each pair of adjacent elements are not equal, than taking the cumulative sum of the list.
answered 1 hour ago
Jo KingJo King
30.6k3 gold badges71 silver badges138 bronze badges
30.6k3 gold badges71 silver badges138 bronze badges
add a comment |
add a comment |
$begingroup$
Haskell, 46 43 bytes
scanl(+)1.map fromEnum.(zipWith(/=)=<<tail)
Try it online!
Anonymous pointfree function that takes a list and returns a list
$endgroup$
add a comment |
$begingroup$
Haskell, 46 43 bytes
scanl(+)1.map fromEnum.(zipWith(/=)=<<tail)
Try it online!
Anonymous pointfree function that takes a list and returns a list
$endgroup$
add a comment |
$begingroup$
Haskell, 46 43 bytes
scanl(+)1.map fromEnum.(zipWith(/=)=<<tail)
Try it online!
Anonymous pointfree function that takes a list and returns a list
$endgroup$
Haskell, 46 43 bytes
scanl(+)1.map fromEnum.(zipWith(/=)=<<tail)
Try it online!
Anonymous pointfree function that takes a list and returns a list
edited 1 hour ago
answered 4 hours ago
Jo KingJo King
30.6k3 gold badges71 silver badges138 bronze badges
30.6k3 gold badges71 silver badges138 bronze badges
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%2f189932%2fchunk-enumerate-a-list-of-digits%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
4
$begingroup$
Any particular reason for the strict input and output format?
$endgroup$
– Unrelated String
8 hours ago
2
$begingroup$
@UnrelatedString Hmm, I shall loosen them.
$endgroup$
– noɥʇʎԀʎzɐɹƆ
8 hours ago
$begingroup$
Can the output start from 0 instead?
$endgroup$
– Embodiment of Ignorance
8 hours ago
2
$begingroup$
The IO is still rather strict. Can't you just say "input and output is as a list" and let the site defaults take care of it for you?
$endgroup$
– Jo King
2 hours ago
1
$begingroup$
Can we assume the list is non-empty?
$endgroup$
– Jo King
1 hour ago