Given an alphabet represented as a nonempty set of positive integers, and a word made up of symbols from that alphabet, find that word's position in the lexicographically ordered set of all words, assuming words can't contain duplicate symbols.
Example
Consider the alphabet {1, 2, 3} and the word [2, 3, 1]. The set of all possible words, ordered via lexicographic order is
{ [1], [1, 2], [1, 2, 3], [1, 3], [1, 3, 2], [2], [2, 1], [2, 1, 3], [2, 3], [2, 3, 1], [3], [3, 1], [3, 1, 2], [3, 2], [3, 2, 1] } [2, 3, 1] is the tenth element in the set, so the answer is 10 (9 if you use zero indexing).
Input/Output
Input can be taken in any reasonable format, including taking the alphabet as a sorted list, or taking the alphabet/word as a string.
Output can be zero or one indexed, please say which one you choose in your answer.
This is code-golf, so the shortest answer wins.
Testcases
One indexed:
alphabet, word -> location (1 indexed) {1, 2, 3} , [] -> undefined {1, 2, 3}, [1] -> 1 {1, 2, 3}, [3] -> 11 {1, 2, 3}, [2, 3, 1] -> 10 {1, 2, 3}, [3, 2, 1] -> 15 {1, 3, 4, 6}, [3, 1, 4] -> 19 {1, 3, 4, 6}, [3, 1, 6, 4] -> 22 {1,3, 4, 16, 23, 37, 43, 57}, [37, 43, 16, 3] -> 79332 {41, 57, 60, 61, 71, 80, 113, 125, 131, 139, 141, 184, 197, 200, 201, 214, 215, 216, 223, 236, 238, 240, 244, 252, 264, 279, 300, 335, 340, 393, 410, 414, 421, 436, 441, 447, 461, 466, 483, 490, 525, 537, 540, 543, 547, 551, 552, 557, 569, 583, 584, 591, 593, 595, 596, 607, 610, 613, 614, 620, 621, 634, 637, 643, 652, 683, 691, 713, 726, 733, 738, 750, 757, 767, 777, 789, 803, 812, 813, 817, 844, 850, 856, 878, 901, 910, 926, 947, 949, 951, 953, 958, 962, 969, 982, 995}, [252, 300, 969, 844, 856, 713, 60, 621, 393, 637, 634, 441, 817, 264, 551, 757, 926, 240, 461, 421, 767, 726, 223, 610, 547, 141, 593, 184, 200, 643, 583, 614, 958, 540, 201, 214, 584, 591, 525, 652, 466, 414, 995, 125, 813, 951, 901, 215, 947, 410, 113, 279, 238, 57, 750, 607, 61, 131, 216, 340, 569, 803, 557, 878, 691, 80, 850, 483, 71, 613, 41, 244, 789, 595, 447, 596, 812, 543, 953, 620, 962, 436, 537, 733, 738, 197, 949, 982, 139, 683, 910, 236, 552, 490, 777, 335] -> 653513463887666116337968717018588523734749776398084200209718028326146195147009645472571018754197481757464478858415475671625444580437153140577102475638 Zero indexed:
alphabet, word -> location (0 indexed) {1, 2, 3} , [] -> undefined {1, 2, 3}, [1] -> 0 {1, 2, 3}, [3] -> 10 {1, 2, 3}, [2, 3, 1] -> 9 {1, 2, 3}, [3, 2, 1] -> 14 {1, 3, 4, 6}, [3, 1, 4] -> 18 {1, 3, 4, 6}, [3, 1, 6, 4] -> 21 {1,3, 4, 16, 23, 37, 43, 57}, [37, 43, 16, 3] -> 79331 {41, 57, 60, 61, 71, 80, 113, 125, 131, 139, 141, 184, 197, 200, 201, 214, 215, 216, 223, 236, 238, 240, 244, 252, 264, 279, 300, 335, 340, 393, 410, 414, 421, 436, 441, 447, 461, 466, 483, 490, 525, 537, 540, 543, 547, 551, 552, 557, 569, 583, 584, 591, 593, 595, 596, 607, 610, 613, 614, 620, 621, 634, 637, 643, 652, 683, 691, 713, 726, 733, 738, 750, 757, 767, 777, 789, 803, 812, 813, 817, 844, 850, 856, 878, 901, 910, 926, 947, 949, 951, 953, 958, 962, 969, 982, 995}, [252, 300, 969, 844, 856, 713, 60, 621, 393, 637, 634, 441, 817, 264, 551, 757, 926, 240, 461, 421, 767, 726, 223, 610, 547, 141, 593, 184, 200, 643, 583, 614, 958, 540, 201, 214, 584, 591, 525, 652, 466, 414, 995, 125, 813, 951, 901, 215, 947, 410, 113, 279, 238, 57, 750, 607, 61, 131, 216, 340, 569, 803, 557, 878, 691, 80, 850, 483, 71, 613, 41, 244, 789, 595, 447, 596, 812, 543, 953, 620, 962, 436, 537, 733, 738, 197, 949, 982, 139, 683, 910, 236, 552, 490, 777, 335] -> 653513463887666116337968717018588523734749776398084200209718028326146195147009645472571018754197481757464478858415475671625444580437153140577102475637 Note: This challenge is loosely based upon an old weekly challenge on replit.
