Matchmaker, Matchmaker, make me a matchFivenum and a little bitGeneralised Array RiffleAre these trees isomorphic?Generate a looping arrayFind the indices of values in one list in anotherIs this a function?Compare the averages of my listsWhere's my value?Disappearing ElementsMy array should equal this, but it doesn't!Maximum summed subsequences with non-adjacent items

Managing and organizing the massively increased number of classes after switching to SOLID?

Why was hardware diversification an asset for the IBM PC ecosystem?

Storming Area 51

Is the genetic term "polycistronic" still used in modern biology?

Print the last, middle and first character of your code

How do you glue a text to a point?

How did the hit man miss?

Good resources for solving techniques (Metaheuristics, MILP, CP etc)

Why weren't bootable game disks ever common on the IBM PC?

definition of "percentile"

Graduate student with abysmal English writing skills, how to help

Is a request to book a business flight ticket for a graduate student an unreasonable one?

If a non-friend comes across my Steam Wishlist, how easily can he gift me one of the games?

Integer Lists of Noah

How to convert a file with several spaces into a tab-delimited file?

How can a dictatorship government be beneficial to a dictator in a post-scarcity society?

Are there any sports for which the world's best player is female?

Cracking the Coding Interview — 1.5 One Away

How were Martello towers supposed to work?

Cops: The Hidden OEIS Substring

US Civil War story: man hanged from a bridge

Why does the U.S. tolerate foreign influence from Saudi Arabia and Israel on its domestic policies while not tolerating that from China or Russia?

Why are all my yellow 2V/20mA LEDs burning out with 330k Ohm resistor?

Optimization terminology: "Exact" v. "Approximate"



Matchmaker, Matchmaker, make me a match


Fivenum and a little bitGeneralised Array RiffleAre these trees isomorphic?Generate a looping arrayFind the indices of values in one list in anotherIs this a function?Compare the averages of my listsWhere's my value?Disappearing ElementsMy array should equal this, but it doesn't!Maximum summed subsequences with non-adjacent items






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








7












$begingroup$


(we won't be finding a Find or catching a tryCatch, though)



This is part two of a multi-part series of implementing some interesting R functions. Part one can be found here.



The task:



You are to implement R's match function in as few bytes as possible.



Input:




  • x, a possibly empty list/array of integers


  • table, a possibly empty list/array of integers


  • nomatch, a single integer value


  • incomparables, a possibly empty list/array of integers

Output:



  • a single array/list of integers O of equal length to x, where each value O[i] represents either:

    • The index j of the first value in table where table[j]==x[i]


    • nomatch, indicating that no value in table is equal to x[i] OR that x[i] is in the list of incomparables.


Test Cases



All in the form x, table, nomatch, incomparables -> output
outputs

[], [1,2,3], 0, [5] -> []

[1, 2, 3], [], 0, [5] -> [0, 0, 0]

[9, 4, 3, 6, 3], [9, 8, 7, 6, 5, 4, 3, 2, 1], -1, [4] -> [1, -1, 7, 4, 7]

[8, 6, 7, 5, 3, 0, 9], [3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5, 8, 9, 7, 9, 3, 2, 3, 8, 4, 6, 2, 6], 1000, [1] -> [12, 8, 14, 5, 1, 1000, 6]


More test cases can be generated as needed.



Additional rules:



  • R has 1-based indices, but a consistent alternative-based indices are acceptable. So you can use indices that start at 3 or 17 or whatever, but this must be consistent, and you must indicate this in your answer.

  • If you chosen language has a builtin that does this, please also implement your own solution.

  • Explanations are appreciated.

This is code-golf, so shortest solution in bytes wins!










share|improve this question









$endgroup$











  • $begingroup$
    If someone can solve this in R without using match or %in% (which is implemented by using match), I will happily award a 150-rep bounty.
    $endgroup$
    – Giuseppe
    6 hours ago


















7












$begingroup$


(we won't be finding a Find or catching a tryCatch, though)



This is part two of a multi-part series of implementing some interesting R functions. Part one can be found here.



The task:



You are to implement R's match function in as few bytes as possible.



Input:




  • x, a possibly empty list/array of integers


  • table, a possibly empty list/array of integers


  • nomatch, a single integer value


  • incomparables, a possibly empty list/array of integers

Output:



  • a single array/list of integers O of equal length to x, where each value O[i] represents either:

    • The index j of the first value in table where table[j]==x[i]


    • nomatch, indicating that no value in table is equal to x[i] OR that x[i] is in the list of incomparables.


Test Cases



All in the form x, table, nomatch, incomparables -> output
outputs

[], [1,2,3], 0, [5] -> []

[1, 2, 3], [], 0, [5] -> [0, 0, 0]

[9, 4, 3, 6, 3], [9, 8, 7, 6, 5, 4, 3, 2, 1], -1, [4] -> [1, -1, 7, 4, 7]

[8, 6, 7, 5, 3, 0, 9], [3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5, 8, 9, 7, 9, 3, 2, 3, 8, 4, 6, 2, 6], 1000, [1] -> [12, 8, 14, 5, 1, 1000, 6]


More test cases can be generated as needed.



Additional rules:



  • R has 1-based indices, but a consistent alternative-based indices are acceptable. So you can use indices that start at 3 or 17 or whatever, but this must be consistent, and you must indicate this in your answer.

  • If you chosen language has a builtin that does this, please also implement your own solution.

  • Explanations are appreciated.

This is code-golf, so shortest solution in bytes wins!










share|improve this question









$endgroup$











  • $begingroup$
    If someone can solve this in R without using match or %in% (which is implemented by using match), I will happily award a 150-rep bounty.
    $endgroup$
    – Giuseppe
    6 hours ago














7












7








7





$begingroup$


(we won't be finding a Find or catching a tryCatch, though)



This is part two of a multi-part series of implementing some interesting R functions. Part one can be found here.



The task:



You are to implement R's match function in as few bytes as possible.



Input:




  • x, a possibly empty list/array of integers


  • table, a possibly empty list/array of integers


  • nomatch, a single integer value


  • incomparables, a possibly empty list/array of integers

Output:



  • a single array/list of integers O of equal length to x, where each value O[i] represents either:

    • The index j of the first value in table where table[j]==x[i]


    • nomatch, indicating that no value in table is equal to x[i] OR that x[i] is in the list of incomparables.


Test Cases



All in the form x, table, nomatch, incomparables -> output
outputs

[], [1,2,3], 0, [5] -> []

[1, 2, 3], [], 0, [5] -> [0, 0, 0]

[9, 4, 3, 6, 3], [9, 8, 7, 6, 5, 4, 3, 2, 1], -1, [4] -> [1, -1, 7, 4, 7]

[8, 6, 7, 5, 3, 0, 9], [3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5, 8, 9, 7, 9, 3, 2, 3, 8, 4, 6, 2, 6], 1000, [1] -> [12, 8, 14, 5, 1, 1000, 6]


More test cases can be generated as needed.



Additional rules:



  • R has 1-based indices, but a consistent alternative-based indices are acceptable. So you can use indices that start at 3 or 17 or whatever, but this must be consistent, and you must indicate this in your answer.

  • If you chosen language has a builtin that does this, please also implement your own solution.

  • Explanations are appreciated.

This is code-golf, so shortest solution in bytes wins!










share|improve this question









$endgroup$




(we won't be finding a Find or catching a tryCatch, though)



This is part two of a multi-part series of implementing some interesting R functions. Part one can be found here.



The task:



You are to implement R's match function in as few bytes as possible.



Input:




  • x, a possibly empty list/array of integers


  • table, a possibly empty list/array of integers


  • nomatch, a single integer value


  • incomparables, a possibly empty list/array of integers

Output:



  • a single array/list of integers O of equal length to x, where each value O[i] represents either:

    • The index j of the first value in table where table[j]==x[i]


    • nomatch, indicating that no value in table is equal to x[i] OR that x[i] is in the list of incomparables.


Test Cases



All in the form x, table, nomatch, incomparables -> output
outputs

[], [1,2,3], 0, [5] -> []

[1, 2, 3], [], 0, [5] -> [0, 0, 0]

[9, 4, 3, 6, 3], [9, 8, 7, 6, 5, 4, 3, 2, 1], -1, [4] -> [1, -1, 7, 4, 7]

[8, 6, 7, 5, 3, 0, 9], [3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5, 8, 9, 7, 9, 3, 2, 3, 8, 4, 6, 2, 6], 1000, [1] -> [12, 8, 14, 5, 1, 1000, 6]


More test cases can be generated as needed.



Additional rules:



  • R has 1-based indices, but a consistent alternative-based indices are acceptable. So you can use indices that start at 3 or 17 or whatever, but this must be consistent, and you must indicate this in your answer.

  • If you chosen language has a builtin that does this, please also implement your own solution.

  • Explanations are appreciated.

This is code-golf, so shortest solution in bytes wins!







code-golf array-manipulation






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked 9 hours ago









GiuseppeGiuseppe

18.9k3 gold badges14 silver badges62 bronze badges




18.9k3 gold badges14 silver badges62 bronze badges











  • $begingroup$
    If someone can solve this in R without using match or %in% (which is implemented by using match), I will happily award a 150-rep bounty.
    $endgroup$
    – Giuseppe
    6 hours ago

















  • $begingroup$
    If someone can solve this in R without using match or %in% (which is implemented by using match), I will happily award a 150-rep bounty.
    $endgroup$
    – Giuseppe
    6 hours ago
















$begingroup$
If someone can solve this in R without using match or %in% (which is implemented by using match), I will happily award a 150-rep bounty.
$endgroup$
– Giuseppe
6 hours ago





$begingroup$
If someone can solve this in R without using match or %in% (which is implemented by using match), I will happily award a 150-rep bounty.
$endgroup$
– Giuseppe
6 hours ago











8 Answers
8






active

oldest

votes


















4












$begingroup$


Jelly,  10  8 bytes



-2 thanks to Erik the Outgolfer



,⁷y⁵iⱮ⁶o


A full program accepting four command line arguments, incomparables nomatch table x which prints a Jelly representation* of the list of R's match function results.



Try it online!



How?



e.g. with incomparables nomatch table x = [1,4], 2, [2,4], [4,3,2,1,0]:



,⁷y⁵iⱮ⁶o - Main Link: list, incomparables; list, nomatch
⁷ - newline character 'n'
, - pair (incompararables) with (right) [[1,4],'n']
⁵ - 5th argument (3rd input = table) [2,4]
y - translate (right) with lookup (left) [2,'n']
⁶ - 6th argument (4th input = x) [4,3,2,1,0]
Ɱ - map with:
i - first index of (right) in (left) [0,0,1,0,0]
o - logical OR [2,2,1,2,2]



* An empty list is represented as nothing, a list of lenth one is represented as just the item, while other lists are enclosed in [] and delimited by ,






share|improve this answer











$endgroup$




















    3












    $begingroup$


    R, 83 bytes





    function(x,t,n,i)sapply(x,function(a)c(which(a==t/!rowSums(outer(t,i,`==`))),n)[1])


    Try it online!



    Avoids match, %in% and setdiff.






    share|improve this answer









    $endgroup$












    • $begingroup$
      I'll award this a bounty once the question is eligible.
      $endgroup$
      – Giuseppe
      6 mins ago


















    2












    $begingroup$


    Ruby, 44 bytes



    Zero-indexed.





    ->x,t,n,ix.map


    Try it online!






    share|improve this answer









    $endgroup$




















      2












      $begingroup$


      R, 55 bytes



      In this case, the code doesn't use match with its full functionality, it is just used as an index function. First R answer, so probably incredibly inefficient byte-wise!



      Note (thanks to Giuseppe for the info): %in% and setdiff are also both internally implemented using match, so completely getting rid of this surprisingly useful function will result in a mess. Therefore, there is a 150-rep bounty with no deadline for this! (note that setdiff is allowed, though)





      function(x,t,n,i)ifelse(x%in%setdiff(t,i),match(x,t),n)


      Try it online!



      or...




      R, 5 bytes





      match


      Try it online!






      share|improve this answer











      $endgroup$












      • $begingroup$
        I'm not sure I could do better although I was eschewing the use of %in% and match; if you want to find a good golfy answer without either of those functions (likely to be horrible), I'll bounty this.
        $endgroup$
        – Giuseppe
        6 hours ago










      • $begingroup$
        Ah lol, I just commented in golfR about that...
        $endgroup$
        – Mr. Xcoder
        6 hours ago


















      2












      $begingroup$


      Jelly, 9 8 bytes



      ṣK¥ƒiⱮo⁶


      Try it online!



      A full program that takes three arguments: [[table], incomparables], x, nomatch in that order.






      share|improve this answer











      $endgroup$




















        1












        $begingroup$


        Japt, 14 bytes



        Ë!XøD ©ÒVbD ªW


        Try it






        share|improve this answer









        $endgroup$




















          1












          $begingroup$


          Python 3, 60 bytes





          lambda x,t,n,i:[v in*t-*iand-~t.index(v)or n for v in x]


          Try it online!






          share|improve this answer











          $endgroup$












          • $begingroup$
            What features of this are specific to 3.8? Looks to me like this could work for any subversion of Python 3.
            $endgroup$
            – Theo
            7 hours ago










          • $begingroup$
            Well, it is not specific to 3.8. I just copy-pasted the auto-generated template on TIO so I didn't notice I used 3.8. Thanks for the heads-up, will adjust.
            $endgroup$
            – Mr. Xcoder
            7 hours ago






          • 1




            $begingroup$
            R has 1-based indices, but a consistent alternative-based indices are acceptable. So you can take out the -~ and just use 0-indexing for -1 bytes.
            $endgroup$
            – Value Ink
            7 hours ago






          • 1




            $begingroup$
            @ValueInk That fails for the 3rd test case (and in general when a matching element is at the beginning of a list), since 0 is falsy in Python.
            $endgroup$
            – Mr. Xcoder
            7 hours ago






          • 1




            $begingroup$
            Ah, fair show. Incidentally, t.index(v)if v in*t-*ielse n has the exact same bytecount as your current v in*t-*iand-~t.index(v)or n solution, haha
            $endgroup$
            – Value Ink
            6 hours ago


















          1












          $begingroup$


          Charcoal, 14 bytes



          IEθ∨∧¬№ει⊕⌕ηιζ


          Try it online! Link is to verbose version of code. 1-indexed. Explanation:



           θ First input (x)
          E Map over elements
          ε Fourth input (incomparables)
          № Count occurrences of
          ι Current element
          ¬ Is zero
          ∧ Logical And
          η Second input (table)
          ⌕ Find 0-based index of
          ι Current element
          ⊕ Convert to 1-indexed
          ∨ Logical Or
          ζ Third input (nomatch)
          I Cast to string
          Implicitly print on separate lines





          share|improve this answer









          $endgroup$















            Your Answer






            StackExchange.ifUsing("editor", function ()
            StackExchange.using("externalEditor", function ()
            StackExchange.using("snippets", function ()
            StackExchange.snippets.init();
            );
            );
            , "code-snippets");

            StackExchange.ready(function()
            var channelOptions =
            tags: "".split(" "),
            id: "200"
            ;
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function()
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled)
            StackExchange.using("snippets", function()
            createEditor();
            );

            else
            createEditor();

            );

            function createEditor()
            StackExchange.prepareEditor(
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: false,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: null,
            bindNavPrevention: true,
            postfix: "",
            imageUploader:
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            ,
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            );



            );













            draft saved

            draft discarded


















            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodegolf.stackexchange.com%2fquestions%2f188162%2fmatchmaker-matchmaker-make-me-a-match%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown

























            8 Answers
            8






            active

            oldest

            votes








            8 Answers
            8






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            4












            $begingroup$


            Jelly,  10  8 bytes



            -2 thanks to Erik the Outgolfer



            ,⁷y⁵iⱮ⁶o


            A full program accepting four command line arguments, incomparables nomatch table x which prints a Jelly representation* of the list of R's match function results.



            Try it online!



            How?



            e.g. with incomparables nomatch table x = [1,4], 2, [2,4], [4,3,2,1,0]:



            ,⁷y⁵iⱮ⁶o - Main Link: list, incomparables; list, nomatch
            ⁷ - newline character 'n'
            , - pair (incompararables) with (right) [[1,4],'n']
            ⁵ - 5th argument (3rd input = table) [2,4]
            y - translate (right) with lookup (left) [2,'n']
            ⁶ - 6th argument (4th input = x) [4,3,2,1,0]
            Ɱ - map with:
            i - first index of (right) in (left) [0,0,1,0,0]
            o - logical OR [2,2,1,2,2]



            * An empty list is represented as nothing, a list of lenth one is represented as just the item, while other lists are enclosed in [] and delimited by ,






            share|improve this answer











            $endgroup$

















              4












              $begingroup$


              Jelly,  10  8 bytes



              -2 thanks to Erik the Outgolfer



              ,⁷y⁵iⱮ⁶o


              A full program accepting four command line arguments, incomparables nomatch table x which prints a Jelly representation* of the list of R's match function results.



              Try it online!



              How?



              e.g. with incomparables nomatch table x = [1,4], 2, [2,4], [4,3,2,1,0]:



              ,⁷y⁵iⱮ⁶o - Main Link: list, incomparables; list, nomatch
              ⁷ - newline character 'n'
              , - pair (incompararables) with (right) [[1,4],'n']
              ⁵ - 5th argument (3rd input = table) [2,4]
              y - translate (right) with lookup (left) [2,'n']
              ⁶ - 6th argument (4th input = x) [4,3,2,1,0]
              Ɱ - map with:
              i - first index of (right) in (left) [0,0,1,0,0]
              o - logical OR [2,2,1,2,2]



              * An empty list is represented as nothing, a list of lenth one is represented as just the item, while other lists are enclosed in [] and delimited by ,






              share|improve this answer











              $endgroup$















                4












                4








                4





                $begingroup$


                Jelly,  10  8 bytes



                -2 thanks to Erik the Outgolfer



                ,⁷y⁵iⱮ⁶o


                A full program accepting four command line arguments, incomparables nomatch table x which prints a Jelly representation* of the list of R's match function results.



                Try it online!



                How?



                e.g. with incomparables nomatch table x = [1,4], 2, [2,4], [4,3,2,1,0]:



                ,⁷y⁵iⱮ⁶o - Main Link: list, incomparables; list, nomatch
                ⁷ - newline character 'n'
                , - pair (incompararables) with (right) [[1,4],'n']
                ⁵ - 5th argument (3rd input = table) [2,4]
                y - translate (right) with lookup (left) [2,'n']
                ⁶ - 6th argument (4th input = x) [4,3,2,1,0]
                Ɱ - map with:
                i - first index of (right) in (left) [0,0,1,0,0]
                o - logical OR [2,2,1,2,2]



                * An empty list is represented as nothing, a list of lenth one is represented as just the item, while other lists are enclosed in [] and delimited by ,






                share|improve this answer











                $endgroup$




                Jelly,  10  8 bytes



                -2 thanks to Erik the Outgolfer



                ,⁷y⁵iⱮ⁶o


                A full program accepting four command line arguments, incomparables nomatch table x which prints a Jelly representation* of the list of R's match function results.



                Try it online!



                How?



                e.g. with incomparables nomatch table x = [1,4], 2, [2,4], [4,3,2,1,0]:



                ,⁷y⁵iⱮ⁶o - Main Link: list, incomparables; list, nomatch
                ⁷ - newline character 'n'
                , - pair (incompararables) with (right) [[1,4],'n']
                ⁵ - 5th argument (3rd input = table) [2,4]
                y - translate (right) with lookup (left) [2,'n']
                ⁶ - 6th argument (4th input = x) [4,3,2,1,0]
                Ɱ - map with:
                i - first index of (right) in (left) [0,0,1,0,0]
                o - logical OR [2,2,1,2,2]



                * An empty list is represented as nothing, a list of lenth one is represented as just the item, while other lists are enclosed in [] and delimited by ,







                share|improve this answer














                share|improve this answer



                share|improve this answer








                edited 5 hours ago

























                answered 6 hours ago









                Jonathan AllanJonathan Allan

                57.3k5 gold badges43 silver badges181 bronze badges




                57.3k5 gold badges43 silver badges181 bronze badges























                    3












                    $begingroup$


                    R, 83 bytes





                    function(x,t,n,i)sapply(x,function(a)c(which(a==t/!rowSums(outer(t,i,`==`))),n)[1])


                    Try it online!



                    Avoids match, %in% and setdiff.






                    share|improve this answer









                    $endgroup$












                    • $begingroup$
                      I'll award this a bounty once the question is eligible.
                      $endgroup$
                      – Giuseppe
                      6 mins ago















                    3












                    $begingroup$


                    R, 83 bytes





                    function(x,t,n,i)sapply(x,function(a)c(which(a==t/!rowSums(outer(t,i,`==`))),n)[1])


                    Try it online!



                    Avoids match, %in% and setdiff.






                    share|improve this answer









                    $endgroup$












                    • $begingroup$
                      I'll award this a bounty once the question is eligible.
                      $endgroup$
                      – Giuseppe
                      6 mins ago













                    3












                    3








                    3





                    $begingroup$


                    R, 83 bytes





                    function(x,t,n,i)sapply(x,function(a)c(which(a==t/!rowSums(outer(t,i,`==`))),n)[1])


                    Try it online!



                    Avoids match, %in% and setdiff.






                    share|improve this answer









                    $endgroup$




                    R, 83 bytes





                    function(x,t,n,i)sapply(x,function(a)c(which(a==t/!rowSums(outer(t,i,`==`))),n)[1])


                    Try it online!



                    Avoids match, %in% and setdiff.







                    share|improve this answer












                    share|improve this answer



                    share|improve this answer










                    answered 5 hours ago









                    Nick KennedyNick Kennedy

                    4,4848 silver badges14 bronze badges




                    4,4848 silver badges14 bronze badges











                    • $begingroup$
                      I'll award this a bounty once the question is eligible.
                      $endgroup$
                      – Giuseppe
                      6 mins ago
















                    • $begingroup$
                      I'll award this a bounty once the question is eligible.
                      $endgroup$
                      – Giuseppe
                      6 mins ago















                    $begingroup$
                    I'll award this a bounty once the question is eligible.
                    $endgroup$
                    – Giuseppe
                    6 mins ago




                    $begingroup$
                    I'll award this a bounty once the question is eligible.
                    $endgroup$
                    – Giuseppe
                    6 mins ago











                    2












                    $begingroup$


                    Ruby, 44 bytes



                    Zero-indexed.





                    ->x,t,n,ix.map


                    Try it online!






                    share|improve this answer









                    $endgroup$

















                      2












                      $begingroup$


                      Ruby, 44 bytes



                      Zero-indexed.





                      ->x,t,n,ix.map


                      Try it online!






                      share|improve this answer









                      $endgroup$















                        2












                        2








                        2





                        $begingroup$


                        Ruby, 44 bytes



                        Zero-indexed.





                        ->x,t,n,ix.map


                        Try it online!






                        share|improve this answer









                        $endgroup$




                        Ruby, 44 bytes



                        Zero-indexed.





                        ->x,t,n,ix.map


                        Try it online!







                        share|improve this answer












                        share|improve this answer



                        share|improve this answer










                        answered 7 hours ago









                        Value InkValue Ink

                        8,7957 silver badges32 bronze badges




                        8,7957 silver badges32 bronze badges





















                            2












                            $begingroup$


                            R, 55 bytes



                            In this case, the code doesn't use match with its full functionality, it is just used as an index function. First R answer, so probably incredibly inefficient byte-wise!



                            Note (thanks to Giuseppe for the info): %in% and setdiff are also both internally implemented using match, so completely getting rid of this surprisingly useful function will result in a mess. Therefore, there is a 150-rep bounty with no deadline for this! (note that setdiff is allowed, though)





                            function(x,t,n,i)ifelse(x%in%setdiff(t,i),match(x,t),n)


                            Try it online!



                            or...




                            R, 5 bytes





                            match


                            Try it online!






                            share|improve this answer











                            $endgroup$












                            • $begingroup$
                              I'm not sure I could do better although I was eschewing the use of %in% and match; if you want to find a good golfy answer without either of those functions (likely to be horrible), I'll bounty this.
                              $endgroup$
                              – Giuseppe
                              6 hours ago










                            • $begingroup$
                              Ah lol, I just commented in golfR about that...
                              $endgroup$
                              – Mr. Xcoder
                              6 hours ago















                            2












                            $begingroup$


                            R, 55 bytes



                            In this case, the code doesn't use match with its full functionality, it is just used as an index function. First R answer, so probably incredibly inefficient byte-wise!



                            Note (thanks to Giuseppe for the info): %in% and setdiff are also both internally implemented using match, so completely getting rid of this surprisingly useful function will result in a mess. Therefore, there is a 150-rep bounty with no deadline for this! (note that setdiff is allowed, though)





                            function(x,t,n,i)ifelse(x%in%setdiff(t,i),match(x,t),n)


                            Try it online!



                            or...




                            R, 5 bytes





                            match


                            Try it online!






                            share|improve this answer











                            $endgroup$












                            • $begingroup$
                              I'm not sure I could do better although I was eschewing the use of %in% and match; if you want to find a good golfy answer without either of those functions (likely to be horrible), I'll bounty this.
                              $endgroup$
                              – Giuseppe
                              6 hours ago










                            • $begingroup$
                              Ah lol, I just commented in golfR about that...
                              $endgroup$
                              – Mr. Xcoder
                              6 hours ago













                            2












                            2








                            2





                            $begingroup$


                            R, 55 bytes



                            In this case, the code doesn't use match with its full functionality, it is just used as an index function. First R answer, so probably incredibly inefficient byte-wise!



                            Note (thanks to Giuseppe for the info): %in% and setdiff are also both internally implemented using match, so completely getting rid of this surprisingly useful function will result in a mess. Therefore, there is a 150-rep bounty with no deadline for this! (note that setdiff is allowed, though)





                            function(x,t,n,i)ifelse(x%in%setdiff(t,i),match(x,t),n)


                            Try it online!



                            or...




                            R, 5 bytes





                            match


                            Try it online!






                            share|improve this answer











                            $endgroup$




                            R, 55 bytes



                            In this case, the code doesn't use match with its full functionality, it is just used as an index function. First R answer, so probably incredibly inefficient byte-wise!



                            Note (thanks to Giuseppe for the info): %in% and setdiff are also both internally implemented using match, so completely getting rid of this surprisingly useful function will result in a mess. Therefore, there is a 150-rep bounty with no deadline for this! (note that setdiff is allowed, though)





                            function(x,t,n,i)ifelse(x%in%setdiff(t,i),match(x,t),n)


                            Try it online!



                            or...




                            R, 5 bytes





                            match


                            Try it online!







                            share|improve this answer














                            share|improve this answer



                            share|improve this answer








                            edited 6 hours ago

























                            answered 6 hours ago









                            Mr. XcoderMr. Xcoder

                            32.7k7 gold badges61 silver badges202 bronze badges




                            32.7k7 gold badges61 silver badges202 bronze badges











                            • $begingroup$
                              I'm not sure I could do better although I was eschewing the use of %in% and match; if you want to find a good golfy answer without either of those functions (likely to be horrible), I'll bounty this.
                              $endgroup$
                              – Giuseppe
                              6 hours ago










                            • $begingroup$
                              Ah lol, I just commented in golfR about that...
                              $endgroup$
                              – Mr. Xcoder
                              6 hours ago
















                            • $begingroup$
                              I'm not sure I could do better although I was eschewing the use of %in% and match; if you want to find a good golfy answer without either of those functions (likely to be horrible), I'll bounty this.
                              $endgroup$
                              – Giuseppe
                              6 hours ago










                            • $begingroup$
                              Ah lol, I just commented in golfR about that...
                              $endgroup$
                              – Mr. Xcoder
                              6 hours ago















                            $begingroup$
                            I'm not sure I could do better although I was eschewing the use of %in% and match; if you want to find a good golfy answer without either of those functions (likely to be horrible), I'll bounty this.
                            $endgroup$
                            – Giuseppe
                            6 hours ago




                            $begingroup$
                            I'm not sure I could do better although I was eschewing the use of %in% and match; if you want to find a good golfy answer without either of those functions (likely to be horrible), I'll bounty this.
                            $endgroup$
                            – Giuseppe
                            6 hours ago












                            $begingroup$
                            Ah lol, I just commented in golfR about that...
                            $endgroup$
                            – Mr. Xcoder
                            6 hours ago




                            $begingroup$
                            Ah lol, I just commented in golfR about that...
                            $endgroup$
                            – Mr. Xcoder
                            6 hours ago











                            2












                            $begingroup$


                            Jelly, 9 8 bytes



                            ṣK¥ƒiⱮo⁶


                            Try it online!



                            A full program that takes three arguments: [[table], incomparables], x, nomatch in that order.






                            share|improve this answer











                            $endgroup$

















                              2












                              $begingroup$


                              Jelly, 9 8 bytes



                              ṣK¥ƒiⱮo⁶


                              Try it online!



                              A full program that takes three arguments: [[table], incomparables], x, nomatch in that order.






                              share|improve this answer











                              $endgroup$















                                2












                                2








                                2





                                $begingroup$


                                Jelly, 9 8 bytes



                                ṣK¥ƒiⱮo⁶


                                Try it online!



                                A full program that takes three arguments: [[table], incomparables], x, nomatch in that order.






                                share|improve this answer











                                $endgroup$




                                Jelly, 9 8 bytes



                                ṣK¥ƒiⱮo⁶


                                Try it online!



                                A full program that takes three arguments: [[table], incomparables], x, nomatch in that order.







                                share|improve this answer














                                share|improve this answer



                                share|improve this answer








                                edited 2 hours ago

























                                answered 6 hours ago









                                Nick KennedyNick Kennedy

                                4,4848 silver badges14 bronze badges




                                4,4848 silver badges14 bronze badges





















                                    1












                                    $begingroup$


                                    Japt, 14 bytes



                                    Ë!XøD ©ÒVbD ªW


                                    Try it






                                    share|improve this answer









                                    $endgroup$

















                                      1












                                      $begingroup$


                                      Japt, 14 bytes



                                      Ë!XøD ©ÒVbD ªW


                                      Try it






                                      share|improve this answer









                                      $endgroup$















                                        1












                                        1








                                        1





                                        $begingroup$


                                        Japt, 14 bytes



                                        Ë!XøD ©ÒVbD ªW


                                        Try it






                                        share|improve this answer









                                        $endgroup$




                                        Japt, 14 bytes



                                        Ë!XøD ©ÒVbD ªW


                                        Try it







                                        share|improve this answer












                                        share|improve this answer



                                        share|improve this answer










                                        answered 7 hours ago









                                        ShaggyShaggy

                                        20.3k3 gold badges20 silver badges69 bronze badges




                                        20.3k3 gold badges20 silver badges69 bronze badges





















                                            1












                                            $begingroup$


                                            Python 3, 60 bytes





                                            lambda x,t,n,i:[v in*t-*iand-~t.index(v)or n for v in x]


                                            Try it online!






                                            share|improve this answer











                                            $endgroup$












                                            • $begingroup$
                                              What features of this are specific to 3.8? Looks to me like this could work for any subversion of Python 3.
                                              $endgroup$
                                              – Theo
                                              7 hours ago










                                            • $begingroup$
                                              Well, it is not specific to 3.8. I just copy-pasted the auto-generated template on TIO so I didn't notice I used 3.8. Thanks for the heads-up, will adjust.
                                              $endgroup$
                                              – Mr. Xcoder
                                              7 hours ago






                                            • 1




                                              $begingroup$
                                              R has 1-based indices, but a consistent alternative-based indices are acceptable. So you can take out the -~ and just use 0-indexing for -1 bytes.
                                              $endgroup$
                                              – Value Ink
                                              7 hours ago






                                            • 1




                                              $begingroup$
                                              @ValueInk That fails for the 3rd test case (and in general when a matching element is at the beginning of a list), since 0 is falsy in Python.
                                              $endgroup$
                                              – Mr. Xcoder
                                              7 hours ago






                                            • 1




                                              $begingroup$
                                              Ah, fair show. Incidentally, t.index(v)if v in*t-*ielse n has the exact same bytecount as your current v in*t-*iand-~t.index(v)or n solution, haha
                                              $endgroup$
                                              – Value Ink
                                              6 hours ago















                                            1












                                            $begingroup$


                                            Python 3, 60 bytes





                                            lambda x,t,n,i:[v in*t-*iand-~t.index(v)or n for v in x]


                                            Try it online!






                                            share|improve this answer











                                            $endgroup$












                                            • $begingroup$
                                              What features of this are specific to 3.8? Looks to me like this could work for any subversion of Python 3.
                                              $endgroup$
                                              – Theo
                                              7 hours ago










                                            • $begingroup$
                                              Well, it is not specific to 3.8. I just copy-pasted the auto-generated template on TIO so I didn't notice I used 3.8. Thanks for the heads-up, will adjust.
                                              $endgroup$
                                              – Mr. Xcoder
                                              7 hours ago






                                            • 1




                                              $begingroup$
                                              R has 1-based indices, but a consistent alternative-based indices are acceptable. So you can take out the -~ and just use 0-indexing for -1 bytes.
                                              $endgroup$
                                              – Value Ink
                                              7 hours ago






                                            • 1




                                              $begingroup$
                                              @ValueInk That fails for the 3rd test case (and in general when a matching element is at the beginning of a list), since 0 is falsy in Python.
                                              $endgroup$
                                              – Mr. Xcoder
                                              7 hours ago






                                            • 1




                                              $begingroup$
                                              Ah, fair show. Incidentally, t.index(v)if v in*t-*ielse n has the exact same bytecount as your current v in*t-*iand-~t.index(v)or n solution, haha
                                              $endgroup$
                                              – Value Ink
                                              6 hours ago













                                            1












                                            1








                                            1





                                            $begingroup$


                                            Python 3, 60 bytes





                                            lambda x,t,n,i:[v in*t-*iand-~t.index(v)or n for v in x]


                                            Try it online!






                                            share|improve this answer











                                            $endgroup$




                                            Python 3, 60 bytes





                                            lambda x,t,n,i:[v in*t-*iand-~t.index(v)or n for v in x]


                                            Try it online!







                                            share|improve this answer














                                            share|improve this answer



                                            share|improve this answer








                                            edited 7 hours ago

























                                            answered 8 hours ago









                                            Mr. XcoderMr. Xcoder

                                            32.7k7 gold badges61 silver badges202 bronze badges




                                            32.7k7 gold badges61 silver badges202 bronze badges











                                            • $begingroup$
                                              What features of this are specific to 3.8? Looks to me like this could work for any subversion of Python 3.
                                              $endgroup$
                                              – Theo
                                              7 hours ago










                                            • $begingroup$
                                              Well, it is not specific to 3.8. I just copy-pasted the auto-generated template on TIO so I didn't notice I used 3.8. Thanks for the heads-up, will adjust.
                                              $endgroup$
                                              – Mr. Xcoder
                                              7 hours ago






                                            • 1




                                              $begingroup$
                                              R has 1-based indices, but a consistent alternative-based indices are acceptable. So you can take out the -~ and just use 0-indexing for -1 bytes.
                                              $endgroup$
                                              – Value Ink
                                              7 hours ago






                                            • 1




                                              $begingroup$
                                              @ValueInk That fails for the 3rd test case (and in general when a matching element is at the beginning of a list), since 0 is falsy in Python.
                                              $endgroup$
                                              – Mr. Xcoder
                                              7 hours ago






                                            • 1




                                              $begingroup$
                                              Ah, fair show. Incidentally, t.index(v)if v in*t-*ielse n has the exact same bytecount as your current v in*t-*iand-~t.index(v)or n solution, haha
                                              $endgroup$
                                              – Value Ink
                                              6 hours ago
















                                            • $begingroup$
                                              What features of this are specific to 3.8? Looks to me like this could work for any subversion of Python 3.
                                              $endgroup$
                                              – Theo
                                              7 hours ago










                                            • $begingroup$
                                              Well, it is not specific to 3.8. I just copy-pasted the auto-generated template on TIO so I didn't notice I used 3.8. Thanks for the heads-up, will adjust.
                                              $endgroup$
                                              – Mr. Xcoder
                                              7 hours ago






                                            • 1




                                              $begingroup$
                                              R has 1-based indices, but a consistent alternative-based indices are acceptable. So you can take out the -~ and just use 0-indexing for -1 bytes.
                                              $endgroup$
                                              – Value Ink
                                              7 hours ago






                                            • 1




                                              $begingroup$
                                              @ValueInk That fails for the 3rd test case (and in general when a matching element is at the beginning of a list), since 0 is falsy in Python.
                                              $endgroup$
                                              – Mr. Xcoder
                                              7 hours ago






                                            • 1




                                              $begingroup$
                                              Ah, fair show. Incidentally, t.index(v)if v in*t-*ielse n has the exact same bytecount as your current v in*t-*iand-~t.index(v)or n solution, haha
                                              $endgroup$
                                              – Value Ink
                                              6 hours ago















                                            $begingroup$
                                            What features of this are specific to 3.8? Looks to me like this could work for any subversion of Python 3.
                                            $endgroup$
                                            – Theo
                                            7 hours ago




                                            $begingroup$
                                            What features of this are specific to 3.8? Looks to me like this could work for any subversion of Python 3.
                                            $endgroup$
                                            – Theo
                                            7 hours ago












                                            $begingroup$
                                            Well, it is not specific to 3.8. I just copy-pasted the auto-generated template on TIO so I didn't notice I used 3.8. Thanks for the heads-up, will adjust.
                                            $endgroup$
                                            – Mr. Xcoder
                                            7 hours ago




                                            $begingroup$
                                            Well, it is not specific to 3.8. I just copy-pasted the auto-generated template on TIO so I didn't notice I used 3.8. Thanks for the heads-up, will adjust.
                                            $endgroup$
                                            – Mr. Xcoder
                                            7 hours ago




                                            1




                                            1




                                            $begingroup$
                                            R has 1-based indices, but a consistent alternative-based indices are acceptable. So you can take out the -~ and just use 0-indexing for -1 bytes.
                                            $endgroup$
                                            – Value Ink
                                            7 hours ago




                                            $begingroup$
                                            R has 1-based indices, but a consistent alternative-based indices are acceptable. So you can take out the -~ and just use 0-indexing for -1 bytes.
                                            $endgroup$
                                            – Value Ink
                                            7 hours ago




                                            1




                                            1




                                            $begingroup$
                                            @ValueInk That fails for the 3rd test case (and in general when a matching element is at the beginning of a list), since 0 is falsy in Python.
                                            $endgroup$
                                            – Mr. Xcoder
                                            7 hours ago




                                            $begingroup$
                                            @ValueInk That fails for the 3rd test case (and in general when a matching element is at the beginning of a list), since 0 is falsy in Python.
                                            $endgroup$
                                            – Mr. Xcoder
                                            7 hours ago




                                            1




                                            1




                                            $begingroup$
                                            Ah, fair show. Incidentally, t.index(v)if v in*t-*ielse n has the exact same bytecount as your current v in*t-*iand-~t.index(v)or n solution, haha
                                            $endgroup$
                                            – Value Ink
                                            6 hours ago




                                            $begingroup$
                                            Ah, fair show. Incidentally, t.index(v)if v in*t-*ielse n has the exact same bytecount as your current v in*t-*iand-~t.index(v)or n solution, haha
                                            $endgroup$
                                            – Value Ink
                                            6 hours ago











                                            1












                                            $begingroup$


                                            Charcoal, 14 bytes



                                            IEθ∨∧¬№ει⊕⌕ηιζ


                                            Try it online! Link is to verbose version of code. 1-indexed. Explanation:



                                             θ First input (x)
                                            E Map over elements
                                            ε Fourth input (incomparables)
                                            № Count occurrences of
                                            ι Current element
                                            ¬ Is zero
                                            ∧ Logical And
                                            η Second input (table)
                                            ⌕ Find 0-based index of
                                            ι Current element
                                            ⊕ Convert to 1-indexed
                                            ∨ Logical Or
                                            ζ Third input (nomatch)
                                            I Cast to string
                                            Implicitly print on separate lines





                                            share|improve this answer









                                            $endgroup$

















                                              1












                                              $begingroup$


                                              Charcoal, 14 bytes



                                              IEθ∨∧¬№ει⊕⌕ηιζ


                                              Try it online! Link is to verbose version of code. 1-indexed. Explanation:



                                               θ First input (x)
                                              E Map over elements
                                              ε Fourth input (incomparables)
                                              № Count occurrences of
                                              ι Current element
                                              ¬ Is zero
                                              ∧ Logical And
                                              η Second input (table)
                                              ⌕ Find 0-based index of
                                              ι Current element
                                              ⊕ Convert to 1-indexed
                                              ∨ Logical Or
                                              ζ Third input (nomatch)
                                              I Cast to string
                                              Implicitly print on separate lines





                                              share|improve this answer









                                              $endgroup$















                                                1












                                                1








                                                1





                                                $begingroup$


                                                Charcoal, 14 bytes



                                                IEθ∨∧¬№ει⊕⌕ηιζ


                                                Try it online! Link is to verbose version of code. 1-indexed. Explanation:



                                                 θ First input (x)
                                                E Map over elements
                                                ε Fourth input (incomparables)
                                                № Count occurrences of
                                                ι Current element
                                                ¬ Is zero
                                                ∧ Logical And
                                                η Second input (table)
                                                ⌕ Find 0-based index of
                                                ι Current element
                                                ⊕ Convert to 1-indexed
                                                ∨ Logical Or
                                                ζ Third input (nomatch)
                                                I Cast to string
                                                Implicitly print on separate lines





                                                share|improve this answer









                                                $endgroup$




                                                Charcoal, 14 bytes



                                                IEθ∨∧¬№ει⊕⌕ηιζ


                                                Try it online! Link is to verbose version of code. 1-indexed. Explanation:



                                                 θ First input (x)
                                                E Map over elements
                                                ε Fourth input (incomparables)
                                                № Count occurrences of
                                                ι Current element
                                                ¬ Is zero
                                                ∧ Logical And
                                                η Second input (table)
                                                ⌕ Find 0-based index of
                                                ι Current element
                                                ⊕ Convert to 1-indexed
                                                ∨ Logical Or
                                                ζ Third input (nomatch)
                                                I Cast to string
                                                Implicitly print on separate lines






                                                share|improve this answer












                                                share|improve this answer



                                                share|improve this answer










                                                answered 2 hours ago









                                                NeilNeil

                                                86.2k8 gold badges46 silver badges183 bronze badges




                                                86.2k8 gold badges46 silver badges183 bronze badges



























                                                    draft saved

                                                    draft discarded
















































                                                    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).




                                                    draft saved


                                                    draft discarded














                                                    StackExchange.ready(
                                                    function ()
                                                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodegolf.stackexchange.com%2fquestions%2f188162%2fmatchmaker-matchmaker-make-me-a-match%23new-answer', 'question_page');

                                                    );

                                                    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







                                                    Popular posts from this blog

                                                    Invision Community Contents History See also References External links Navigation menuProprietaryinvisioncommunity.comIPS Community ForumsIPS Community Forumsthis blog entry"License Changes, IP.Board 3.4, and the Future""Interview -- Matt Mecham of Ibforums""CEO Invision Power Board, Matt Mecham Is a Liar, Thief!"IPB License Explanation 1.3, 1.3.1, 2.0, and 2.1ArchivedSecurity Fixes, Updates And Enhancements For IPB 1.3.1Archived"New Demo Accounts - Invision Power Services"the original"New Default Skin"the original"Invision Power Board 3.0.0 and Applications Released"the original"Archived copy"the original"Perpetual licenses being done away with""Release Notes - Invision Power Services""Introducing: IPS Community Suite 4!"Invision Community Release Notes

                                                    Canceling a color specificationRandomly assigning color to Graphics3D objects?Default color for Filling in Mathematica 9Coloring specific elements of sets with a prime modified order in an array plotHow to pick a color differing significantly from the colors already in a given color list?Detection of the text colorColor numbers based on their valueCan color schemes for use with ColorData include opacity specification?My dynamic color schemes

                                                    Ласкавець круглолистий Зміст Опис | Поширення | Галерея | Примітки | Посилання | Навігаційне меню58171138361-22960890446Bupleurum rotundifoliumEuro+Med PlantbasePlants of the World Online — Kew ScienceGermplasm Resources Information Network (GRIN)Ласкавецькн. VI : Літери Ком — Левиправивши або дописавши її