Enumerate each series of identical numbers in-place
Given a list of strictly positive integers, go through each distinct number and replace all occurrences of it with successive indices (zero or one based) of a new series.
Examples
→
/
[42]
→ [0]
/[1]
[7,7,7]
→ [0,1,2]
/[1,2,3]
[10,20,30]
→ [0,0,0]
/[1,1,1]
[5,12,10,12,12,10]
→ [0,0,0,1,2,1]
/[1,1,1,2,3,2]
[2,7,1,8,2,8,1,8,2,8]
→ [0,0,0,0,1,1,1,2,2,3]
/[1,1,1,1,2,2,2,3,3,4]
[3,1,4,1,5,9,2,6,5,3,5,9]
→ [0,0,0,1,0,0,0,0,1,1,2,1]
/[1,1,1,2,1,1,1,1,2,2,3,2]
code-golf number integer sorting substitution
add a comment |
Given a list of strictly positive integers, go through each distinct number and replace all occurrences of it with successive indices (zero or one based) of a new series.
Examples
→
/
[42]
→ [0]
/[1]
[7,7,7]
→ [0,1,2]
/[1,2,3]
[10,20,30]
→ [0,0,0]
/[1,1,1]
[5,12,10,12,12,10]
→ [0,0,0,1,2,1]
/[1,1,1,2,3,2]
[2,7,1,8,2,8,1,8,2,8]
→ [0,0,0,0,1,1,1,2,2,3]
/[1,1,1,1,2,2,2,3,3,4]
[3,1,4,1,5,9,2,6,5,3,5,9]
→ [0,0,0,1,0,0,0,0,1,1,2,1]
/[1,1,1,2,1,1,1,1,2,2,3,2]
code-golf number integer sorting substitution
2
So basically the number of times it has appeared the sequence so far?
– Jo King
2 days ago
1
@JoKing Yes, that's another way to state it, but "so far" implies zero-based, and "until and including this" implies one-based. I wanted to keep the choice.
– Adám
2 days ago
add a comment |
Given a list of strictly positive integers, go through each distinct number and replace all occurrences of it with successive indices (zero or one based) of a new series.
Examples
→
/
[42]
→ [0]
/[1]
[7,7,7]
→ [0,1,2]
/[1,2,3]
[10,20,30]
→ [0,0,0]
/[1,1,1]
[5,12,10,12,12,10]
→ [0,0,0,1,2,1]
/[1,1,1,2,3,2]
[2,7,1,8,2,8,1,8,2,8]
→ [0,0,0,0,1,1,1,2,2,3]
/[1,1,1,1,2,2,2,3,3,4]
[3,1,4,1,5,9,2,6,5,3,5,9]
→ [0,0,0,1,0,0,0,0,1,1,2,1]
/[1,1,1,2,1,1,1,1,2,2,3,2]
code-golf number integer sorting substitution
Given a list of strictly positive integers, go through each distinct number and replace all occurrences of it with successive indices (zero or one based) of a new series.
Examples
→
/
[42]
→ [0]
/[1]
[7,7,7]
→ [0,1,2]
/[1,2,3]
[10,20,30]
→ [0,0,0]
/[1,1,1]
[5,12,10,12,12,10]
→ [0,0,0,1,2,1]
/[1,1,1,2,3,2]
[2,7,1,8,2,8,1,8,2,8]
→ [0,0,0,0,1,1,1,2,2,3]
/[1,1,1,1,2,2,2,3,3,4]
[3,1,4,1,5,9,2,6,5,3,5,9]
→ [0,0,0,1,0,0,0,0,1,1,2,1]
/[1,1,1,2,1,1,1,1,2,2,3,2]
code-golf number integer sorting substitution
code-golf number integer sorting substitution
asked 2 days ago
AdámAdám
29k269192
29k269192
2
So basically the number of times it has appeared the sequence so far?
– Jo King
2 days ago
1
@JoKing Yes, that's another way to state it, but "so far" implies zero-based, and "until and including this" implies one-based. I wanted to keep the choice.
– Adám
2 days ago
add a comment |
2
So basically the number of times it has appeared the sequence so far?
– Jo King
2 days ago
1
@JoKing Yes, that's another way to state it, but "so far" implies zero-based, and "until and including this" implies one-based. I wanted to keep the choice.
– Adám
2 days ago
2
2
So basically the number of times it has appeared the sequence so far?
– Jo King
2 days ago
So basically the number of times it has appeared the sequence so far?
– Jo King
2 days ago
1
1
@JoKing Yes, that's another way to state it, but "so far" implies zero-based, and "until and including this" implies one-based. I wanted to keep the choice.
– Adám
2 days ago
@JoKing Yes, that's another way to state it, but "so far" implies zero-based, and "until and including this" implies one-based. I wanted to keep the choice.
– Adám
2 days ago
add a comment |
30 Answers
30
active
oldest
votes
JavaScript (ES6), 26 bytes
1-indexed.
a=>a.map(o=x=>o[x]=-~o[x])
Try it online!
Commented
a => // a = input array
a.map(o = // assign the callback function of map() to the variable o, so that
// we have an object that can be used to store the counters
x => // for each value x in a:
o[x] = -~o[x] // increment o[x] and yield the result
// the '-~' syntax allows to go from undefined to 1
) // end of map()
1
I have no idea how that works, but it sure looks elegant.
– Adám
2 days ago
I've not seen-~
before - that is an absolute gem.
– DaveMongoose
2 days ago
Alternatively, it's possible to usea
to store the values, but it's required to-
/~
the index so no byte is saved.
– user202729
2 days ago
@DaveMongoose Tips for golfing in JavaScript
– user202729
2 days ago
1
@DaveMongoose-~
is actually a commonly used alternative to+1
(since it has different precedence) in many languages
– ASCII-only
yesterday
|
show 2 more comments
MATL, 4 bytes
&=Rs
This solution is 1-based
Try it out at MATL Online!
Explanation
Uses [1,2,3,2]
as an example
# Implicitly grab the input array of length N
#
# [1,2,3,2]
#
&= # Create an N x N boolean matrix by performing an element-wise comparison
# between the original array and its transpose:
#
# 1 2 3 2
# -------
# 1 | 1 0 0 0
# 2 | 0 1 0 1
# 3 | 0 0 1 0
# 2 | 0 1 0 1
#
R # Take the upper-triangular portion of this matrix (sets below-diagonal to 0)
#
# [1 0 0 0
# 0 1 0 1
# 0 0 1 0
# 0 0 0 1]
#
s # Compute the sum down the columns
#
# [1,1,1,2]
#
# Implicitly display the result
1
ah, I knew there was an old problem that made me think of something similar, it's Unique is Cheap, and the MATL solution there is one character different!
– Giuseppe
2 days ago
add a comment |
APL (Dyalog Unicode), 7 bytes
Many, many thanks to H.PWiz, Adám and dzaima for all their help in debugging and correcting this.
+/¨⊢=,
Try it online!
Explanation
The 10-byte non-tacit version will be easier to explain first
{+/¨⍵=,⍵}
{ } A user-defined function, a dfn
,⍵ The list of prefixes of our input list ⍵
(⍵ more generally means the right argument of a dfn)
is 'scan' which both gives us our prefixes
and applies ,/ over each prefix, which keeps each prefix as-is
⍵= Checks each element of ⍵ against its corresponding prefix
This checks each prefix for occurrences of the last element of that prefix
This gives us several lists of 0s and 1s
+/¨ This sums over each list of 0s and 1s to give us the enumeration we are looking for
The tacit version does three things
- First, it removes the instance of
⍵
used in,⍵
as,
on the right by itself can implicitly figure out that it's supposed to operate on the right argument. - Second, for
⍵=
, we replace the⍵
with⊢
, which stands for right argument - Third, now that we have no explicit arguments (in this case,
⍵
), we can remove the braces{}
as tacit functions do not use them
add a comment |
J, 7 bytes
1#.]=]
Try it online!
1-indexed.
Explanation:
] all the prefixes (filled with zeros, but there won't be any 0s in the input):
] 5 12 10 12 12 10
5 0 0 0 0 0
5 12 0 0 0 0
5 12 10 0 0 0
5 12 10 12 0 0
5 12 10 12 12 0
5 12 10 12 12 10
]= is each number from the input equal to the prefix:
(]=]) 5 12 10 12 12 10
1 0 0 0 0 0
0 1 0 0 0 0
0 0 1 0 0 0
0 1 0 1 0 0
0 1 0 1 1 0
0 0 1 0 0 1
1#. sum each row:
(1#.]=]) 5 12 10 12 12 10
1 1 1 2 3 2
K (oK), 11 bytes
{+/'x=',x}
Try it online!
1
Heh, you're happy that I made the data strictly positive…
– Adám
2 days ago
@Adám Yes, otherwise I'd need to box the prefixes :)
– Galen Ivanov
2 days ago
add a comment |
Python 2, 48 bytes
lambda a:[a[:i].count(v)for i,v in enumerate(a)]
Try it online!
add a comment |
05AB1E, 4 bytes
ηε¤¢
Try it online!
or as a Test Suite
Explanation
ηε # apply to each prefix of the input list
¤¢ # count occurrences of the last element
add a comment |
C# (Visual C# Interactive Compiler), 44 bytes
x=>x.Select((y,i)=>x.Take(i).Count(z=>z==y))
Try it online!
22 bytes
– LiefdeWen
2 days ago
You have the inversed of the challenge right now..[7,7,7]
should output[0,1,2]
, and not[0,0,0]
.
– Kevin Cruijssen
2 days ago
1
@KevinCruijssen - Thanks :) Looks like I misread things, it should be fixed now.
– dana
2 days ago
add a comment |
AWK, 15
{print a[$1]++}
Try it online!
The above does zero-based indexing. If you prefer one-based indexing, its a simple change:
{print ++a[$1]}
Try it online!
add a comment |
Python 2, 47 43 bytes
f=lambda a:a and f(a[:-1])+[a.count(a[-1])]
Try it online!
A recursive 'one-based' solution.
add a comment |
Jelly, 4 bytes
ċṪ$Ƥ
Try it online!
For each prefix of the input list, it counts the number of occurrences of its last element in itself.
Alternatively the old-school;ċ"
is also 4.
– Jonathan Allan
2 days ago
add a comment |
Ruby, 35 bytes
->a{f=Hash.new 0;a.map{|v|f[v]+=1}}
It's pretty mundane, unfortunately - build a hash that stores the total for each entry encountered so far.
Some other, fun options that unfortunately weren't quite short enough:
->a{a.dup.map{a.count a.pop}.reverse} # 37
->a{i=-1;a.map{|v|a[0..i+=1].count v}} # 38
add a comment |
Perl 6, 15 bytes
*>>.&{%.{$_}++}
Try it online!
You can move the ++
to before the %
for a one based index.
Explanation:
*>>.&{ } # Map the input to
% # An anonymous hash
.{$_} # The current element indexed
++ # Incremented
add a comment |
R, 41 bytes
function(x)diag(diffinv(outer(x,x,"==")))
Try it online!
Oddly, returning a zero-based index is shorter in R.
Once again Giuseppe, your superior knowledge of R has beaten me. I had a decently ingenious method at 60 bytes, but alas, it wasn't enough!
– Sumner18
2 days ago
@Sumner18 post it anyway! I always learn a lot from other peoples' approaches, and getting feedback is the fastest way to learn!
– Giuseppe
2 days ago
thanks for the encouragement! I've posted mine now and am always open to suggestions for improvement!
– Sumner18
2 days ago
add a comment |
Java (JDK), 76 bytes
a->{for(int l=a.length,i,c;l-->0;a[l]=c)for(c=i=0;i<l;)c+=a[l]==a[i++]?1:0;}
Try it online!
Credits
- -2 bytes thanks to Kevin Cruijssen
1
-2 bytes by changingfor(c=0,i=l;i-->0;)c+=a[l]==a[i]?1:0;
tofor(c=i=0;i<l;)c+=a[l]==a[i++]?1:0;
.
– Kevin Cruijssen
2 days ago
add a comment |
R, 62 43 bytes
x=z=scan();for(i in x)z[y]=1:sum(y<-x==i);z
-19 bytes thanks to Giuseppe, by removing which, and table, and only slight changes to the implementation
Original
x=z=scan();for(i in names(r<-table(x)))z[which(x==i)]=1:r[i];z
I can't compete with Giuseppe's knowledge, so my submission is somewhat longer than his, but using my basic knowledge, I felt that this solution was rather ingenious.
r<-table(x)
counts the number of times each number appears and stores it in r, for future reference
names()
gets the values of each unique entry in the table, and we iterate over these names with a for loop.
The remaining portion checks which entries are equal to the iterations and stores a sequence of values (from 1 to the number of entries of the iteration)
Try it online!
you can remove thewhich()
to save 7 bytes.
– Giuseppe
2 days ago
Your use of1:r[i]
gave me the idea to just removetable()
entirely:x=z=scan();for(i in x)z[y]=1:sum(y<-x==i);z
is 43 bytes! This is a nice approach!
– Giuseppe
2 days ago
add a comment |
Haskell, 44 bytes
(#)
x#(y:z)=sum[1|a<-x,a==y]:(y:x)#z
_#e=e
Try it online!
Explanation
Traverses the list from left to right keeping the list x
of visited elements, initially :
For every encounter of a y
count all equal elements in the list x
.
1
A bit longer but maybe nevertheless interesting:(#(0*));(x:r)#g=g x:r# y->0^abs(y-x)+g y;e#g=e
Try it online!
– Laikoni
12 hours ago
@Laikoni: How did you even come up with that, you should totally post it!
– BMO
12 hours ago
1
Done: codegolf.stackexchange.com/a/178629/56433
– Laikoni
11 hours ago
add a comment |
Ruby, 34 bytes
->a{r=;a.map{|x|(r<<x).count x}}
Try it online!
I can't believe I tried->a{i=-1;a.map{|v|a[0..i+=1].count v}}
and didn't think of just building a new array, lol. Nice work.
– DaveMongoose
yesterday
add a comment |
bash, 37 bytes or 24 bytes
f()(for x;{ r+=$[a[x]++] ;};echo $r)
TIO
if valid, there is also this variation, as suggested by DigitalTrauma
for x;{ echo $[a[x]++];}
TIO
1
Pass the list as command line args - tio.run/##S0oszvj/Py2/SKHCuporNTkjX0ElOjG6IlZbO5ar9v///8b/… - only 24 bytes.
– Digital Trauma
2 days ago
@DigitalTrauma, thanks however i don't know if it broke the rules. also as it was asked to replace list and maybe should be something like tio.run/…
– Nahuel Fouilleul
yesterday
2
@NahuelFouilleul It's fine, full programs are allowed too, and that's a valid method of inputting/outputting a list (IMO)
– ASCII-only
yesterday
add a comment |
Haskell, 47 46 bytes
(#(*0))
(x:r)#g=g x:r# y->0^(y-x)^2+g y
e#g=e
Try it online!
A different approach than BMO's answer which turned out a bit longer. (And kindly borrows their nice test suit.)
The idea is to iterate over the input list and keep track of the number of times each element has occurred by updating a function g
. Ungolfed:
f (const 0)
f g (x:r) = g x : f ( y -> if x==y then 1 + g y else g y) r
f g =
Two interesting golfing opportunities arose. First for the initial value of g
, a constant function which disregards its argument and returns 0
:
const 0 -- the idiomatic way
(_->0) -- can be shorter if parenthesis are not needed
min 0 -- only works as inputs are guaranteed to be non-negative
(0*) -- obvious in hindsight but took me a while to think of
And secondly an expression over variables x
and y
which yields 1
if x
equals y
and 0
otherwise:
if x==y then 1else 0 -- yes you don't need a space after the 1
fromEnum$x==y -- works because Bool is an instance of Enum
sum[1|x==y] -- uses that the sum of an empty list is zero
0^abs(x-y) -- uses that 0^0=1 and 0^x=0 for any positive x
0^(x-y)^2 -- Thanks to Christian Sievers!
There still might be shorter ways. Anyone got an idea?
1
You can use0^(x-y)^2
.
– Christian Sievers
8 hours ago
add a comment |
Retina 0.8.2, 30 bytes
b(d+)b(?<=(b1b.*?)+)
$#2
Try it online! Link includes test cases. 1-indexed. Explanation: The first part of the regex matches each integer in the list in turn. The lookbehind's group matches each occurrence of that integer on that line up to and including the current integer. The integer is then substituted with the number of matches.
add a comment |
Batch, 61 bytes
@setlocal
@for %%n in (%*)do @set/ac=c%%n+=1&call echo %%c%%
1-indexed. Because variable substitution happens before parsing, the set/a
command ends up incrementing the variable name given by concatenating the letter c
with the integer from the list (numeric variables default to zero in Batch). The result is then copied to another integer for ease of output (more precisely, it saves a byte).
add a comment |
awk (46 bytes)
{delete(a);for(i=1;i<=NF;i++)$i=a[$i]++;print}
TIO
I think{for(;i++<NF;)$i=a[$i]++;print}
works.delete(a);
is only needed for the test suite, no?
– Dennis♦
6 hours ago
add a comment |
Tcl, 48 bytes
proc C L {lmap n $L {dict g [dict inc D $n] $n}}
Try it online!
add a comment |
Japt, 8 bytes
£¯YÄ è¶X
Try it here
£¯YÄ è¶X
:Implicit input of array U
£ :Map each X at 0-based index Y
¯ : Slice U to index
YÄ : Y+1
è : Count the elements
¶X : Equal to X
add a comment |
Haxe, 58 bytes
l->{var x=[0=>0];l.map(e->++x[(x[e]==null?x[e]=0:0)+e]);};
(Requires arrow functions, so 4.0+)
var x=[0=>0]
declares a new IntMap
, with 0
as its only key (since the question say inputs are strictly positive). Unfortunately most targets throw when adding null
to a number, hence the explicit check to make sure each key is in the map before incrementing.
Also a cheeky rip off based on the JS answer:
Haxe (JS target), 41 bytes
l->{var x=[0=>0];l.map(e->x[e]=-~x[e]);};
Try both online
add a comment |
GO 121 Bytes (Not included new lines and tabs)
func cg(a int) int{
var m = make(map[int]int)
var r = make(int, len(a))
for i,v := range a{
r[i] = m[v]
m[v]++
}
return r
}
Accepts integer array and returns integer array.
New contributor
3
Welcome to PPCG. Rare to see Go represented here. You do need to count necessary newlines, but you also have a lot of spaces that can be removed, and you can also shortencg
toc
. I recommend using TIO to generate the main part of your post: Try it online!
– Adám
yesterday
add a comment |
C++,137 bytes
//v is input , ov is output ; //example to populate v: vector v{7,8,7};
vector<int> v,ov(v.size());map<int,int>m;transform(begin(v),end(v),begin(ov),[&m](int i){!m.count(i)?m[i]=0:m[i]+=1;return m[i];});
New contributor
I'm not sure about C++, but can't you remove the newlines to save 2 bytes?
– Stephen
2 days ago
1
I don't know C++ either, but what is this? It doesn't look like a function, and I don't see how you take input?
– Jo King
yesterday
You can't take input via a predefined variable, otherwise this becomes a snippet. Submissions have to be a full program or a function
– Jo King
11 hours ago
add a comment |
Python 2, 44 bytes
a=
for x in input():print a.count(x);a+=x,
Try it online!
The first thing I wrote tied Chas Brown's 43, so here's a different solution that's one byte longer.
add a comment |
Reticular, 17 bytes
L[ddc@c~]~*$qlbo;
Try it online!
The input list of integers is assumed to already be pushed to the stack. Run the following code to test input:
'2''7''1''8''2''8''1''8''2''8'lbL[ddc@c~]~*$qlbo;
Explanation
The pop instruction c
which is supposed to: pop a list from the stack, pop the last element from that list and push this element to the stack. However, if the list occurs at more than 1 place in the stack (if it has been duplicated for example), all of the duplicated lists in the stack will also have their last element popped contrary to what one might think will happen. This is fortunately used in our favor in this puzzle.
L # Push length of input list to the stack.
[ ] # Push the following function:
dd # Duplicate top of stack twice.
c # Pop the list at top of the stack,
pop the last element in the list (which will pop the element of every list!)
and finally push it to the stack.
@c # Pop two items at the top of the stack (list + last element in that list).
then push the number of occurrences of that element in the list.
~ # Swap top two items in the stack (so that the popped list is on top again).
~ # Swap top two items in the stack.
* # Call the above function the same number of times as length of the input list.
$ # Remove the item at the top of the stack (which by now is an empty list).
q # Reverse stack.
lb # Push size of stack and put that many items from the stack into a list.
o; # Output resulting list and exit.
add a comment |
SNOBOL4 (CSNOBOL4), 63 bytes
T =TABLE()
R I =INPUT :F(END)
T<I> =OUTPUT =T<I> + 1 :(R)
END
Try it online!
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
return StackExchange.using("mathjaxEditing", function () {
StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix) {
StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["\$", "\$"]]);
});
});
}, "mathjax-editing");
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%2f178500%2fenumerate-each-series-of-identical-numbers-in-place%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
30 Answers
30
active
oldest
votes
30 Answers
30
active
oldest
votes
active
oldest
votes
active
oldest
votes
JavaScript (ES6), 26 bytes
1-indexed.
a=>a.map(o=x=>o[x]=-~o[x])
Try it online!
Commented
a => // a = input array
a.map(o = // assign the callback function of map() to the variable o, so that
// we have an object that can be used to store the counters
x => // for each value x in a:
o[x] = -~o[x] // increment o[x] and yield the result
// the '-~' syntax allows to go from undefined to 1
) // end of map()
1
I have no idea how that works, but it sure looks elegant.
– Adám
2 days ago
I've not seen-~
before - that is an absolute gem.
– DaveMongoose
2 days ago
Alternatively, it's possible to usea
to store the values, but it's required to-
/~
the index so no byte is saved.
– user202729
2 days ago
@DaveMongoose Tips for golfing in JavaScript
– user202729
2 days ago
1
@DaveMongoose-~
is actually a commonly used alternative to+1
(since it has different precedence) in many languages
– ASCII-only
yesterday
|
show 2 more comments
JavaScript (ES6), 26 bytes
1-indexed.
a=>a.map(o=x=>o[x]=-~o[x])
Try it online!
Commented
a => // a = input array
a.map(o = // assign the callback function of map() to the variable o, so that
// we have an object that can be used to store the counters
x => // for each value x in a:
o[x] = -~o[x] // increment o[x] and yield the result
// the '-~' syntax allows to go from undefined to 1
) // end of map()
1
I have no idea how that works, but it sure looks elegant.
– Adám
2 days ago
I've not seen-~
before - that is an absolute gem.
– DaveMongoose
2 days ago
Alternatively, it's possible to usea
to store the values, but it's required to-
/~
the index so no byte is saved.
– user202729
2 days ago
@DaveMongoose Tips for golfing in JavaScript
– user202729
2 days ago
1
@DaveMongoose-~
is actually a commonly used alternative to+1
(since it has different precedence) in many languages
– ASCII-only
yesterday
|
show 2 more comments
JavaScript (ES6), 26 bytes
1-indexed.
a=>a.map(o=x=>o[x]=-~o[x])
Try it online!
Commented
a => // a = input array
a.map(o = // assign the callback function of map() to the variable o, so that
// we have an object that can be used to store the counters
x => // for each value x in a:
o[x] = -~o[x] // increment o[x] and yield the result
// the '-~' syntax allows to go from undefined to 1
) // end of map()
JavaScript (ES6), 26 bytes
1-indexed.
a=>a.map(o=x=>o[x]=-~o[x])
Try it online!
Commented
a => // a = input array
a.map(o = // assign the callback function of map() to the variable o, so that
// we have an object that can be used to store the counters
x => // for each value x in a:
o[x] = -~o[x] // increment o[x] and yield the result
// the '-~' syntax allows to go from undefined to 1
) // end of map()
edited 2 days ago
answered 2 days ago
ArnauldArnauld
72.9k689307
72.9k689307
1
I have no idea how that works, but it sure looks elegant.
– Adám
2 days ago
I've not seen-~
before - that is an absolute gem.
– DaveMongoose
2 days ago
Alternatively, it's possible to usea
to store the values, but it's required to-
/~
the index so no byte is saved.
– user202729
2 days ago
@DaveMongoose Tips for golfing in JavaScript
– user202729
2 days ago
1
@DaveMongoose-~
is actually a commonly used alternative to+1
(since it has different precedence) in many languages
– ASCII-only
yesterday
|
show 2 more comments
1
I have no idea how that works, but it sure looks elegant.
– Adám
2 days ago
I've not seen-~
before - that is an absolute gem.
– DaveMongoose
2 days ago
Alternatively, it's possible to usea
to store the values, but it's required to-
/~
the index so no byte is saved.
– user202729
2 days ago
@DaveMongoose Tips for golfing in JavaScript
– user202729
2 days ago
1
@DaveMongoose-~
is actually a commonly used alternative to+1
(since it has different precedence) in many languages
– ASCII-only
yesterday
1
1
I have no idea how that works, but it sure looks elegant.
– Adám
2 days ago
I have no idea how that works, but it sure looks elegant.
– Adám
2 days ago
I've not seen
-~
before - that is an absolute gem.– DaveMongoose
2 days ago
I've not seen
-~
before - that is an absolute gem.– DaveMongoose
2 days ago
Alternatively, it's possible to use
a
to store the values, but it's required to -
/~
the index so no byte is saved.– user202729
2 days ago
Alternatively, it's possible to use
a
to store the values, but it's required to -
/~
the index so no byte is saved.– user202729
2 days ago
@DaveMongoose Tips for golfing in JavaScript
– user202729
2 days ago
@DaveMongoose Tips for golfing in JavaScript
– user202729
2 days ago
1
1
@DaveMongoose
-~
is actually a commonly used alternative to +1
(since it has different precedence) in many languages– ASCII-only
yesterday
@DaveMongoose
-~
is actually a commonly used alternative to +1
(since it has different precedence) in many languages– ASCII-only
yesterday
|
show 2 more comments
MATL, 4 bytes
&=Rs
This solution is 1-based
Try it out at MATL Online!
Explanation
Uses [1,2,3,2]
as an example
# Implicitly grab the input array of length N
#
# [1,2,3,2]
#
&= # Create an N x N boolean matrix by performing an element-wise comparison
# between the original array and its transpose:
#
# 1 2 3 2
# -------
# 1 | 1 0 0 0
# 2 | 0 1 0 1
# 3 | 0 0 1 0
# 2 | 0 1 0 1
#
R # Take the upper-triangular portion of this matrix (sets below-diagonal to 0)
#
# [1 0 0 0
# 0 1 0 1
# 0 0 1 0
# 0 0 0 1]
#
s # Compute the sum down the columns
#
# [1,1,1,2]
#
# Implicitly display the result
1
ah, I knew there was an old problem that made me think of something similar, it's Unique is Cheap, and the MATL solution there is one character different!
– Giuseppe
2 days ago
add a comment |
MATL, 4 bytes
&=Rs
This solution is 1-based
Try it out at MATL Online!
Explanation
Uses [1,2,3,2]
as an example
# Implicitly grab the input array of length N
#
# [1,2,3,2]
#
&= # Create an N x N boolean matrix by performing an element-wise comparison
# between the original array and its transpose:
#
# 1 2 3 2
# -------
# 1 | 1 0 0 0
# 2 | 0 1 0 1
# 3 | 0 0 1 0
# 2 | 0 1 0 1
#
R # Take the upper-triangular portion of this matrix (sets below-diagonal to 0)
#
# [1 0 0 0
# 0 1 0 1
# 0 0 1 0
# 0 0 0 1]
#
s # Compute the sum down the columns
#
# [1,1,1,2]
#
# Implicitly display the result
1
ah, I knew there was an old problem that made me think of something similar, it's Unique is Cheap, and the MATL solution there is one character different!
– Giuseppe
2 days ago
add a comment |
MATL, 4 bytes
&=Rs
This solution is 1-based
Try it out at MATL Online!
Explanation
Uses [1,2,3,2]
as an example
# Implicitly grab the input array of length N
#
# [1,2,3,2]
#
&= # Create an N x N boolean matrix by performing an element-wise comparison
# between the original array and its transpose:
#
# 1 2 3 2
# -------
# 1 | 1 0 0 0
# 2 | 0 1 0 1
# 3 | 0 0 1 0
# 2 | 0 1 0 1
#
R # Take the upper-triangular portion of this matrix (sets below-diagonal to 0)
#
# [1 0 0 0
# 0 1 0 1
# 0 0 1 0
# 0 0 0 1]
#
s # Compute the sum down the columns
#
# [1,1,1,2]
#
# Implicitly display the result
MATL, 4 bytes
&=Rs
This solution is 1-based
Try it out at MATL Online!
Explanation
Uses [1,2,3,2]
as an example
# Implicitly grab the input array of length N
#
# [1,2,3,2]
#
&= # Create an N x N boolean matrix by performing an element-wise comparison
# between the original array and its transpose:
#
# 1 2 3 2
# -------
# 1 | 1 0 0 0
# 2 | 0 1 0 1
# 3 | 0 0 1 0
# 2 | 0 1 0 1
#
R # Take the upper-triangular portion of this matrix (sets below-diagonal to 0)
#
# [1 0 0 0
# 0 1 0 1
# 0 0 1 0
# 0 0 0 1]
#
s # Compute the sum down the columns
#
# [1,1,1,2]
#
# Implicitly display the result
edited 2 days ago
answered 2 days ago
SueverSuever
9,6021345
9,6021345
1
ah, I knew there was an old problem that made me think of something similar, it's Unique is Cheap, and the MATL solution there is one character different!
– Giuseppe
2 days ago
add a comment |
1
ah, I knew there was an old problem that made me think of something similar, it's Unique is Cheap, and the MATL solution there is one character different!
– Giuseppe
2 days ago
1
1
ah, I knew there was an old problem that made me think of something similar, it's Unique is Cheap, and the MATL solution there is one character different!
– Giuseppe
2 days ago
ah, I knew there was an old problem that made me think of something similar, it's Unique is Cheap, and the MATL solution there is one character different!
– Giuseppe
2 days ago
add a comment |
APL (Dyalog Unicode), 7 bytes
Many, many thanks to H.PWiz, Adám and dzaima for all their help in debugging and correcting this.
+/¨⊢=,
Try it online!
Explanation
The 10-byte non-tacit version will be easier to explain first
{+/¨⍵=,⍵}
{ } A user-defined function, a dfn
,⍵ The list of prefixes of our input list ⍵
(⍵ more generally means the right argument of a dfn)
is 'scan' which both gives us our prefixes
and applies ,/ over each prefix, which keeps each prefix as-is
⍵= Checks each element of ⍵ against its corresponding prefix
This checks each prefix for occurrences of the last element of that prefix
This gives us several lists of 0s and 1s
+/¨ This sums over each list of 0s and 1s to give us the enumeration we are looking for
The tacit version does three things
- First, it removes the instance of
⍵
used in,⍵
as,
on the right by itself can implicitly figure out that it's supposed to operate on the right argument. - Second, for
⍵=
, we replace the⍵
with⊢
, which stands for right argument - Third, now that we have no explicit arguments (in this case,
⍵
), we can remove the braces{}
as tacit functions do not use them
add a comment |
APL (Dyalog Unicode), 7 bytes
Many, many thanks to H.PWiz, Adám and dzaima for all their help in debugging and correcting this.
+/¨⊢=,
Try it online!
Explanation
The 10-byte non-tacit version will be easier to explain first
{+/¨⍵=,⍵}
{ } A user-defined function, a dfn
,⍵ The list of prefixes of our input list ⍵
(⍵ more generally means the right argument of a dfn)
is 'scan' which both gives us our prefixes
and applies ,/ over each prefix, which keeps each prefix as-is
⍵= Checks each element of ⍵ against its corresponding prefix
This checks each prefix for occurrences of the last element of that prefix
This gives us several lists of 0s and 1s
+/¨ This sums over each list of 0s and 1s to give us the enumeration we are looking for
The tacit version does three things
- First, it removes the instance of
⍵
used in,⍵
as,
on the right by itself can implicitly figure out that it's supposed to operate on the right argument. - Second, for
⍵=
, we replace the⍵
with⊢
, which stands for right argument - Third, now that we have no explicit arguments (in this case,
⍵
), we can remove the braces{}
as tacit functions do not use them
add a comment |
APL (Dyalog Unicode), 7 bytes
Many, many thanks to H.PWiz, Adám and dzaima for all their help in debugging and correcting this.
+/¨⊢=,
Try it online!
Explanation
The 10-byte non-tacit version will be easier to explain first
{+/¨⍵=,⍵}
{ } A user-defined function, a dfn
,⍵ The list of prefixes of our input list ⍵
(⍵ more generally means the right argument of a dfn)
is 'scan' which both gives us our prefixes
and applies ,/ over each prefix, which keeps each prefix as-is
⍵= Checks each element of ⍵ against its corresponding prefix
This checks each prefix for occurrences of the last element of that prefix
This gives us several lists of 0s and 1s
+/¨ This sums over each list of 0s and 1s to give us the enumeration we are looking for
The tacit version does three things
- First, it removes the instance of
⍵
used in,⍵
as,
on the right by itself can implicitly figure out that it's supposed to operate on the right argument. - Second, for
⍵=
, we replace the⍵
with⊢
, which stands for right argument - Third, now that we have no explicit arguments (in this case,
⍵
), we can remove the braces{}
as tacit functions do not use them
APL (Dyalog Unicode), 7 bytes
Many, many thanks to H.PWiz, Adám and dzaima for all their help in debugging and correcting this.
+/¨⊢=,
Try it online!
Explanation
The 10-byte non-tacit version will be easier to explain first
{+/¨⍵=,⍵}
{ } A user-defined function, a dfn
,⍵ The list of prefixes of our input list ⍵
(⍵ more generally means the right argument of a dfn)
is 'scan' which both gives us our prefixes
and applies ,/ over each prefix, which keeps each prefix as-is
⍵= Checks each element of ⍵ against its corresponding prefix
This checks each prefix for occurrences of the last element of that prefix
This gives us several lists of 0s and 1s
+/¨ This sums over each list of 0s and 1s to give us the enumeration we are looking for
The tacit version does three things
- First, it removes the instance of
⍵
used in,⍵
as,
on the right by itself can implicitly figure out that it's supposed to operate on the right argument. - Second, for
⍵=
, we replace the⍵
with⊢
, which stands for right argument - Third, now that we have no explicit arguments (in this case,
⍵
), we can remove the braces{}
as tacit functions do not use them
edited 2 days ago
answered 2 days ago
Sherlock9Sherlock9
7,86411859
7,86411859
add a comment |
add a comment |
J, 7 bytes
1#.]=]
Try it online!
1-indexed.
Explanation:
] all the prefixes (filled with zeros, but there won't be any 0s in the input):
] 5 12 10 12 12 10
5 0 0 0 0 0
5 12 0 0 0 0
5 12 10 0 0 0
5 12 10 12 0 0
5 12 10 12 12 0
5 12 10 12 12 10
]= is each number from the input equal to the prefix:
(]=]) 5 12 10 12 12 10
1 0 0 0 0 0
0 1 0 0 0 0
0 0 1 0 0 0
0 1 0 1 0 0
0 1 0 1 1 0
0 0 1 0 0 1
1#. sum each row:
(1#.]=]) 5 12 10 12 12 10
1 1 1 2 3 2
K (oK), 11 bytes
{+/'x=',x}
Try it online!
1
Heh, you're happy that I made the data strictly positive…
– Adám
2 days ago
@Adám Yes, otherwise I'd need to box the prefixes :)
– Galen Ivanov
2 days ago
add a comment |
J, 7 bytes
1#.]=]
Try it online!
1-indexed.
Explanation:
] all the prefixes (filled with zeros, but there won't be any 0s in the input):
] 5 12 10 12 12 10
5 0 0 0 0 0
5 12 0 0 0 0
5 12 10 0 0 0
5 12 10 12 0 0
5 12 10 12 12 0
5 12 10 12 12 10
]= is each number from the input equal to the prefix:
(]=]) 5 12 10 12 12 10
1 0 0 0 0 0
0 1 0 0 0 0
0 0 1 0 0 0
0 1 0 1 0 0
0 1 0 1 1 0
0 0 1 0 0 1
1#. sum each row:
(1#.]=]) 5 12 10 12 12 10
1 1 1 2 3 2
K (oK), 11 bytes
{+/'x=',x}
Try it online!
1
Heh, you're happy that I made the data strictly positive…
– Adám
2 days ago
@Adám Yes, otherwise I'd need to box the prefixes :)
– Galen Ivanov
2 days ago
add a comment |
J, 7 bytes
1#.]=]
Try it online!
1-indexed.
Explanation:
] all the prefixes (filled with zeros, but there won't be any 0s in the input):
] 5 12 10 12 12 10
5 0 0 0 0 0
5 12 0 0 0 0
5 12 10 0 0 0
5 12 10 12 0 0
5 12 10 12 12 0
5 12 10 12 12 10
]= is each number from the input equal to the prefix:
(]=]) 5 12 10 12 12 10
1 0 0 0 0 0
0 1 0 0 0 0
0 0 1 0 0 0
0 1 0 1 0 0
0 1 0 1 1 0
0 0 1 0 0 1
1#. sum each row:
(1#.]=]) 5 12 10 12 12 10
1 1 1 2 3 2
K (oK), 11 bytes
{+/'x=',x}
Try it online!
J, 7 bytes
1#.]=]
Try it online!
1-indexed.
Explanation:
] all the prefixes (filled with zeros, but there won't be any 0s in the input):
] 5 12 10 12 12 10
5 0 0 0 0 0
5 12 0 0 0 0
5 12 10 0 0 0
5 12 10 12 0 0
5 12 10 12 12 0
5 12 10 12 12 10
]= is each number from the input equal to the prefix:
(]=]) 5 12 10 12 12 10
1 0 0 0 0 0
0 1 0 0 0 0
0 0 1 0 0 0
0 1 0 1 0 0
0 1 0 1 1 0
0 0 1 0 0 1
1#. sum each row:
(1#.]=]) 5 12 10 12 12 10
1 1 1 2 3 2
K (oK), 11 bytes
{+/'x=',x}
Try it online!
edited yesterday
answered 2 days ago
Galen IvanovGalen Ivanov
6,44711032
6,44711032
1
Heh, you're happy that I made the data strictly positive…
– Adám
2 days ago
@Adám Yes, otherwise I'd need to box the prefixes :)
– Galen Ivanov
2 days ago
add a comment |
1
Heh, you're happy that I made the data strictly positive…
– Adám
2 days ago
@Adám Yes, otherwise I'd need to box the prefixes :)
– Galen Ivanov
2 days ago
1
1
Heh, you're happy that I made the data strictly positive…
– Adám
2 days ago
Heh, you're happy that I made the data strictly positive…
– Adám
2 days ago
@Adám Yes, otherwise I'd need to box the prefixes :)
– Galen Ivanov
2 days ago
@Adám Yes, otherwise I'd need to box the prefixes :)
– Galen Ivanov
2 days ago
add a comment |
Python 2, 48 bytes
lambda a:[a[:i].count(v)for i,v in enumerate(a)]
Try it online!
add a comment |
Python 2, 48 bytes
lambda a:[a[:i].count(v)for i,v in enumerate(a)]
Try it online!
add a comment |
Python 2, 48 bytes
lambda a:[a[:i].count(v)for i,v in enumerate(a)]
Try it online!
Python 2, 48 bytes
lambda a:[a[:i].count(v)for i,v in enumerate(a)]
Try it online!
answered 2 days ago
TFeldTFeld
14.4k21240
14.4k21240
add a comment |
add a comment |
05AB1E, 4 bytes
ηε¤¢
Try it online!
or as a Test Suite
Explanation
ηε # apply to each prefix of the input list
¤¢ # count occurrences of the last element
add a comment |
05AB1E, 4 bytes
ηε¤¢
Try it online!
or as a Test Suite
Explanation
ηε # apply to each prefix of the input list
¤¢ # count occurrences of the last element
add a comment |
05AB1E, 4 bytes
ηε¤¢
Try it online!
or as a Test Suite
Explanation
ηε # apply to each prefix of the input list
¤¢ # count occurrences of the last element
05AB1E, 4 bytes
ηε¤¢
Try it online!
or as a Test Suite
Explanation
ηε # apply to each prefix of the input list
¤¢ # count occurrences of the last element
answered 2 days ago
EmignaEmigna
45.5k432138
45.5k432138
add a comment |
add a comment |
C# (Visual C# Interactive Compiler), 44 bytes
x=>x.Select((y,i)=>x.Take(i).Count(z=>z==y))
Try it online!
22 bytes
– LiefdeWen
2 days ago
You have the inversed of the challenge right now..[7,7,7]
should output[0,1,2]
, and not[0,0,0]
.
– Kevin Cruijssen
2 days ago
1
@KevinCruijssen - Thanks :) Looks like I misread things, it should be fixed now.
– dana
2 days ago
add a comment |
C# (Visual C# Interactive Compiler), 44 bytes
x=>x.Select((y,i)=>x.Take(i).Count(z=>z==y))
Try it online!
22 bytes
– LiefdeWen
2 days ago
You have the inversed of the challenge right now..[7,7,7]
should output[0,1,2]
, and not[0,0,0]
.
– Kevin Cruijssen
2 days ago
1
@KevinCruijssen - Thanks :) Looks like I misread things, it should be fixed now.
– dana
2 days ago
add a comment |
C# (Visual C# Interactive Compiler), 44 bytes
x=>x.Select((y,i)=>x.Take(i).Count(z=>z==y))
Try it online!
C# (Visual C# Interactive Compiler), 44 bytes
x=>x.Select((y,i)=>x.Take(i).Count(z=>z==y))
Try it online!
edited 2 days ago
answered 2 days ago
danadana
58135
58135
22 bytes
– LiefdeWen
2 days ago
You have the inversed of the challenge right now..[7,7,7]
should output[0,1,2]
, and not[0,0,0]
.
– Kevin Cruijssen
2 days ago
1
@KevinCruijssen - Thanks :) Looks like I misread things, it should be fixed now.
– dana
2 days ago
add a comment |
22 bytes
– LiefdeWen
2 days ago
You have the inversed of the challenge right now..[7,7,7]
should output[0,1,2]
, and not[0,0,0]
.
– Kevin Cruijssen
2 days ago
1
@KevinCruijssen - Thanks :) Looks like I misread things, it should be fixed now.
– dana
2 days ago
22 bytes
– LiefdeWen
2 days ago
22 bytes
– LiefdeWen
2 days ago
You have the inversed of the challenge right now..
[7,7,7]
should output [0,1,2]
, and not [0,0,0]
.– Kevin Cruijssen
2 days ago
You have the inversed of the challenge right now..
[7,7,7]
should output [0,1,2]
, and not [0,0,0]
.– Kevin Cruijssen
2 days ago
1
1
@KevinCruijssen - Thanks :) Looks like I misread things, it should be fixed now.
– dana
2 days ago
@KevinCruijssen - Thanks :) Looks like I misread things, it should be fixed now.
– dana
2 days ago
add a comment |
AWK, 15
{print a[$1]++}
Try it online!
The above does zero-based indexing. If you prefer one-based indexing, its a simple change:
{print ++a[$1]}
Try it online!
add a comment |
AWK, 15
{print a[$1]++}
Try it online!
The above does zero-based indexing. If you prefer one-based indexing, its a simple change:
{print ++a[$1]}
Try it online!
add a comment |
AWK, 15
{print a[$1]++}
Try it online!
The above does zero-based indexing. If you prefer one-based indexing, its a simple change:
{print ++a[$1]}
Try it online!
AWK, 15
{print a[$1]++}
Try it online!
The above does zero-based indexing. If you prefer one-based indexing, its a simple change:
{print ++a[$1]}
Try it online!
edited 2 days ago
answered 2 days ago
Digital TraumaDigital Trauma
58.6k787221
58.6k787221
add a comment |
add a comment |
Python 2, 47 43 bytes
f=lambda a:a and f(a[:-1])+[a.count(a[-1])]
Try it online!
A recursive 'one-based' solution.
add a comment |
Python 2, 47 43 bytes
f=lambda a:a and f(a[:-1])+[a.count(a[-1])]
Try it online!
A recursive 'one-based' solution.
add a comment |
Python 2, 47 43 bytes
f=lambda a:a and f(a[:-1])+[a.count(a[-1])]
Try it online!
A recursive 'one-based' solution.
Python 2, 47 43 bytes
f=lambda a:a and f(a[:-1])+[a.count(a[-1])]
Try it online!
A recursive 'one-based' solution.
edited 2 days ago
answered 2 days ago
Chas BrownChas Brown
4,8391522
4,8391522
add a comment |
add a comment |
Jelly, 4 bytes
ċṪ$Ƥ
Try it online!
For each prefix of the input list, it counts the number of occurrences of its last element in itself.
Alternatively the old-school;ċ"
is also 4.
– Jonathan Allan
2 days ago
add a comment |
Jelly, 4 bytes
ċṪ$Ƥ
Try it online!
For each prefix of the input list, it counts the number of occurrences of its last element in itself.
Alternatively the old-school;ċ"
is also 4.
– Jonathan Allan
2 days ago
add a comment |
Jelly, 4 bytes
ċṪ$Ƥ
Try it online!
For each prefix of the input list, it counts the number of occurrences of its last element in itself.
Jelly, 4 bytes
ċṪ$Ƥ
Try it online!
For each prefix of the input list, it counts the number of occurrences of its last element in itself.
answered 2 days ago
Mr. XcoderMr. Xcoder
31.7k759198
31.7k759198
Alternatively the old-school;ċ"
is also 4.
– Jonathan Allan
2 days ago
add a comment |
Alternatively the old-school;ċ"
is also 4.
– Jonathan Allan
2 days ago
Alternatively the old-school
;ċ"
is also 4.– Jonathan Allan
2 days ago
Alternatively the old-school
;ċ"
is also 4.– Jonathan Allan
2 days ago
add a comment |
Ruby, 35 bytes
->a{f=Hash.new 0;a.map{|v|f[v]+=1}}
It's pretty mundane, unfortunately - build a hash that stores the total for each entry encountered so far.
Some other, fun options that unfortunately weren't quite short enough:
->a{a.dup.map{a.count a.pop}.reverse} # 37
->a{i=-1;a.map{|v|a[0..i+=1].count v}} # 38
add a comment |
Ruby, 35 bytes
->a{f=Hash.new 0;a.map{|v|f[v]+=1}}
It's pretty mundane, unfortunately - build a hash that stores the total for each entry encountered so far.
Some other, fun options that unfortunately weren't quite short enough:
->a{a.dup.map{a.count a.pop}.reverse} # 37
->a{i=-1;a.map{|v|a[0..i+=1].count v}} # 38
add a comment |
Ruby, 35 bytes
->a{f=Hash.new 0;a.map{|v|f[v]+=1}}
It's pretty mundane, unfortunately - build a hash that stores the total for each entry encountered so far.
Some other, fun options that unfortunately weren't quite short enough:
->a{a.dup.map{a.count a.pop}.reverse} # 37
->a{i=-1;a.map{|v|a[0..i+=1].count v}} # 38
Ruby, 35 bytes
->a{f=Hash.new 0;a.map{|v|f[v]+=1}}
It's pretty mundane, unfortunately - build a hash that stores the total for each entry encountered so far.
Some other, fun options that unfortunately weren't quite short enough:
->a{a.dup.map{a.count a.pop}.reverse} # 37
->a{i=-1;a.map{|v|a[0..i+=1].count v}} # 38
answered 2 days ago
DaveMongooseDaveMongoose
1414
1414
add a comment |
add a comment |
Perl 6, 15 bytes
*>>.&{%.{$_}++}
Try it online!
You can move the ++
to before the %
for a one based index.
Explanation:
*>>.&{ } # Map the input to
% # An anonymous hash
.{$_} # The current element indexed
++ # Incremented
add a comment |
Perl 6, 15 bytes
*>>.&{%.{$_}++}
Try it online!
You can move the ++
to before the %
for a one based index.
Explanation:
*>>.&{ } # Map the input to
% # An anonymous hash
.{$_} # The current element indexed
++ # Incremented
add a comment |
Perl 6, 15 bytes
*>>.&{%.{$_}++}
Try it online!
You can move the ++
to before the %
for a one based index.
Explanation:
*>>.&{ } # Map the input to
% # An anonymous hash
.{$_} # The current element indexed
++ # Incremented
Perl 6, 15 bytes
*>>.&{%.{$_}++}
Try it online!
You can move the ++
to before the %
for a one based index.
Explanation:
*>>.&{ } # Map the input to
% # An anonymous hash
.{$_} # The current element indexed
++ # Incremented
edited yesterday
answered 2 days ago
Jo KingJo King
21.2k248110
21.2k248110
add a comment |
add a comment |
R, 41 bytes
function(x)diag(diffinv(outer(x,x,"==")))
Try it online!
Oddly, returning a zero-based index is shorter in R.
Once again Giuseppe, your superior knowledge of R has beaten me. I had a decently ingenious method at 60 bytes, but alas, it wasn't enough!
– Sumner18
2 days ago
@Sumner18 post it anyway! I always learn a lot from other peoples' approaches, and getting feedback is the fastest way to learn!
– Giuseppe
2 days ago
thanks for the encouragement! I've posted mine now and am always open to suggestions for improvement!
– Sumner18
2 days ago
add a comment |
R, 41 bytes
function(x)diag(diffinv(outer(x,x,"==")))
Try it online!
Oddly, returning a zero-based index is shorter in R.
Once again Giuseppe, your superior knowledge of R has beaten me. I had a decently ingenious method at 60 bytes, but alas, it wasn't enough!
– Sumner18
2 days ago
@Sumner18 post it anyway! I always learn a lot from other peoples' approaches, and getting feedback is the fastest way to learn!
– Giuseppe
2 days ago
thanks for the encouragement! I've posted mine now and am always open to suggestions for improvement!
– Sumner18
2 days ago
add a comment |
R, 41 bytes
function(x)diag(diffinv(outer(x,x,"==")))
Try it online!
Oddly, returning a zero-based index is shorter in R.
R, 41 bytes
function(x)diag(diffinv(outer(x,x,"==")))
Try it online!
Oddly, returning a zero-based index is shorter in R.
answered 2 days ago
GiuseppeGiuseppe
16.6k31052
16.6k31052
Once again Giuseppe, your superior knowledge of R has beaten me. I had a decently ingenious method at 60 bytes, but alas, it wasn't enough!
– Sumner18
2 days ago
@Sumner18 post it anyway! I always learn a lot from other peoples' approaches, and getting feedback is the fastest way to learn!
– Giuseppe
2 days ago
thanks for the encouragement! I've posted mine now and am always open to suggestions for improvement!
– Sumner18
2 days ago
add a comment |
Once again Giuseppe, your superior knowledge of R has beaten me. I had a decently ingenious method at 60 bytes, but alas, it wasn't enough!
– Sumner18
2 days ago
@Sumner18 post it anyway! I always learn a lot from other peoples' approaches, and getting feedback is the fastest way to learn!
– Giuseppe
2 days ago
thanks for the encouragement! I've posted mine now and am always open to suggestions for improvement!
– Sumner18
2 days ago
Once again Giuseppe, your superior knowledge of R has beaten me. I had a decently ingenious method at 60 bytes, but alas, it wasn't enough!
– Sumner18
2 days ago
Once again Giuseppe, your superior knowledge of R has beaten me. I had a decently ingenious method at 60 bytes, but alas, it wasn't enough!
– Sumner18
2 days ago
@Sumner18 post it anyway! I always learn a lot from other peoples' approaches, and getting feedback is the fastest way to learn!
– Giuseppe
2 days ago
@Sumner18 post it anyway! I always learn a lot from other peoples' approaches, and getting feedback is the fastest way to learn!
– Giuseppe
2 days ago
thanks for the encouragement! I've posted mine now and am always open to suggestions for improvement!
– Sumner18
2 days ago
thanks for the encouragement! I've posted mine now and am always open to suggestions for improvement!
– Sumner18
2 days ago
add a comment |
Java (JDK), 76 bytes
a->{for(int l=a.length,i,c;l-->0;a[l]=c)for(c=i=0;i<l;)c+=a[l]==a[i++]?1:0;}
Try it online!
Credits
- -2 bytes thanks to Kevin Cruijssen
1
-2 bytes by changingfor(c=0,i=l;i-->0;)c+=a[l]==a[i]?1:0;
tofor(c=i=0;i<l;)c+=a[l]==a[i++]?1:0;
.
– Kevin Cruijssen
2 days ago
add a comment |
Java (JDK), 76 bytes
a->{for(int l=a.length,i,c;l-->0;a[l]=c)for(c=i=0;i<l;)c+=a[l]==a[i++]?1:0;}
Try it online!
Credits
- -2 bytes thanks to Kevin Cruijssen
1
-2 bytes by changingfor(c=0,i=l;i-->0;)c+=a[l]==a[i]?1:0;
tofor(c=i=0;i<l;)c+=a[l]==a[i++]?1:0;
.
– Kevin Cruijssen
2 days ago
add a comment |
Java (JDK), 76 bytes
a->{for(int l=a.length,i,c;l-->0;a[l]=c)for(c=i=0;i<l;)c+=a[l]==a[i++]?1:0;}
Try it online!
Credits
- -2 bytes thanks to Kevin Cruijssen
Java (JDK), 76 bytes
a->{for(int l=a.length,i,c;l-->0;a[l]=c)for(c=i=0;i<l;)c+=a[l]==a[i++]?1:0;}
Try it online!
Credits
- -2 bytes thanks to Kevin Cruijssen
edited 2 days ago
answered 2 days ago
Olivier GrégoireOlivier Grégoire
8,84711843
8,84711843
1
-2 bytes by changingfor(c=0,i=l;i-->0;)c+=a[l]==a[i]?1:0;
tofor(c=i=0;i<l;)c+=a[l]==a[i++]?1:0;
.
– Kevin Cruijssen
2 days ago
add a comment |
1
-2 bytes by changingfor(c=0,i=l;i-->0;)c+=a[l]==a[i]?1:0;
tofor(c=i=0;i<l;)c+=a[l]==a[i++]?1:0;
.
– Kevin Cruijssen
2 days ago
1
1
-2 bytes by changing
for(c=0,i=l;i-->0;)c+=a[l]==a[i]?1:0;
to for(c=i=0;i<l;)c+=a[l]==a[i++]?1:0;
.– Kevin Cruijssen
2 days ago
-2 bytes by changing
for(c=0,i=l;i-->0;)c+=a[l]==a[i]?1:0;
to for(c=i=0;i<l;)c+=a[l]==a[i++]?1:0;
.– Kevin Cruijssen
2 days ago
add a comment |
R, 62 43 bytes
x=z=scan();for(i in x)z[y]=1:sum(y<-x==i);z
-19 bytes thanks to Giuseppe, by removing which, and table, and only slight changes to the implementation
Original
x=z=scan();for(i in names(r<-table(x)))z[which(x==i)]=1:r[i];z
I can't compete with Giuseppe's knowledge, so my submission is somewhat longer than his, but using my basic knowledge, I felt that this solution was rather ingenious.
r<-table(x)
counts the number of times each number appears and stores it in r, for future reference
names()
gets the values of each unique entry in the table, and we iterate over these names with a for loop.
The remaining portion checks which entries are equal to the iterations and stores a sequence of values (from 1 to the number of entries of the iteration)
Try it online!
you can remove thewhich()
to save 7 bytes.
– Giuseppe
2 days ago
Your use of1:r[i]
gave me the idea to just removetable()
entirely:x=z=scan();for(i in x)z[y]=1:sum(y<-x==i);z
is 43 bytes! This is a nice approach!
– Giuseppe
2 days ago
add a comment |
R, 62 43 bytes
x=z=scan();for(i in x)z[y]=1:sum(y<-x==i);z
-19 bytes thanks to Giuseppe, by removing which, and table, and only slight changes to the implementation
Original
x=z=scan();for(i in names(r<-table(x)))z[which(x==i)]=1:r[i];z
I can't compete with Giuseppe's knowledge, so my submission is somewhat longer than his, but using my basic knowledge, I felt that this solution was rather ingenious.
r<-table(x)
counts the number of times each number appears and stores it in r, for future reference
names()
gets the values of each unique entry in the table, and we iterate over these names with a for loop.
The remaining portion checks which entries are equal to the iterations and stores a sequence of values (from 1 to the number of entries of the iteration)
Try it online!
you can remove thewhich()
to save 7 bytes.
– Giuseppe
2 days ago
Your use of1:r[i]
gave me the idea to just removetable()
entirely:x=z=scan();for(i in x)z[y]=1:sum(y<-x==i);z
is 43 bytes! This is a nice approach!
– Giuseppe
2 days ago
add a comment |
R, 62 43 bytes
x=z=scan();for(i in x)z[y]=1:sum(y<-x==i);z
-19 bytes thanks to Giuseppe, by removing which, and table, and only slight changes to the implementation
Original
x=z=scan();for(i in names(r<-table(x)))z[which(x==i)]=1:r[i];z
I can't compete with Giuseppe's knowledge, so my submission is somewhat longer than his, but using my basic knowledge, I felt that this solution was rather ingenious.
r<-table(x)
counts the number of times each number appears and stores it in r, for future reference
names()
gets the values of each unique entry in the table, and we iterate over these names with a for loop.
The remaining portion checks which entries are equal to the iterations and stores a sequence of values (from 1 to the number of entries of the iteration)
Try it online!
R, 62 43 bytes
x=z=scan();for(i in x)z[y]=1:sum(y<-x==i);z
-19 bytes thanks to Giuseppe, by removing which, and table, and only slight changes to the implementation
Original
x=z=scan();for(i in names(r<-table(x)))z[which(x==i)]=1:r[i];z
I can't compete with Giuseppe's knowledge, so my submission is somewhat longer than his, but using my basic knowledge, I felt that this solution was rather ingenious.
r<-table(x)
counts the number of times each number appears and stores it in r, for future reference
names()
gets the values of each unique entry in the table, and we iterate over these names with a for loop.
The remaining portion checks which entries are equal to the iterations and stores a sequence of values (from 1 to the number of entries of the iteration)
Try it online!
edited 2 days ago
answered 2 days ago
Sumner18Sumner18
4007
4007
you can remove thewhich()
to save 7 bytes.
– Giuseppe
2 days ago
Your use of1:r[i]
gave me the idea to just removetable()
entirely:x=z=scan();for(i in x)z[y]=1:sum(y<-x==i);z
is 43 bytes! This is a nice approach!
– Giuseppe
2 days ago
add a comment |
you can remove thewhich()
to save 7 bytes.
– Giuseppe
2 days ago
Your use of1:r[i]
gave me the idea to just removetable()
entirely:x=z=scan();for(i in x)z[y]=1:sum(y<-x==i);z
is 43 bytes! This is a nice approach!
– Giuseppe
2 days ago
you can remove the
which()
to save 7 bytes.– Giuseppe
2 days ago
you can remove the
which()
to save 7 bytes.– Giuseppe
2 days ago
Your use of
1:r[i]
gave me the idea to just remove table()
entirely: x=z=scan();for(i in x)z[y]=1:sum(y<-x==i);z
is 43 bytes! This is a nice approach!– Giuseppe
2 days ago
Your use of
1:r[i]
gave me the idea to just remove table()
entirely: x=z=scan();for(i in x)z[y]=1:sum(y<-x==i);z
is 43 bytes! This is a nice approach!– Giuseppe
2 days ago
add a comment |
Haskell, 44 bytes
(#)
x#(y:z)=sum[1|a<-x,a==y]:(y:x)#z
_#e=e
Try it online!
Explanation
Traverses the list from left to right keeping the list x
of visited elements, initially :
For every encounter of a y
count all equal elements in the list x
.
1
A bit longer but maybe nevertheless interesting:(#(0*));(x:r)#g=g x:r# y->0^abs(y-x)+g y;e#g=e
Try it online!
– Laikoni
12 hours ago
@Laikoni: How did you even come up with that, you should totally post it!
– BMO
12 hours ago
1
Done: codegolf.stackexchange.com/a/178629/56433
– Laikoni
11 hours ago
add a comment |
Haskell, 44 bytes
(#)
x#(y:z)=sum[1|a<-x,a==y]:(y:x)#z
_#e=e
Try it online!
Explanation
Traverses the list from left to right keeping the list x
of visited elements, initially :
For every encounter of a y
count all equal elements in the list x
.
1
A bit longer but maybe nevertheless interesting:(#(0*));(x:r)#g=g x:r# y->0^abs(y-x)+g y;e#g=e
Try it online!
– Laikoni
12 hours ago
@Laikoni: How did you even come up with that, you should totally post it!
– BMO
12 hours ago
1
Done: codegolf.stackexchange.com/a/178629/56433
– Laikoni
11 hours ago
add a comment |
Haskell, 44 bytes
(#)
x#(y:z)=sum[1|a<-x,a==y]:(y:x)#z
_#e=e
Try it online!
Explanation
Traverses the list from left to right keeping the list x
of visited elements, initially :
For every encounter of a y
count all equal elements in the list x
.
Haskell, 44 bytes
(#)
x#(y:z)=sum[1|a<-x,a==y]:(y:x)#z
_#e=e
Try it online!
Explanation
Traverses the list from left to right keeping the list x
of visited elements, initially :
For every encounter of a y
count all equal elements in the list x
.
answered 2 days ago
BMOBMO
11.8k22188
11.8k22188
1
A bit longer but maybe nevertheless interesting:(#(0*));(x:r)#g=g x:r# y->0^abs(y-x)+g y;e#g=e
Try it online!
– Laikoni
12 hours ago
@Laikoni: How did you even come up with that, you should totally post it!
– BMO
12 hours ago
1
Done: codegolf.stackexchange.com/a/178629/56433
– Laikoni
11 hours ago
add a comment |
1
A bit longer but maybe nevertheless interesting:(#(0*));(x:r)#g=g x:r# y->0^abs(y-x)+g y;e#g=e
Try it online!
– Laikoni
12 hours ago
@Laikoni: How did you even come up with that, you should totally post it!
– BMO
12 hours ago
1
Done: codegolf.stackexchange.com/a/178629/56433
– Laikoni
11 hours ago
1
1
A bit longer but maybe nevertheless interesting:
(#(0*));(x:r)#g=g x:r# y->0^abs(y-x)+g y;e#g=e
Try it online!– Laikoni
12 hours ago
A bit longer but maybe nevertheless interesting:
(#(0*));(x:r)#g=g x:r# y->0^abs(y-x)+g y;e#g=e
Try it online!– Laikoni
12 hours ago
@Laikoni: How did you even come up with that, you should totally post it!
– BMO
12 hours ago
@Laikoni: How did you even come up with that, you should totally post it!
– BMO
12 hours ago
1
1
Done: codegolf.stackexchange.com/a/178629/56433
– Laikoni
11 hours ago
Done: codegolf.stackexchange.com/a/178629/56433
– Laikoni
11 hours ago
add a comment |
Ruby, 34 bytes
->a{r=;a.map{|x|(r<<x).count x}}
Try it online!
I can't believe I tried->a{i=-1;a.map{|v|a[0..i+=1].count v}}
and didn't think of just building a new array, lol. Nice work.
– DaveMongoose
yesterday
add a comment |
Ruby, 34 bytes
->a{r=;a.map{|x|(r<<x).count x}}
Try it online!
I can't believe I tried->a{i=-1;a.map{|v|a[0..i+=1].count v}}
and didn't think of just building a new array, lol. Nice work.
– DaveMongoose
yesterday
add a comment |
Ruby, 34 bytes
->a{r=;a.map{|x|(r<<x).count x}}
Try it online!
Ruby, 34 bytes
->a{r=;a.map{|x|(r<<x).count x}}
Try it online!
answered 2 days ago
G BG B
7,6961328
7,6961328
I can't believe I tried->a{i=-1;a.map{|v|a[0..i+=1].count v}}
and didn't think of just building a new array, lol. Nice work.
– DaveMongoose
yesterday
add a comment |
I can't believe I tried->a{i=-1;a.map{|v|a[0..i+=1].count v}}
and didn't think of just building a new array, lol. Nice work.
– DaveMongoose
yesterday
I can't believe I tried
->a{i=-1;a.map{|v|a[0..i+=1].count v}}
and didn't think of just building a new array, lol. Nice work.– DaveMongoose
yesterday
I can't believe I tried
->a{i=-1;a.map{|v|a[0..i+=1].count v}}
and didn't think of just building a new array, lol. Nice work.– DaveMongoose
yesterday
add a comment |
bash, 37 bytes or 24 bytes
f()(for x;{ r+=$[a[x]++] ;};echo $r)
TIO
if valid, there is also this variation, as suggested by DigitalTrauma
for x;{ echo $[a[x]++];}
TIO
1
Pass the list as command line args - tio.run/##S0oszvj/Py2/SKHCuporNTkjX0ElOjG6IlZbO5ar9v///8b/… - only 24 bytes.
– Digital Trauma
2 days ago
@DigitalTrauma, thanks however i don't know if it broke the rules. also as it was asked to replace list and maybe should be something like tio.run/…
– Nahuel Fouilleul
yesterday
2
@NahuelFouilleul It's fine, full programs are allowed too, and that's a valid method of inputting/outputting a list (IMO)
– ASCII-only
yesterday
add a comment |
bash, 37 bytes or 24 bytes
f()(for x;{ r+=$[a[x]++] ;};echo $r)
TIO
if valid, there is also this variation, as suggested by DigitalTrauma
for x;{ echo $[a[x]++];}
TIO
1
Pass the list as command line args - tio.run/##S0oszvj/Py2/SKHCuporNTkjX0ElOjG6IlZbO5ar9v///8b/… - only 24 bytes.
– Digital Trauma
2 days ago
@DigitalTrauma, thanks however i don't know if it broke the rules. also as it was asked to replace list and maybe should be something like tio.run/…
– Nahuel Fouilleul
yesterday
2
@NahuelFouilleul It's fine, full programs are allowed too, and that's a valid method of inputting/outputting a list (IMO)
– ASCII-only
yesterday
add a comment |
bash, 37 bytes or 24 bytes
f()(for x;{ r+=$[a[x]++] ;};echo $r)
TIO
if valid, there is also this variation, as suggested by DigitalTrauma
for x;{ echo $[a[x]++];}
TIO
bash, 37 bytes or 24 bytes
f()(for x;{ r+=$[a[x]++] ;};echo $r)
TIO
if valid, there is also this variation, as suggested by DigitalTrauma
for x;{ echo $[a[x]++];}
TIO
edited yesterday
answered 2 days ago
Nahuel FouilleulNahuel Fouilleul
1,64228
1,64228
1
Pass the list as command line args - tio.run/##S0oszvj/Py2/SKHCuporNTkjX0ElOjG6IlZbO5ar9v///8b/… - only 24 bytes.
– Digital Trauma
2 days ago
@DigitalTrauma, thanks however i don't know if it broke the rules. also as it was asked to replace list and maybe should be something like tio.run/…
– Nahuel Fouilleul
yesterday
2
@NahuelFouilleul It's fine, full programs are allowed too, and that's a valid method of inputting/outputting a list (IMO)
– ASCII-only
yesterday
add a comment |
1
Pass the list as command line args - tio.run/##S0oszvj/Py2/SKHCuporNTkjX0ElOjG6IlZbO5ar9v///8b/… - only 24 bytes.
– Digital Trauma
2 days ago
@DigitalTrauma, thanks however i don't know if it broke the rules. also as it was asked to replace list and maybe should be something like tio.run/…
– Nahuel Fouilleul
yesterday
2
@NahuelFouilleul It's fine, full programs are allowed too, and that's a valid method of inputting/outputting a list (IMO)
– ASCII-only
yesterday
1
1
Pass the list as command line args - tio.run/##S0oszvj/Py2/SKHCuporNTkjX0ElOjG6IlZbO5ar9v///8b/… - only 24 bytes.
– Digital Trauma
2 days ago
Pass the list as command line args - tio.run/##S0oszvj/Py2/SKHCuporNTkjX0ElOjG6IlZbO5ar9v///8b/… - only 24 bytes.
– Digital Trauma
2 days ago
@DigitalTrauma, thanks however i don't know if it broke the rules. also as it was asked to replace list and maybe should be something like tio.run/…
– Nahuel Fouilleul
yesterday
@DigitalTrauma, thanks however i don't know if it broke the rules. also as it was asked to replace list and maybe should be something like tio.run/…
– Nahuel Fouilleul
yesterday
2
2
@NahuelFouilleul It's fine, full programs are allowed too, and that's a valid method of inputting/outputting a list (IMO)
– ASCII-only
yesterday
@NahuelFouilleul It's fine, full programs are allowed too, and that's a valid method of inputting/outputting a list (IMO)
– ASCII-only
yesterday
add a comment |
Haskell, 47 46 bytes
(#(*0))
(x:r)#g=g x:r# y->0^(y-x)^2+g y
e#g=e
Try it online!
A different approach than BMO's answer which turned out a bit longer. (And kindly borrows their nice test suit.)
The idea is to iterate over the input list and keep track of the number of times each element has occurred by updating a function g
. Ungolfed:
f (const 0)
f g (x:r) = g x : f ( y -> if x==y then 1 + g y else g y) r
f g =
Two interesting golfing opportunities arose. First for the initial value of g
, a constant function which disregards its argument and returns 0
:
const 0 -- the idiomatic way
(_->0) -- can be shorter if parenthesis are not needed
min 0 -- only works as inputs are guaranteed to be non-negative
(0*) -- obvious in hindsight but took me a while to think of
And secondly an expression over variables x
and y
which yields 1
if x
equals y
and 0
otherwise:
if x==y then 1else 0 -- yes you don't need a space after the 1
fromEnum$x==y -- works because Bool is an instance of Enum
sum[1|x==y] -- uses that the sum of an empty list is zero
0^abs(x-y) -- uses that 0^0=1 and 0^x=0 for any positive x
0^(x-y)^2 -- Thanks to Christian Sievers!
There still might be shorter ways. Anyone got an idea?
1
You can use0^(x-y)^2
.
– Christian Sievers
8 hours ago
add a comment |
Haskell, 47 46 bytes
(#(*0))
(x:r)#g=g x:r# y->0^(y-x)^2+g y
e#g=e
Try it online!
A different approach than BMO's answer which turned out a bit longer. (And kindly borrows their nice test suit.)
The idea is to iterate over the input list and keep track of the number of times each element has occurred by updating a function g
. Ungolfed:
f (const 0)
f g (x:r) = g x : f ( y -> if x==y then 1 + g y else g y) r
f g =
Two interesting golfing opportunities arose. First for the initial value of g
, a constant function which disregards its argument and returns 0
:
const 0 -- the idiomatic way
(_->0) -- can be shorter if parenthesis are not needed
min 0 -- only works as inputs are guaranteed to be non-negative
(0*) -- obvious in hindsight but took me a while to think of
And secondly an expression over variables x
and y
which yields 1
if x
equals y
and 0
otherwise:
if x==y then 1else 0 -- yes you don't need a space after the 1
fromEnum$x==y -- works because Bool is an instance of Enum
sum[1|x==y] -- uses that the sum of an empty list is zero
0^abs(x-y) -- uses that 0^0=1 and 0^x=0 for any positive x
0^(x-y)^2 -- Thanks to Christian Sievers!
There still might be shorter ways. Anyone got an idea?
1
You can use0^(x-y)^2
.
– Christian Sievers
8 hours ago
add a comment |
Haskell, 47 46 bytes
(#(*0))
(x:r)#g=g x:r# y->0^(y-x)^2+g y
e#g=e
Try it online!
A different approach than BMO's answer which turned out a bit longer. (And kindly borrows their nice test suit.)
The idea is to iterate over the input list and keep track of the number of times each element has occurred by updating a function g
. Ungolfed:
f (const 0)
f g (x:r) = g x : f ( y -> if x==y then 1 + g y else g y) r
f g =
Two interesting golfing opportunities arose. First for the initial value of g
, a constant function which disregards its argument and returns 0
:
const 0 -- the idiomatic way
(_->0) -- can be shorter if parenthesis are not needed
min 0 -- only works as inputs are guaranteed to be non-negative
(0*) -- obvious in hindsight but took me a while to think of
And secondly an expression over variables x
and y
which yields 1
if x
equals y
and 0
otherwise:
if x==y then 1else 0 -- yes you don't need a space after the 1
fromEnum$x==y -- works because Bool is an instance of Enum
sum[1|x==y] -- uses that the sum of an empty list is zero
0^abs(x-y) -- uses that 0^0=1 and 0^x=0 for any positive x
0^(x-y)^2 -- Thanks to Christian Sievers!
There still might be shorter ways. Anyone got an idea?
Haskell, 47 46 bytes
(#(*0))
(x:r)#g=g x:r# y->0^(y-x)^2+g y
e#g=e
Try it online!
A different approach than BMO's answer which turned out a bit longer. (And kindly borrows their nice test suit.)
The idea is to iterate over the input list and keep track of the number of times each element has occurred by updating a function g
. Ungolfed:
f (const 0)
f g (x:r) = g x : f ( y -> if x==y then 1 + g y else g y) r
f g =
Two interesting golfing opportunities arose. First for the initial value of g
, a constant function which disregards its argument and returns 0
:
const 0 -- the idiomatic way
(_->0) -- can be shorter if parenthesis are not needed
min 0 -- only works as inputs are guaranteed to be non-negative
(0*) -- obvious in hindsight but took me a while to think of
And secondly an expression over variables x
and y
which yields 1
if x
equals y
and 0
otherwise:
if x==y then 1else 0 -- yes you don't need a space after the 1
fromEnum$x==y -- works because Bool is an instance of Enum
sum[1|x==y] -- uses that the sum of an empty list is zero
0^abs(x-y) -- uses that 0^0=1 and 0^x=0 for any positive x
0^(x-y)^2 -- Thanks to Christian Sievers!
There still might be shorter ways. Anyone got an idea?
edited 8 hours ago
answered 11 hours ago
LaikoniLaikoni
19.8k43699
19.8k43699
1
You can use0^(x-y)^2
.
– Christian Sievers
8 hours ago
add a comment |
1
You can use0^(x-y)^2
.
– Christian Sievers
8 hours ago
1
1
You can use
0^(x-y)^2
.– Christian Sievers
8 hours ago
You can use
0^(x-y)^2
.– Christian Sievers
8 hours ago
add a comment |
Retina 0.8.2, 30 bytes
b(d+)b(?<=(b1b.*?)+)
$#2
Try it online! Link includes test cases. 1-indexed. Explanation: The first part of the regex matches each integer in the list in turn. The lookbehind's group matches each occurrence of that integer on that line up to and including the current integer. The integer is then substituted with the number of matches.
add a comment |
Retina 0.8.2, 30 bytes
b(d+)b(?<=(b1b.*?)+)
$#2
Try it online! Link includes test cases. 1-indexed. Explanation: The first part of the regex matches each integer in the list in turn. The lookbehind's group matches each occurrence of that integer on that line up to and including the current integer. The integer is then substituted with the number of matches.
add a comment |
Retina 0.8.2, 30 bytes
b(d+)b(?<=(b1b.*?)+)
$#2
Try it online! Link includes test cases. 1-indexed. Explanation: The first part of the regex matches each integer in the list in turn. The lookbehind's group matches each occurrence of that integer on that line up to and including the current integer. The integer is then substituted with the number of matches.
Retina 0.8.2, 30 bytes
b(d+)b(?<=(b1b.*?)+)
$#2
Try it online! Link includes test cases. 1-indexed. Explanation: The first part of the regex matches each integer in the list in turn. The lookbehind's group matches each occurrence of that integer on that line up to and including the current integer. The integer is then substituted with the number of matches.
answered 2 days ago
NeilNeil
79.6k744177
79.6k744177
add a comment |
add a comment |
Batch, 61 bytes
@setlocal
@for %%n in (%*)do @set/ac=c%%n+=1&call echo %%c%%
1-indexed. Because variable substitution happens before parsing, the set/a
command ends up incrementing the variable name given by concatenating the letter c
with the integer from the list (numeric variables default to zero in Batch). The result is then copied to another integer for ease of output (more precisely, it saves a byte).
add a comment |
Batch, 61 bytes
@setlocal
@for %%n in (%*)do @set/ac=c%%n+=1&call echo %%c%%
1-indexed. Because variable substitution happens before parsing, the set/a
command ends up incrementing the variable name given by concatenating the letter c
with the integer from the list (numeric variables default to zero in Batch). The result is then copied to another integer for ease of output (more precisely, it saves a byte).
add a comment |
Batch, 61 bytes
@setlocal
@for %%n in (%*)do @set/ac=c%%n+=1&call echo %%c%%
1-indexed. Because variable substitution happens before parsing, the set/a
command ends up incrementing the variable name given by concatenating the letter c
with the integer from the list (numeric variables default to zero in Batch). The result is then copied to another integer for ease of output (more precisely, it saves a byte).
Batch, 61 bytes
@setlocal
@for %%n in (%*)do @set/ac=c%%n+=1&call echo %%c%%
1-indexed. Because variable substitution happens before parsing, the set/a
command ends up incrementing the variable name given by concatenating the letter c
with the integer from the list (numeric variables default to zero in Batch). The result is then copied to another integer for ease of output (more precisely, it saves a byte).
answered 2 days ago
NeilNeil
79.6k744177
79.6k744177
add a comment |
add a comment |
awk (46 bytes)
{delete(a);for(i=1;i<=NF;i++)$i=a[$i]++;print}
TIO
I think{for(;i++<NF;)$i=a[$i]++;print}
works.delete(a);
is only needed for the test suite, no?
– Dennis♦
6 hours ago
add a comment |
awk (46 bytes)
{delete(a);for(i=1;i<=NF;i++)$i=a[$i]++;print}
TIO
I think{for(;i++<NF;)$i=a[$i]++;print}
works.delete(a);
is only needed for the test suite, no?
– Dennis♦
6 hours ago
add a comment |
awk (46 bytes)
{delete(a);for(i=1;i<=NF;i++)$i=a[$i]++;print}
TIO
awk (46 bytes)
{delete(a);for(i=1;i<=NF;i++)$i=a[$i]++;print}
TIO
answered 2 days ago
Nahuel FouilleulNahuel Fouilleul
1,64228
1,64228
I think{for(;i++<NF;)$i=a[$i]++;print}
works.delete(a);
is only needed for the test suite, no?
– Dennis♦
6 hours ago
add a comment |
I think{for(;i++<NF;)$i=a[$i]++;print}
works.delete(a);
is only needed for the test suite, no?
– Dennis♦
6 hours ago
I think
{for(;i++<NF;)$i=a[$i]++;print}
works. delete(a);
is only needed for the test suite, no?– Dennis♦
6 hours ago
I think
{for(;i++<NF;)$i=a[$i]++;print}
works. delete(a);
is only needed for the test suite, no?– Dennis♦
6 hours ago
add a comment |
Tcl, 48 bytes
proc C L {lmap n $L {dict g [dict inc D $n] $n}}
Try it online!
add a comment |
Tcl, 48 bytes
proc C L {lmap n $L {dict g [dict inc D $n] $n}}
Try it online!
add a comment |
Tcl, 48 bytes
proc C L {lmap n $L {dict g [dict inc D $n] $n}}
Try it online!
Tcl, 48 bytes
proc C L {lmap n $L {dict g [dict inc D $n] $n}}
Try it online!
edited 2 days ago
answered 2 days ago
sergiolsergiol
2,5121925
2,5121925
add a comment |
add a comment |
Japt, 8 bytes
£¯YÄ è¶X
Try it here
£¯YÄ è¶X
:Implicit input of array U
£ :Map each X at 0-based index Y
¯ : Slice U to index
YÄ : Y+1
è : Count the elements
¶X : Equal to X
add a comment |
Japt, 8 bytes
£¯YÄ è¶X
Try it here
£¯YÄ è¶X
:Implicit input of array U
£ :Map each X at 0-based index Y
¯ : Slice U to index
YÄ : Y+1
è : Count the elements
¶X : Equal to X
add a comment |
Japt, 8 bytes
£¯YÄ è¶X
Try it here
£¯YÄ è¶X
:Implicit input of array U
£ :Map each X at 0-based index Y
¯ : Slice U to index
YÄ : Y+1
è : Count the elements
¶X : Equal to X
Japt, 8 bytes
£¯YÄ è¶X
Try it here
£¯YÄ è¶X
:Implicit input of array U
£ :Map each X at 0-based index Y
¯ : Slice U to index
YÄ : Y+1
è : Count the elements
¶X : Equal to X
edited 2 days ago
answered 2 days ago
ShaggyShaggy
19.2k21666
19.2k21666
add a comment |
add a comment |
Haxe, 58 bytes
l->{var x=[0=>0];l.map(e->++x[(x[e]==null?x[e]=0:0)+e]);};
(Requires arrow functions, so 4.0+)
var x=[0=>0]
declares a new IntMap
, with 0
as its only key (since the question say inputs are strictly positive). Unfortunately most targets throw when adding null
to a number, hence the explicit check to make sure each key is in the map before incrementing.
Also a cheeky rip off based on the JS answer:
Haxe (JS target), 41 bytes
l->{var x=[0=>0];l.map(e->x[e]=-~x[e]);};
Try both online
add a comment |
Haxe, 58 bytes
l->{var x=[0=>0];l.map(e->++x[(x[e]==null?x[e]=0:0)+e]);};
(Requires arrow functions, so 4.0+)
var x=[0=>0]
declares a new IntMap
, with 0
as its only key (since the question say inputs are strictly positive). Unfortunately most targets throw when adding null
to a number, hence the explicit check to make sure each key is in the map before incrementing.
Also a cheeky rip off based on the JS answer:
Haxe (JS target), 41 bytes
l->{var x=[0=>0];l.map(e->x[e]=-~x[e]);};
Try both online
add a comment |
Haxe, 58 bytes
l->{var x=[0=>0];l.map(e->++x[(x[e]==null?x[e]=0:0)+e]);};
(Requires arrow functions, so 4.0+)
var x=[0=>0]
declares a new IntMap
, with 0
as its only key (since the question say inputs are strictly positive). Unfortunately most targets throw when adding null
to a number, hence the explicit check to make sure each key is in the map before incrementing.
Also a cheeky rip off based on the JS answer:
Haxe (JS target), 41 bytes
l->{var x=[0=>0];l.map(e->x[e]=-~x[e]);};
Try both online
Haxe, 58 bytes
l->{var x=[0=>0];l.map(e->++x[(x[e]==null?x[e]=0:0)+e]);};
(Requires arrow functions, so 4.0+)
var x=[0=>0]
declares a new IntMap
, with 0
as its only key (since the question say inputs are strictly positive). Unfortunately most targets throw when adding null
to a number, hence the explicit check to make sure each key is in the map before incrementing.
Also a cheeky rip off based on the JS answer:
Haxe (JS target), 41 bytes
l->{var x=[0=>0];l.map(e->x[e]=-~x[e]);};
Try both online
answered 2 days ago
Aurel BílýAurel Bílý
1,07398
1,07398
add a comment |
add a comment |
GO 121 Bytes (Not included new lines and tabs)
func cg(a int) int{
var m = make(map[int]int)
var r = make(int, len(a))
for i,v := range a{
r[i] = m[v]
m[v]++
}
return r
}
Accepts integer array and returns integer array.
New contributor
3
Welcome to PPCG. Rare to see Go represented here. You do need to count necessary newlines, but you also have a lot of spaces that can be removed, and you can also shortencg
toc
. I recommend using TIO to generate the main part of your post: Try it online!
– Adám
yesterday
add a comment |
GO 121 Bytes (Not included new lines and tabs)
func cg(a int) int{
var m = make(map[int]int)
var r = make(int, len(a))
for i,v := range a{
r[i] = m[v]
m[v]++
}
return r
}
Accepts integer array and returns integer array.
New contributor
3
Welcome to PPCG. Rare to see Go represented here. You do need to count necessary newlines, but you also have a lot of spaces that can be removed, and you can also shortencg
toc
. I recommend using TIO to generate the main part of your post: Try it online!
– Adám
yesterday
add a comment |
GO 121 Bytes (Not included new lines and tabs)
func cg(a int) int{
var m = make(map[int]int)
var r = make(int, len(a))
for i,v := range a{
r[i] = m[v]
m[v]++
}
return r
}
Accepts integer array and returns integer array.
New contributor
GO 121 Bytes (Not included new lines and tabs)
func cg(a int) int{
var m = make(map[int]int)
var r = make(int, len(a))
for i,v := range a{
r[i] = m[v]
m[v]++
}
return r
}
Accepts integer array and returns integer array.
New contributor
New contributor
answered 2 days ago
rock starrock star
101
101
New contributor
New contributor
3
Welcome to PPCG. Rare to see Go represented here. You do need to count necessary newlines, but you also have a lot of spaces that can be removed, and you can also shortencg
toc
. I recommend using TIO to generate the main part of your post: Try it online!
– Adám
yesterday
add a comment |
3
Welcome to PPCG. Rare to see Go represented here. You do need to count necessary newlines, but you also have a lot of spaces that can be removed, and you can also shortencg
toc
. I recommend using TIO to generate the main part of your post: Try it online!
– Adám
yesterday
3
3
Welcome to PPCG. Rare to see Go represented here. You do need to count necessary newlines, but you also have a lot of spaces that can be removed, and you can also shorten
cg
to c
. I recommend using TIO to generate the main part of your post: Try it online!– Adám
yesterday
Welcome to PPCG. Rare to see Go represented here. You do need to count necessary newlines, but you also have a lot of spaces that can be removed, and you can also shorten
cg
to c
. I recommend using TIO to generate the main part of your post: Try it online!– Adám
yesterday
add a comment |
C++,137 bytes
//v is input , ov is output ; //example to populate v: vector v{7,8,7};
vector<int> v,ov(v.size());map<int,int>m;transform(begin(v),end(v),begin(ov),[&m](int i){!m.count(i)?m[i]=0:m[i]+=1;return m[i];});
New contributor
I'm not sure about C++, but can't you remove the newlines to save 2 bytes?
– Stephen
2 days ago
1
I don't know C++ either, but what is this? It doesn't look like a function, and I don't see how you take input?
– Jo King
yesterday
You can't take input via a predefined variable, otherwise this becomes a snippet. Submissions have to be a full program or a function
– Jo King
11 hours ago
add a comment |
C++,137 bytes
//v is input , ov is output ; //example to populate v: vector v{7,8,7};
vector<int> v,ov(v.size());map<int,int>m;transform(begin(v),end(v),begin(ov),[&m](int i){!m.count(i)?m[i]=0:m[i]+=1;return m[i];});
New contributor
I'm not sure about C++, but can't you remove the newlines to save 2 bytes?
– Stephen
2 days ago
1
I don't know C++ either, but what is this? It doesn't look like a function, and I don't see how you take input?
– Jo King
yesterday
You can't take input via a predefined variable, otherwise this becomes a snippet. Submissions have to be a full program or a function
– Jo King
11 hours ago
add a comment |
C++,137 bytes
//v is input , ov is output ; //example to populate v: vector v{7,8,7};
vector<int> v,ov(v.size());map<int,int>m;transform(begin(v),end(v),begin(ov),[&m](int i){!m.count(i)?m[i]=0:m[i]+=1;return m[i];});
New contributor
C++,137 bytes
//v is input , ov is output ; //example to populate v: vector v{7,8,7};
vector<int> v,ov(v.size());map<int,int>m;transform(begin(v),end(v),begin(ov),[&m](int i){!m.count(i)?m[i]=0:m[i]+=1;return m[i];});
New contributor
edited yesterday
New contributor
answered 2 days ago
qqqqqqqqqq
1012
1012
New contributor
New contributor
I'm not sure about C++, but can't you remove the newlines to save 2 bytes?
– Stephen
2 days ago
1
I don't know C++ either, but what is this? It doesn't look like a function, and I don't see how you take input?
– Jo King
yesterday
You can't take input via a predefined variable, otherwise this becomes a snippet. Submissions have to be a full program or a function
– Jo King
11 hours ago
add a comment |
I'm not sure about C++, but can't you remove the newlines to save 2 bytes?
– Stephen
2 days ago
1
I don't know C++ either, but what is this? It doesn't look like a function, and I don't see how you take input?
– Jo King
yesterday
You can't take input via a predefined variable, otherwise this becomes a snippet. Submissions have to be a full program or a function
– Jo King
11 hours ago
I'm not sure about C++, but can't you remove the newlines to save 2 bytes?
– Stephen
2 days ago
I'm not sure about C++, but can't you remove the newlines to save 2 bytes?
– Stephen
2 days ago
1
1
I don't know C++ either, but what is this? It doesn't look like a function, and I don't see how you take input?
– Jo King
yesterday
I don't know C++ either, but what is this? It doesn't look like a function, and I don't see how you take input?
– Jo King
yesterday
You can't take input via a predefined variable, otherwise this becomes a snippet. Submissions have to be a full program or a function
– Jo King
11 hours ago
You can't take input via a predefined variable, otherwise this becomes a snippet. Submissions have to be a full program or a function
– Jo King
11 hours ago
add a comment |
Python 2, 44 bytes
a=
for x in input():print a.count(x);a+=x,
Try it online!
The first thing I wrote tied Chas Brown's 43, so here's a different solution that's one byte longer.
add a comment |
Python 2, 44 bytes
a=
for x in input():print a.count(x);a+=x,
Try it online!
The first thing I wrote tied Chas Brown's 43, so here's a different solution that's one byte longer.
add a comment |
Python 2, 44 bytes
a=
for x in input():print a.count(x);a+=x,
Try it online!
The first thing I wrote tied Chas Brown's 43, so here's a different solution that's one byte longer.
Python 2, 44 bytes
a=
for x in input():print a.count(x);a+=x,
Try it online!
The first thing I wrote tied Chas Brown's 43, so here's a different solution that's one byte longer.
answered yesterday
LynnLynn
49.5k794227
49.5k794227
add a comment |
add a comment |
Reticular, 17 bytes
L[ddc@c~]~*$qlbo;
Try it online!
The input list of integers is assumed to already be pushed to the stack. Run the following code to test input:
'2''7''1''8''2''8''1''8''2''8'lbL[ddc@c~]~*$qlbo;
Explanation
The pop instruction c
which is supposed to: pop a list from the stack, pop the last element from that list and push this element to the stack. However, if the list occurs at more than 1 place in the stack (if it has been duplicated for example), all of the duplicated lists in the stack will also have their last element popped contrary to what one might think will happen. This is fortunately used in our favor in this puzzle.
L # Push length of input list to the stack.
[ ] # Push the following function:
dd # Duplicate top of stack twice.
c # Pop the list at top of the stack,
pop the last element in the list (which will pop the element of every list!)
and finally push it to the stack.
@c # Pop two items at the top of the stack (list + last element in that list).
then push the number of occurrences of that element in the list.
~ # Swap top two items in the stack (so that the popped list is on top again).
~ # Swap top two items in the stack.
* # Call the above function the same number of times as length of the input list.
$ # Remove the item at the top of the stack (which by now is an empty list).
q # Reverse stack.
lb # Push size of stack and put that many items from the stack into a list.
o; # Output resulting list and exit.
add a comment |
Reticular, 17 bytes
L[ddc@c~]~*$qlbo;
Try it online!
The input list of integers is assumed to already be pushed to the stack. Run the following code to test input:
'2''7''1''8''2''8''1''8''2''8'lbL[ddc@c~]~*$qlbo;
Explanation
The pop instruction c
which is supposed to: pop a list from the stack, pop the last element from that list and push this element to the stack. However, if the list occurs at more than 1 place in the stack (if it has been duplicated for example), all of the duplicated lists in the stack will also have their last element popped contrary to what one might think will happen. This is fortunately used in our favor in this puzzle.
L # Push length of input list to the stack.
[ ] # Push the following function:
dd # Duplicate top of stack twice.
c # Pop the list at top of the stack,
pop the last element in the list (which will pop the element of every list!)
and finally push it to the stack.
@c # Pop two items at the top of the stack (list + last element in that list).
then push the number of occurrences of that element in the list.
~ # Swap top two items in the stack (so that the popped list is on top again).
~ # Swap top two items in the stack.
* # Call the above function the same number of times as length of the input list.
$ # Remove the item at the top of the stack (which by now is an empty list).
q # Reverse stack.
lb # Push size of stack and put that many items from the stack into a list.
o; # Output resulting list and exit.
add a comment |
Reticular, 17 bytes
L[ddc@c~]~*$qlbo;
Try it online!
The input list of integers is assumed to already be pushed to the stack. Run the following code to test input:
'2''7''1''8''2''8''1''8''2''8'lbL[ddc@c~]~*$qlbo;
Explanation
The pop instruction c
which is supposed to: pop a list from the stack, pop the last element from that list and push this element to the stack. However, if the list occurs at more than 1 place in the stack (if it has been duplicated for example), all of the duplicated lists in the stack will also have their last element popped contrary to what one might think will happen. This is fortunately used in our favor in this puzzle.
L # Push length of input list to the stack.
[ ] # Push the following function:
dd # Duplicate top of stack twice.
c # Pop the list at top of the stack,
pop the last element in the list (which will pop the element of every list!)
and finally push it to the stack.
@c # Pop two items at the top of the stack (list + last element in that list).
then push the number of occurrences of that element in the list.
~ # Swap top two items in the stack (so that the popped list is on top again).
~ # Swap top two items in the stack.
* # Call the above function the same number of times as length of the input list.
$ # Remove the item at the top of the stack (which by now is an empty list).
q # Reverse stack.
lb # Push size of stack and put that many items from the stack into a list.
o; # Output resulting list and exit.
Reticular, 17 bytes
L[ddc@c~]~*$qlbo;
Try it online!
The input list of integers is assumed to already be pushed to the stack. Run the following code to test input:
'2''7''1''8''2''8''1''8''2''8'lbL[ddc@c~]~*$qlbo;
Explanation
The pop instruction c
which is supposed to: pop a list from the stack, pop the last element from that list and push this element to the stack. However, if the list occurs at more than 1 place in the stack (if it has been duplicated for example), all of the duplicated lists in the stack will also have their last element popped contrary to what one might think will happen. This is fortunately used in our favor in this puzzle.
L # Push length of input list to the stack.
[ ] # Push the following function:
dd # Duplicate top of stack twice.
c # Pop the list at top of the stack,
pop the last element in the list (which will pop the element of every list!)
and finally push it to the stack.
@c # Pop two items at the top of the stack (list + last element in that list).
then push the number of occurrences of that element in the list.
~ # Swap top two items in the stack (so that the popped list is on top again).
~ # Swap top two items in the stack.
* # Call the above function the same number of times as length of the input list.
$ # Remove the item at the top of the stack (which by now is an empty list).
q # Reverse stack.
lb # Push size of stack and put that many items from the stack into a list.
o; # Output resulting list and exit.
answered 7 hours ago
WisławWisław
1113
1113
add a comment |
add a comment |
SNOBOL4 (CSNOBOL4), 63 bytes
T =TABLE()
R I =INPUT :F(END)
T<I> =OUTPUT =T<I> + 1 :(R)
END
Try it online!
add a comment |
SNOBOL4 (CSNOBOL4), 63 bytes
T =TABLE()
R I =INPUT :F(END)
T<I> =OUTPUT =T<I> + 1 :(R)
END
Try it online!
add a comment |
SNOBOL4 (CSNOBOL4), 63 bytes
T =TABLE()
R I =INPUT :F(END)
T<I> =OUTPUT =T<I> + 1 :(R)
END
Try it online!
SNOBOL4 (CSNOBOL4), 63 bytes
T =TABLE()
R I =INPUT :F(END)
T<I> =OUTPUT =T<I> + 1 :(R)
END
Try it online!
answered 7 hours ago
GiuseppeGiuseppe
16.6k31052
16.6k31052
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%2f178500%2fenumerate-each-series-of-identical-numbers-in-place%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
2
So basically the number of times it has appeared the sequence so far?
– Jo King
2 days ago
1
@JoKing Yes, that's another way to state it, but "so far" implies zero-based, and "until and including this" implies one-based. I wanted to keep the choice.
– Adám
2 days ago