A well linked challenge












5












$begingroup$


An activity I sometimes do when I'm bored is to write a couple of characters in matching pairs. I then draw lines (over the tops never below) to connect these characters. For example I might write $abcbac$ and then I would draw the lines as:



First Link



Or I might write $abbcac$



Second Link



Once I've drawn these lines I try to draw closed loops around chunks so that my loop doesn't intersect any of the lines I just drew. For example, in the first one the only loop we can draw is around the entire thing, but in the second one we can draw a loop around just the $b$s (or everything else)



Loop drawn



If we play around with this for a little while we will find that some strings can only be drawn so that closed loops contain all or none of the letters (like our first example). We will call such strings well linked strings.



Note that some strings can be drawn in multiple ways. For example $bbbb$ can be drawn in both of the following ways (and a third not included):



Way 1 or Way 2



If one of these ways can be drawn such that a closed loop can be made to contain some of the characters without intersecting any of the lines, then the string is not strongly linked. (so $bbbb$ is not strongly linked)



Task



Your task is to write a program to identify strings that are well linked. Your input will consist of a string where every character appears an even number of times, and your output should be one of two distinct consistent values, one if the strings are well linked and the other otherwise.



In addition your program must be a well linked string meaning




  • Every character appears an even number of times in your program.


  • It should output the truthy value when passed itself.



Answers will be scored as their lengths in bytes with fewer bytes being a better score.



Hint




A loop can be drawn around a contiguous substring iff there each character appears an even number of times in that substring.




Test Cases



abcbac -> True
abbcac -> False
bbbb -> False
abacbc -> True
abcbabcb -> True









share|improve this question









$endgroup$








  • 1




    $begingroup$
    Test case: abcbca -> False.
    $endgroup$
    – Ørjan Johansen
    2 hours ago










  • $begingroup$
    I think your hint contains a superfluous there.
    $endgroup$
    – Jonathan Frech
    2 hours ago
















5












$begingroup$


An activity I sometimes do when I'm bored is to write a couple of characters in matching pairs. I then draw lines (over the tops never below) to connect these characters. For example I might write $abcbac$ and then I would draw the lines as:



First Link



Or I might write $abbcac$



Second Link



Once I've drawn these lines I try to draw closed loops around chunks so that my loop doesn't intersect any of the lines I just drew. For example, in the first one the only loop we can draw is around the entire thing, but in the second one we can draw a loop around just the $b$s (or everything else)



Loop drawn



If we play around with this for a little while we will find that some strings can only be drawn so that closed loops contain all or none of the letters (like our first example). We will call such strings well linked strings.



Note that some strings can be drawn in multiple ways. For example $bbbb$ can be drawn in both of the following ways (and a third not included):



Way 1 or Way 2



If one of these ways can be drawn such that a closed loop can be made to contain some of the characters without intersecting any of the lines, then the string is not strongly linked. (so $bbbb$ is not strongly linked)



Task



Your task is to write a program to identify strings that are well linked. Your input will consist of a string where every character appears an even number of times, and your output should be one of two distinct consistent values, one if the strings are well linked and the other otherwise.



In addition your program must be a well linked string meaning




  • Every character appears an even number of times in your program.


  • It should output the truthy value when passed itself.



Answers will be scored as their lengths in bytes with fewer bytes being a better score.



Hint




A loop can be drawn around a contiguous substring iff there each character appears an even number of times in that substring.




Test Cases



abcbac -> True
abbcac -> False
bbbb -> False
abacbc -> True
abcbabcb -> True









share|improve this question









$endgroup$








  • 1




    $begingroup$
    Test case: abcbca -> False.
    $endgroup$
    – Ørjan Johansen
    2 hours ago










  • $begingroup$
    I think your hint contains a superfluous there.
    $endgroup$
    – Jonathan Frech
    2 hours ago














5












5








5





$begingroup$


An activity I sometimes do when I'm bored is to write a couple of characters in matching pairs. I then draw lines (over the tops never below) to connect these characters. For example I might write $abcbac$ and then I would draw the lines as:



First Link



Or I might write $abbcac$



Second Link



Once I've drawn these lines I try to draw closed loops around chunks so that my loop doesn't intersect any of the lines I just drew. For example, in the first one the only loop we can draw is around the entire thing, but in the second one we can draw a loop around just the $b$s (or everything else)



Loop drawn



If we play around with this for a little while we will find that some strings can only be drawn so that closed loops contain all or none of the letters (like our first example). We will call such strings well linked strings.



Note that some strings can be drawn in multiple ways. For example $bbbb$ can be drawn in both of the following ways (and a third not included):



Way 1 or Way 2



If one of these ways can be drawn such that a closed loop can be made to contain some of the characters without intersecting any of the lines, then the string is not strongly linked. (so $bbbb$ is not strongly linked)



Task



Your task is to write a program to identify strings that are well linked. Your input will consist of a string where every character appears an even number of times, and your output should be one of two distinct consistent values, one if the strings are well linked and the other otherwise.



In addition your program must be a well linked string meaning




  • Every character appears an even number of times in your program.


  • It should output the truthy value when passed itself.



Answers will be scored as their lengths in bytes with fewer bytes being a better score.



Hint




A loop can be drawn around a contiguous substring iff there each character appears an even number of times in that substring.




Test Cases



abcbac -> True
abbcac -> False
bbbb -> False
abacbc -> True
abcbabcb -> True









share|improve this question









$endgroup$




An activity I sometimes do when I'm bored is to write a couple of characters in matching pairs. I then draw lines (over the tops never below) to connect these characters. For example I might write $abcbac$ and then I would draw the lines as:



First Link



Or I might write $abbcac$



Second Link



Once I've drawn these lines I try to draw closed loops around chunks so that my loop doesn't intersect any of the lines I just drew. For example, in the first one the only loop we can draw is around the entire thing, but in the second one we can draw a loop around just the $b$s (or everything else)



Loop drawn



If we play around with this for a little while we will find that some strings can only be drawn so that closed loops contain all or none of the letters (like our first example). We will call such strings well linked strings.



Note that some strings can be drawn in multiple ways. For example $bbbb$ can be drawn in both of the following ways (and a third not included):



Way 1 or Way 2



If one of these ways can be drawn such that a closed loop can be made to contain some of the characters without intersecting any of the lines, then the string is not strongly linked. (so $bbbb$ is not strongly linked)



Task



Your task is to write a program to identify strings that are well linked. Your input will consist of a string where every character appears an even number of times, and your output should be one of two distinct consistent values, one if the strings are well linked and the other otherwise.



In addition your program must be a well linked string meaning




  • Every character appears an even number of times in your program.


  • It should output the truthy value when passed itself.



Answers will be scored as their lengths in bytes with fewer bytes being a better score.



Hint




A loop can be drawn around a contiguous substring iff there each character appears an even number of times in that substring.




Test Cases



abcbac -> True
abbcac -> False
bbbb -> False
abacbc -> True
abcbabcb -> True






code-golf decision-problem restricted-source






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked 2 hours ago









TRITICIMAGVSTRITICIMAGVS

34.2k10156367




34.2k10156367








  • 1




    $begingroup$
    Test case: abcbca -> False.
    $endgroup$
    – Ørjan Johansen
    2 hours ago










  • $begingroup$
    I think your hint contains a superfluous there.
    $endgroup$
    – Jonathan Frech
    2 hours ago














  • 1




    $begingroup$
    Test case: abcbca -> False.
    $endgroup$
    – Ørjan Johansen
    2 hours ago










  • $begingroup$
    I think your hint contains a superfluous there.
    $endgroup$
    – Jonathan Frech
    2 hours ago








1




1




$begingroup$
Test case: abcbca -> False.
$endgroup$
– Ørjan Johansen
2 hours ago




$begingroup$
Test case: abcbca -> False.
$endgroup$
– Ørjan Johansen
2 hours ago












$begingroup$
I think your hint contains a superfluous there.
$endgroup$
– Jonathan Frech
2 hours ago




$begingroup$
I think your hint contains a superfluous there.
$endgroup$
– Jonathan Frech
2 hours ago










2 Answers
2






active

oldest

votes


















1












$begingroup$

Jelly, 20 bytes



ĠẈḂẸẆṖÇ€Ạ
ĠẈḂẸ
ẆṖÇ€Ạ


Try it online!



The first line is ignored. It's only there to satisfy the condition that every character appear an even number of times.



The next line first Ġroups indices by their value. If we then take the length of each sublist in the resulting list (), we get the number of times each character appears. To check whether any of these are non-even, we get the last it of each count and ask whether there xists a truthy (nonzero) value.



Therefore, this helper link returns whether a substring cannot be circled.



In the main link, we take all substrings of the input (), op off the last one (so that we don't check whether the entire string can be circled), and run the helper link (Ç) on ach substring. The result is then whether ll substrings cannot be circled.






share|improve this answer











$endgroup$





















    0












    $begingroup$


    Retina, 41 bytes



    Lw`.+
    N$^`
    $.&
    0A`
    %O`.
    (.)1

    ^.+(¶.+)+$


    Try it online! Link includes test cases. Explanation:



    Lw`.+


    List all of the substrings. (This lists the odd ones as well, but we don't care.)



    N$^`
    $.&
    0A`


    Sort the substrings in reverse order of length so that we can remove the original string.



    %O`.


    Sort the characters in each substring.



    (.)1


    Remove duplicated characters, thus checking whether they appear an even number of times.



    ^.+(¶.+)+$


    Check whether no substring could be circled.






    share|improve this answer









    $endgroup$













    • $begingroup$
      This seems not to satisfy the restricted source requirements.
      $endgroup$
      – Ørjan Johansen
      1 hour ago











    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
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodegolf.stackexchange.com%2fquestions%2f179422%2fa-well-linked-challenge%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    1












    $begingroup$

    Jelly, 20 bytes



    ĠẈḂẸẆṖÇ€Ạ
    ĠẈḂẸ
    ẆṖÇ€Ạ


    Try it online!



    The first line is ignored. It's only there to satisfy the condition that every character appear an even number of times.



    The next line first Ġroups indices by their value. If we then take the length of each sublist in the resulting list (), we get the number of times each character appears. To check whether any of these are non-even, we get the last it of each count and ask whether there xists a truthy (nonzero) value.



    Therefore, this helper link returns whether a substring cannot be circled.



    In the main link, we take all substrings of the input (), op off the last one (so that we don't check whether the entire string can be circled), and run the helper link (Ç) on ach substring. The result is then whether ll substrings cannot be circled.






    share|improve this answer











    $endgroup$


















      1












      $begingroup$

      Jelly, 20 bytes



      ĠẈḂẸẆṖÇ€Ạ
      ĠẈḂẸ
      ẆṖÇ€Ạ


      Try it online!



      The first line is ignored. It's only there to satisfy the condition that every character appear an even number of times.



      The next line first Ġroups indices by their value. If we then take the length of each sublist in the resulting list (), we get the number of times each character appears. To check whether any of these are non-even, we get the last it of each count and ask whether there xists a truthy (nonzero) value.



      Therefore, this helper link returns whether a substring cannot be circled.



      In the main link, we take all substrings of the input (), op off the last one (so that we don't check whether the entire string can be circled), and run the helper link (Ç) on ach substring. The result is then whether ll substrings cannot be circled.






      share|improve this answer











      $endgroup$
















        1












        1








        1





        $begingroup$

        Jelly, 20 bytes



        ĠẈḂẸẆṖÇ€Ạ
        ĠẈḂẸ
        ẆṖÇ€Ạ


        Try it online!



        The first line is ignored. It's only there to satisfy the condition that every character appear an even number of times.



        The next line first Ġroups indices by their value. If we then take the length of each sublist in the resulting list (), we get the number of times each character appears. To check whether any of these are non-even, we get the last it of each count and ask whether there xists a truthy (nonzero) value.



        Therefore, this helper link returns whether a substring cannot be circled.



        In the main link, we take all substrings of the input (), op off the last one (so that we don't check whether the entire string can be circled), and run the helper link (Ç) on ach substring. The result is then whether ll substrings cannot be circled.






        share|improve this answer











        $endgroup$



        Jelly, 20 bytes



        ĠẈḂẸẆṖÇ€Ạ
        ĠẈḂẸ
        ẆṖÇ€Ạ


        Try it online!



        The first line is ignored. It's only there to satisfy the condition that every character appear an even number of times.



        The next line first Ġroups indices by their value. If we then take the length of each sublist in the resulting list (), we get the number of times each character appears. To check whether any of these are non-even, we get the last it of each count and ask whether there xists a truthy (nonzero) value.



        Therefore, this helper link returns whether a substring cannot be circled.



        In the main link, we take all substrings of the input (), op off the last one (so that we don't check whether the entire string can be circled), and run the helper link (Ç) on ach substring. The result is then whether ll substrings cannot be circled.







        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited 1 hour ago

























        answered 2 hours ago









        DoorknobDoorknob

        54.4k17114347




        54.4k17114347























            0












            $begingroup$


            Retina, 41 bytes



            Lw`.+
            N$^`
            $.&
            0A`
            %O`.
            (.)1

            ^.+(¶.+)+$


            Try it online! Link includes test cases. Explanation:



            Lw`.+


            List all of the substrings. (This lists the odd ones as well, but we don't care.)



            N$^`
            $.&
            0A`


            Sort the substrings in reverse order of length so that we can remove the original string.



            %O`.


            Sort the characters in each substring.



            (.)1


            Remove duplicated characters, thus checking whether they appear an even number of times.



            ^.+(¶.+)+$


            Check whether no substring could be circled.






            share|improve this answer









            $endgroup$













            • $begingroup$
              This seems not to satisfy the restricted source requirements.
              $endgroup$
              – Ørjan Johansen
              1 hour ago
















            0












            $begingroup$


            Retina, 41 bytes



            Lw`.+
            N$^`
            $.&
            0A`
            %O`.
            (.)1

            ^.+(¶.+)+$


            Try it online! Link includes test cases. Explanation:



            Lw`.+


            List all of the substrings. (This lists the odd ones as well, but we don't care.)



            N$^`
            $.&
            0A`


            Sort the substrings in reverse order of length so that we can remove the original string.



            %O`.


            Sort the characters in each substring.



            (.)1


            Remove duplicated characters, thus checking whether they appear an even number of times.



            ^.+(¶.+)+$


            Check whether no substring could be circled.






            share|improve this answer









            $endgroup$













            • $begingroup$
              This seems not to satisfy the restricted source requirements.
              $endgroup$
              – Ørjan Johansen
              1 hour ago














            0












            0








            0





            $begingroup$


            Retina, 41 bytes



            Lw`.+
            N$^`
            $.&
            0A`
            %O`.
            (.)1

            ^.+(¶.+)+$


            Try it online! Link includes test cases. Explanation:



            Lw`.+


            List all of the substrings. (This lists the odd ones as well, but we don't care.)



            N$^`
            $.&
            0A`


            Sort the substrings in reverse order of length so that we can remove the original string.



            %O`.


            Sort the characters in each substring.



            (.)1


            Remove duplicated characters, thus checking whether they appear an even number of times.



            ^.+(¶.+)+$


            Check whether no substring could be circled.






            share|improve this answer









            $endgroup$




            Retina, 41 bytes



            Lw`.+
            N$^`
            $.&
            0A`
            %O`.
            (.)1

            ^.+(¶.+)+$


            Try it online! Link includes test cases. Explanation:



            Lw`.+


            List all of the substrings. (This lists the odd ones as well, but we don't care.)



            N$^`
            $.&
            0A`


            Sort the substrings in reverse order of length so that we can remove the original string.



            %O`.


            Sort the characters in each substring.



            (.)1


            Remove duplicated characters, thus checking whether they appear an even number of times.



            ^.+(¶.+)+$


            Check whether no substring could be circled.







            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered 1 hour ago









            NeilNeil

            80.3k744178




            80.3k744178












            • $begingroup$
              This seems not to satisfy the restricted source requirements.
              $endgroup$
              – Ørjan Johansen
              1 hour ago


















            • $begingroup$
              This seems not to satisfy the restricted source requirements.
              $endgroup$
              – Ørjan Johansen
              1 hour ago
















            $begingroup$
            This seems not to satisfy the restricted source requirements.
            $endgroup$
            – Ørjan Johansen
            1 hour ago




            $begingroup$
            This seems not to satisfy the restricted source requirements.
            $endgroup$
            – Ørjan Johansen
            1 hour ago


















            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%2f179422%2fa-well-linked-challenge%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

            A CLEAN and SIMPLE way to add appendices to Table of Contents and bookmarks

            Calculate evaluation metrics using cross_val_predict sklearn

            Insert data from modal to MySQL (multiple modal on website)