g | x | w | all
Bytes Lang Time Link
032Java240522T224647ZUnmitiga
420Nibbles240522T221110ZDLosc
080AWK240522T175035ZC K
025Arturo240522T083504Zchunes
001Uiua231114T234643Zchunes
005R170501T175610ZGiuseppe
056PHP170501T180509ZJör
034Perl 5170501T202550ZChris
001APL Dyalog170501T174447Zuser4180
025Clojure170502T091427ZNikoNyrh
080Java 7170502T080455ZKevin Cr
051Bash + coreutils170501T231155ZDigital
032Haskell170501T221611Zxnor
032C#170501T200553ZMetaColo
030Retina170501T175922ZBusiness
034Haskell170501T191551Znimi
043Haskell170501T191339ZDoorknob
002MATL170501T175901ZLuis Men
081Java170501T174942ZLeaky Nu
026V170501T180123ZDJMcMayh
004Japt170501T181622ZETHprodu
001k170501T175520Zskeevey
025Python 2170501T175247ZLeaky Nu
nan170501T175141ZBrad Gil
004CJam170501T175109ZBusiness
028JavaScript ES6170501T174937ZArnauld
025Octave170501T174900Zrahnema1
025Mathematica170501T174706ZMartin E
002J170501T174423ZLeaky Nu
003Jelly170501T173800ZLeaky Nu
00505AB1E170501T174020ZRiley
004Pyth170501T174016ZLeaky Nu

Java, 32 bytes

n->m->n.stream().map(m::indexOf)

Returns a 0-indexed Stream of Integers.

Try it online!

Nibbles, 4 nibbles (2.0 bytes)

.$?_

Uses 1-based indices. Attempt This Online!

Explanation

.$?_$
.      Map the following function over
 $     the first program argument:
  ?     Find the index of
    $   the function argument
   _    in the second program argument

The final $ is inferred if omitted.

AWK, 80 bytes

{ORS="";split($1,n,"");split($2,m,"");for(i in n)for(j in m)print n[i]~m[j]?j:X}

Try it online!

Example:

echo "5341 6841253" | awk '{ORS="";split($1,n,"");split($2,m,"");for(i in n)for(j in m)print n[i]~m[j]?j:X}'
6734

Arturo, 25 bytes

$[n,m]->map n=>[index m&]

Try it

Uiua, 1 byte

Try it!

0-indexed.

R, 20 5 bytes

1-indexed; match is the builtin function that finds the indices in the second input of the elements of the first, i.e., match(n,m) gives the desired answer

match

thanks to @flodel for pointing out that returning a function is perfectly acceptable as an answer!

Try it online!

PHP, 56 Bytes

Online Versions

0 Indexing

output as String

<?foreach($_GET[0]as$v)echo" ".array_flip($_GET[1])[$v];

PHP, 65 Bytes

Output as array

<?foreach($_GET[0]as$v)$r[]=array_flip($_GET[1])[$v];print_r($r);

PHP, 78 Bytes

workaround with array_map

<?print_r(array_map(function($v){return array_flip($_GET[1])[$v];},$_GET[0]));

for not unique arrays replace with array_flip($_GET[1])[$v] array_search($v,$_GET[1])

Perl 5, 38 34 bytes

4 bytes saved thanks to Dada

sub{map$x{$_}//($x{$_}=++$x)x0,@_}

1-indexed. Takes the lists m and n as a single list, like f(@m,@n). The x0 is just to keep the output from starting with 1,2,3,4,5, etc.

APL (Dyalog), 1 byte

Try it online!

Note: the function does not take scalars as its left argument, so to give it a left argument like 54, you have to make it into an array using , like so (,54).

Clojure, 25 bytes

#(map(zipmap %2(range))%)

0-indexed.

Java 7, 80 bytes

void c(int[]a,java.util.List b){for(int i=0;i<a.length;a[i]=b.indexOf(a[i++]));}

0-indexed

Explanation:

void c(int[]a,java.util.List b){  // Method with integer-array and List parameters
  for(int i=0;i<a.length;         //  Loop over the integer-array
    a[i]=b.indexOf(a[i++])        //   And change every value to the index of the List
  );                              //  End of loop (no body)
}                                 // End of method

Test code:

Try it here.

import java.util.Arrays;
class M{
  static void c(int[]a,java.util.List b){for(int i=0;i<a.length;a[i]=b.indexOf(a[i++]));}

  public static void main(String[] a){
    int[] x = new int[]{ 5, 3, 4, 1 };
    c(x, Arrays.asList(6, 8, 4, 1, 2, 5, 3, 100));
    System.out.println(Arrays.toString(x));
    
    x = new int[]{ 5, 3, 4, 9, 7, 5, 7 };
    c(x, Arrays.asList(3, 4, 5, 7, 9));
    System.out.println(Arrays.toString(x));

    x = new int[]{ 1, 2, 3, 4, 5, 6 };
    c(x, Arrays.asList(1, 2, 3, 4, 5, 6));
    System.out.println(Arrays.toString(x));
    

    x = new int[]{ 16, 27, 18, 12, 6, 26, 11, 24, 26, 20, 2, 8, 7, 12, 5, 22, 22, 2, 17, 4 };
    c(x, Arrays.asList(15, 18, 11, 16, 14, 20, 37, 38, 6, 36, 8, 32, 21, 2, 31, 22, 33, 4, 1, 35, 3, 25, 9, 30, 26, 39, 5, 23, 29, 10, 13, 12, 7, 19, 24, 17, 34, 27, 40, 28));
    System.out.println(Arrays.toString(x));
    

    x = new int[]{ 54 };
    c(x, Arrays.asList(54));
    System.out.println(Arrays.toString(x));
  }
}

Output:

[5, 6, 2, 3]
[2, 0, 1, 4, 3, 2, 3]
[0, 1, 2, 3, 4, 5]
[3, 37, 1, 31, 8, 24, 2, 34, 24, 5, 13, 10, 32, 31, 26, 15, 15, 13, 35, 17]
[0]

Bash + coreutils, 51

for n in $1
do grep -wn $n <<<"$2"
done|cut -d: -f1

Try it online.


Previous answer:

s()(sort -$1k2)
nl|s|join -j2 - <(nl<<<"$1"|s)|s n|cut -d\  -f3

Try it online.

Haskell, 32 bytes

a%b=[length$fst$span(/=x)b|x<-a]

Try it online! One-indexed.

Other attempts:

q(h:t)x|x==h=0|1>0=1+q t x;map.q
f b=map$length.fst.($b).span.(/=)
a%b=[until((==x).(b!!))(+1)0|x<-a]
a%b=[until(\y->x==b!!y)(+1)0|x<-a]
import Data.List;map.flip elemIndex

C#, 32 Bytes

(n,m)=>n.Select(i=>m.IndexOf(i))

This is the code as a lambda expression, so it should be valid.

The solution is with a 0 based index. I think it's pretty straigt forward how it works - it simply takes the items of n and selects the indices of the items in m.

Retina, 32 31 30 bytes

1 byte saved thanks to Kritixi Lithos and 1 byte thanks to Martin Ender

(\d+)(?=.*¶(\d+ )*\1 )
$#2
G1`

Uses 0-indexing. Input has a trailing space on each line.

Try it online!

Explanation

(\d+)(?=.*¶(\d+ )*\1 )
$#2

Here we replace every number on the first line by the number of numbers before the same number on the second line.

G1`

Then, we delete the second line, leaving only the new first line as the output.

Haskell, 34 bytes

n#m=[i|a<-n,(i,e)<-zip[1..]m,e==a]

Usage example: [5,3,4,9,7,5,7] # [3,4,5,7,9] -> [3,1,2,5,4,3,4]

The built-in elemIndex is in Data.List and therefore longer than the version above. The outer loop goes through n and the inner loop through pairs of (i,e) where i is the index of e in m. Keep the i where e equals the current element of n.

Haskell, 43 bytes

a*b=[[fst x|x<-zip[0..]b,y==snd x]!!0|y<-a]
a*b=                                         -- define function * with 2 args
    [                                |y<-a]  -- for each elt in first arg
               zip[0..]b                     -- match elts in second arg w/ idxs
                                             -- [a,b,c] -> [[0,a],[1,b],[2,c]]
     [fst x|x<-                  ]           -- take first element in each pair
                        ,y==snd x            -- if the index matches
                                  !!0        -- first element (always only 1)

MATL, 2 bytes

&m

This uses 1-indexing. Try it online!

Explanation

The meta-function & indicates that the next function will use a (function-specific) secondary default in/out specification. For function m (ismember), & specifies that its second output will be produced. This contains the index of (the first occurrence of) each entry of the first input in the second input.

Java, 104 81 bytes

1 byte thanks to Business cat.

void f(int[]a,int[]b){for(int i=0,j=0;i<b.length;)j=a[j++]==b[i]?0*(b[i++]=j):j;}

Try it online!

V, 26 bytes

jòdf kÄ/-
DÓÓ
ÒC1@"Gòdk

Try it online!

This is a very strange and hacky solution, because V has little to no concept of numbers. Input comes in this format:

6 8 4 1 2 5 3 100 
5 3 4 1 

With a trailing space on each line.

Hexdump:

00000000: 6af2 6466 206b c42f 122d 0a44 d3d3 0ad2  j.df k./.-.D....
00000010: 0143 311b 4022 47f2 646b                 .C1.@"G.dk

Explanation:

j                   " Move down one line (to N) (1)
 ò                  " Recursively:
  df                "   (d)elete until you (f)ind a space. This will be saved into
                    "   register '-' (2)
     k              "   Move up one line (to M)
      Ä             "   Duplicate line M (3)
       /<C-r>-      "   Move the cursor forward until the next occurence of register '-' 
                    "   (the number we deleted from N)
                    "   (4)
D                   "   Delete every character *after* the cursor (5)
 ÓÓ                 "   Remove everything on this line except for whitespace
Ò<C-a>              "   Replace every character on this line with `<C-a>`, which is the 
                    "   command for incrementing a number (6)
      C             "   Delete this line into register '"', and enter insert mode
       1<esc>       "   Enter a '1' and return to normal mode
             @"     "   Run register '"' as V code (7)
               G    "   Go to the last line (1)
                ò   " End recursion
                 dk " Delete the last two lines (m and n)

If this doesn't make it clearer, here are examples of the buffer during the various stages the loop goes through:

Stage 1 (| is the cursor)

6 8 4 1 2 5 3 100
|5 3 4 1

Stage 2:

6 8 4 1 2 5 3 100
|3 4 1

Stage 3:

|6 8 4 1 2 5 3 100
6 8 4 1 2 5 3 100
3 4 1

Stage 4:

6 8 4 1 2 |5 3 100
6 8 4 1 2 5 3 100
3 4 1

Stage 5:

6 8 4 1 2 |
6 8 4 1 2 5 3 100
3 4 1

Stage 6:

|<C-a><C-a><C-a><C-a><C-a>
6 8 4 1 2 5 3 100
3 4 1

Stage 7:

|6
6 8 4 1 2 5 3 100
3 4 1

Back to stage 1:

6
6 8 4 1 2 5 3 100
|3 4 1

Japt, 4 bytes

m!bV

Test it online!

Explanation

There's not much to explain here, but it shows off an interesting feature of Japt. Normally, you would pass a function to m, like so:

mX{VbX}

This is basically U.map(X => V.indexOf(X)) (the U is implicit). However, when you're just performing one operation between two values (b here, on V and X), you can just give the operator and the other value and Japt will make a function out of it. This means mX{X+2} can be golfed to m+2.

However, this doesn't work when the values are in the wrong order (mbV would be short for mX{XbV}). To get around this, you can prepend an exclamation mark to the operator, which tells Japt to swap the operands. This costs an extra byte, but it's still a couple bytes shorter than the alternative. And now you know a little more about Japt.

k, 1

This is a built-in operator in k and uses zero-based indexing.

?

Example:

k)6 8 4 1 2 5 3 100 ? 5 3 4 1
5 6 2 3

Python 2, 25 bytes

lambda a,b:map(a.index,b)

Try it online!

Note that this uses 0-indexing.

Perl 6, 31 bytes

->\n,\m{n.map:{m.first($_,:k)}}

Try it

Expanded:

-> \n, \m {  # pointy block lambda

  n.map: {            # map over the values in 「n」
    m.first( $_, :k ) # return the key 「:k」 of the first occurrence
  }
}

0 indexed

CJam, 4 bytes

{f#}

Anonymous block that expects arguments on the stack and leaves the result on the stack.

Uses 0-indexing.

Try it online!

JavaScript (ES6), 28 bytes

Takes the arrays in currying syntax (n)(m). 0-indexed.

let f =

n=>m=>n.map(v=>m.indexOf(v))

console.log(JSON.stringify(f([5,3,4,1])([6,8,4,1,2,5,3,100])))
console.log(JSON.stringify(f([5,3,4,9,7,5,7])([3,4,5,7,9])))
console.log(JSON.stringify(f([1,2,3,4,5,6])([1,2,3,4,5,6])))
console.log(JSON.stringify(f([16,27,18,12,6,26,11,24,26,20,2,8,7,12,5,22,22,2,17,4])([15,18,11,16,14,20,37,38,6,36,8,32,21,2,31,22,33,4,1,35,3,25,9,30,26,39,5,23,29,10,13,12,7,19,24,17,34,27,40,28])))
console.log(JSON.stringify(f([54])([54])))

Octave, 25 bytes

@(n,m)([x,~]=find(n==m'))

Try it online!

Mathematica, 25 bytes

#&@@@PositionIndex@#/@#2&

Takes two inputs m and n, and returns the 1-based indices of n in m.

J, 2 bytes

i.

This is not a complete program, but a built-in function.

Use it as such:

echo 6 8 4 1 2 5 3 100 i. 5 3 4 1

Try it online!

Note that this uses 0-indexing.

Jelly, 3 bytes

iЀ

Try it online!

Specs

05AB1E, 5 bytes

v²yk,

Try it online!

v     # For each value in n (call it y)
 ²    # Push m
  y   # Push y
   k, # Print the 0-indexed index of y in m

Pyth, 4 bytes

xLQE

Try it online!

Note that this uses 0-indexing.