C 340 362 166 115 Bytes
Hello all. My first time here. I figured since I enjoy (attempting) to write optimized code I may as well give this a try.
@Rodney - ~39 bytes from the includes
@Zacharý - 7 bytes with implicit typing
0-indexed.
How to Run:
As per @Arnolds suggestion, the program takes arguments in a much more C friendly manner. This let me reduce the size of the file by a little more than half.
The arguments should be passed in the following order value [element1 ...]
where braces indicate optional arguments
You may or may not have to add escaped quotes to any strings that are provided in order to satisfy the condition of 12 != "12"
. On my system the this can be done in the following manner
prog-name.exe 12 3 "Hello" 12 4 "12"
Returns [2,4] < This is incorrect
prog-name.exe 12 3 "\"Hello\"" 12 4 "\"12\""
Returns [2] < Correct
golfed
#define P printf(
b=0;main(int c,char**v){P"[");for(--c;c-1;c--)b|=strcmp(v[1],v[c])?0:P b?",%i":"%i",c-2);P"]");}
ungolfed
#define P printf(
//Implicit only works in global(I totally knew this after almost 4 years of C :P)
b = 0;
main(int c,char**v)
{
P"[");
//match loop
//b is used to determine if this is the first iteration. it can be assumed that printf will always return >0
//subract two from c to get correct index number of match
for(--c; c-1; c--)
b |= strcmp(v[1], v[c]) ? 0 : P b ? ",%i" : "%i", c-2);
P"]");
return 0;
}