Senin, 18 Maret 2019

Would this string work as string?





















19
























$begingroup$





Write a program that takes a single line string that you can assume will only contain the characters /_‾. (That's forward and backward slash, underline and overline. You can use ~ in place of overline if you need since overline is not convenient ASCII.)



For example, one possible input is:



__/‾‾/_/‾



Your program needs to output a truthy or falsy value depending on whether the left edge of the string is "connected", so to speak, to the right edge of the string via the lines of the characters. So, if the kerning was a bit less, there would be a solid black (albeit kinky) line all the way from the left edge to the right, like an unbroken piece of string or twine.



The output for the above example would be true because the edges are connected:



example path



To be clear on the connections:





  • / connects on its bottom left and top right


  • connects on its top left and bottom right


  • _ connects on its bottom left and bottom right


  • (or ~) connects on its top left and top right


Also:




  • It doesn't matter whether the edges of the string started on the top or the bottom, it only matters that they connect horizontally through the whole length of the string.


  • You can assume the input string is non-empty, and of course just one line.



Here are some more examples followed by 1 (truthy) if they are connected or 0 (falsy) if not:



__/‾‾/_/‾

1



_

1





1



/

1





1



___

1



/

1



//

1



//

1



‾‾‾

1



\

0



‾‾

1



_‾

0



‾_

0



_____/

1



/\/\___

0



/__/‾‾

1



______/_____

1



‾‾‾‾‾‾\_____

0



‾‾‾‾‾‾______

1



_____/‾‾‾‾‾

1



___/‾‾‾___/‾‾‾

1



_/__

0



_/_

1



////////////

1



____________________

1



‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾

1



‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾/

0



‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾

1



/‾/‾___/|_|/__/‾‾

0



The shortest code is the winner.

















share|improve this question














New contributor









Discrete Games is a new contributor to this site. Take care in asking for clarification, commenting, and answering.

Check out our Code of Conduct.














$endgroup$
















  • 4









    $begingroup$

    Welcome to PPCG! Nice first challenge.

    $endgroup$

    – AdmBorkBork

    1 hour ago





















  • $begingroup$

    Are the characters specified in your challenge the only ones that will appear in the string?

    $endgroup$

    – Embodiment of Ignorance

    1 hour ago





















  • $begingroup$

    @EmbodimentofIgnorance Yes, only the 4.

    $endgroup$

    – Discrete Games

    1 hour ago






























19
























$begingroup$





Write a program that takes a single line string that you can assume will only contain the characters /_‾. (That's forward and backward slash, underline and overline. You can use ~ in place of overline if you need since overline is not convenient ASCII.)



For example, one possible input is:



__/‾‾/_/‾



Your program needs to output a truthy or falsy value depending on whether the left edge of the string is "connected", so to speak, to the right edge of the string via the lines of the characters. So, if the kerning was a bit less, there would be a solid black (albeit kinky) line all the way from the left edge to the right, like an unbroken piece of string or twine.



The output for the above example would be true because the edges are connected:



example path



To be clear on the connections:





  • / connects on its bottom left and top right


  • connects on its top left and bottom right


  • _ connects on its bottom left and bottom right


  • (or ~) connects on its top left and top right


Also:




  • It doesn't matter whether the edges of the string started on the top or the bottom, it only matters that they connect horizontally through the whole length of the string.


  • You can assume the input string is non-empty, and of course just one line.



Here are some more examples followed by 1 (truthy) if they are connected or 0 (falsy) if not:



__/‾‾/_/‾

1



_

1





1



/

1





1



___

1



/

1



//

1



//

1



‾‾‾

1



\

0



‾‾

1



_‾

0



‾_

0



_____/

1



/\/\___

0



/__/‾‾

1



______/_____

1



‾‾‾‾‾‾\_____

0



‾‾‾‾‾‾______

1



_____/‾‾‾‾‾

1



___/‾‾‾___/‾‾‾

1



_/__

0



_/_

1



////////////

1



____________________

1



‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾

1



‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾/

0



‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾

1



/‾/‾___/|_|/__/‾‾

0



The shortest code is the winner.

















share|improve this question














New contributor









Discrete Games is a new contributor to this site. Take care in asking for clarification, commenting, and answering.

Check out our Code of Conduct.














$endgroup$
















  • 4









    $begingroup$

    Welcome to PPCG! Nice first challenge.

    $endgroup$

    – AdmBorkBork

    1 hour ago





















  • $begingroup$

    Are the characters specified in your challenge the only ones that will appear in the string?

    $endgroup$

    – Embodiment of Ignorance

    1 hour ago





















  • $begingroup$

    @EmbodimentofIgnorance Yes, only the 4.

    $endgroup$

    – Discrete Games

    1 hour ago


























19






















19














19


2




$begingroup$





Write a program that takes a single line string that you can assume will only contain the characters /_‾. (That's forward and backward slash, underline and overline. You can use ~ in place of overline if you need since overline is not convenient ASCII.)



For example, one possible input is:



__/‾‾/_/‾



Your program needs to output a truthy or falsy value depending on whether the left edge of the string is "connected", so to speak, to the right edge of the string via the lines of the characters. So, if the kerning was a bit less, there would be a solid black (albeit kinky) line all the way from the left edge to the right, like an unbroken piece of string or twine.



The output for the above example would be true because the edges are connected:



example path



To be clear on the connections:





  • / connects on its bottom left and top right


  • connects on its top left and bottom right


  • _ connects on its bottom left and bottom right


  • (or ~) connects on its top left and top right


Also:




  • It doesn't matter whether the edges of the string started on the top or the bottom, it only matters that they connect horizontally through the whole length of the string.


  • You can assume the input string is non-empty, and of course just one line.



Here are some more examples followed by 1 (truthy) if they are connected or 0 (falsy) if not:



__/‾‾/_/‾

1



_

1





1



/

1





1



___

1



/

1



//

1



//

1



‾‾‾

1



\

0



‾‾

1



_‾

0



‾_

0



_____/

1



/\/\___

0



/__/‾‾

1



______/_____

1



‾‾‾‾‾‾\_____

0



‾‾‾‾‾‾______

1



_____/‾‾‾‾‾

1



___/‾‾‾___/‾‾‾

1



_/__

0



_/_

1



////////////

1



____________________

1



‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾

1



‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾/

0



‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾

1



/‾/‾___/|_|/__/‾‾

0



The shortest code is the winner.

















share|improve this question














New contributor









Discrete Games is a new contributor to this site. Take care in asking for clarification, commenting, and answering.

Check out our Code of Conduct.














$endgroup$







Write a program that takes a single line string that you can assume will only contain the characters /_‾. (That's forward and backward slash, underline and overline. You can use ~ in place of overline if you need since overline is not convenient ASCII.)



For example, one possible input is:



__/‾‾/_/‾



Your program needs to output a truthy or falsy value depending on whether the left edge of the string is "connected", so to speak, to the right edge of the string via the lines of the characters. So, if the kerning was a bit less, there would be a solid black (albeit kinky) line all the way from the left edge to the right, like an unbroken piece of string or twine.



The output for the above example would be true because the edges are connected:



example path



To be clear on the connections:





  • / connects on its bottom left and top right


  • connects on its top left and bottom right


  • _ connects on its bottom left and bottom right


  • (or ~) connects on its top left and top right


Also:




  • It doesn't matter whether the edges of the string started on the top or the bottom, it only matters that they connect horizontally through the whole length of the string.


  • You can assume the input string is non-empty, and of course just one line.



Here are some more examples followed by 1 (truthy) if they are connected or 0 (falsy) if not:



__/‾‾/_/‾

1



_

1





1



/

1





1



___

1



/

1



//

1



//

1



‾‾‾

1



\

0



‾‾

1



_‾

0



‾_

0



_____/

1



/\/\___

0



/__/‾‾

1



______/_____

1



‾‾‾‾‾‾\_____

0



‾‾‾‾‾‾______

1



_____/‾‾‾‾‾

1



___/‾‾‾___/‾‾‾

1



_/__

0



_/_

1



////////////

1



____________________

1



‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾

1



‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾/

0



‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾

1



/‾/‾___/|_|/__/‾‾

0



The shortest code is the winner.








code-golf string decision-problem










share|improve this question














New contributor









Discrete Games is a new contributor to this site. Take care in asking for clarification, commenting, and answering.

Check out our Code of Conduct.



















share|improve this question














New contributor









Discrete Games is a new contributor to this site. Take care in asking for clarification, commenting, and answering.

Check out our Code of Conduct.















share|improve this question





share|improve this question










New contributor









Discrete Games is a new contributor to this site. Take care in asking for clarification, commenting, and answering.

Check out our Code of Conduct.














asked 1 hour ago













Discrete GamesDiscrete Games



963







963







New contributor









Discrete Games is a new contributor to this site. Take care in asking for clarification, commenting, and answering.

Check out our Code of Conduct.








New contributor









Discrete Games is a new contributor to this site. Take care in asking for clarification, commenting, and answering.

Check out our Code of Conduct.








Discrete Games is a new contributor to this site. Take care in asking for clarification, commenting, and answering.

Check out our Code of Conduct.













  • 4









    $begingroup$

    Welcome to PPCG! Nice first challenge.

    $endgroup$

    – AdmBorkBork

    1 hour ago





















  • $begingroup$

    Are the characters specified in your challenge the only ones that will appear in the string?

    $endgroup$

    – Embodiment of Ignorance

    1 hour ago





















  • $begingroup$

    @EmbodimentofIgnorance Yes, only the 4.

    $endgroup$

    – Discrete Games

    1 hour ago

























  • 4









    $begingroup$

    Welcome to PPCG! Nice first challenge.

    $endgroup$

    – AdmBorkBork

    1 hour ago





















  • $begingroup$

    Are the characters specified in your challenge the only ones that will appear in the string?

    $endgroup$

    – Embodiment of Ignorance

    1 hour ago





















  • $begingroup$

    @EmbodimentofIgnorance Yes, only the 4.

    $endgroup$

    – Discrete Games

    1 hour ago














4







4







$begingroup$

Welcome to PPCG! Nice first challenge.

$endgroup$

– AdmBorkBork

1 hour ago







$begingroup$

Welcome to PPCG! Nice first challenge.

$endgroup$

– AdmBorkBork

1 hour ago



















$begingroup$

Are the characters specified in your challenge the only ones that will appear in the string?

$endgroup$

– Embodiment of Ignorance

1 hour ago







$begingroup$

Are the characters specified in your challenge the only ones that will appear in the string?

$endgroup$

– Embodiment of Ignorance

1 hour ago



















$begingroup$

@EmbodimentofIgnorance Yes, only the 4.

$endgroup$

– Discrete Games

1 hour ago







$begingroup$

@EmbodimentofIgnorance Yes, only the 4.

$endgroup$

– Discrete Games

1 hour ago

















8 Answers

8











active



oldest



votes





































6
























$begingroup$




Ruby -n, 30 bytes





p !/[_\][\‾]|[/‾][_/]/



Try it online!



Reduces all of the string-breaking sequences to two cases using Regex character classes.









share|improve this answer


















$endgroup$


















  • 2









    $begingroup$

    You can save 4 bytes by using ~ instead of . I'm not sure if it matters for this challenge, since the character count is the same.

    $endgroup$

    – iamnotmaynard

    36 mins ago






































5
























$begingroup$



JavaScript (ES6), 45 bytes



The naive way.





s=>!///|\\|_~|~_|~/|_\|/_|\~/.test(s)



Try it online!









share|improve this answer






















$endgroup$


























  • $begingroup$

    So this is checking all the invalid pairings, making sure they don't exist in the string? Smart.

    $endgroup$

    – Discrete Games

    1 hour ago





















  • $begingroup$

    @DiscreteGames Yes, exactly. (Except that I forgot 2 of them. Now fixed.)

    $endgroup$

    – Arnauld

    1 hour ago






































3
























$begingroup$



Python 3, 126 bytes



lambda s,d={'‾':'‾','_':'/_','/':'‾','\':'/_'}:len(s)<2or all([s[i+1] in d[s[i]]for i in range(len(s)-1)if s[i]in d])









share|improve this answer


















$endgroup$










































    3
























    $begingroup$




    C (gcc), 93 bytes





    w,o,r;k(char*_){for(r=0;w=*_,o=*++_;)r|=w-126&&w>47?w-95&&w-92?0:o>47&&o-95:o-92&&o<126;_=r;}



    Try it online!









    share|improve this answer


















    $endgroup$










































      3
























      $begingroup$




      05AB1E, 29 bytes



      „_~SD2×s:Çü-т+•6_üê{↕ƵΔвåO_



      It sounded shorter in my head.. Will try to golf it down from here.



      Try it online or verify all test cases.



      Explanation:"





      „_~S                          # Push the characters ["_","~"]

      D2× # Duplicate it, and increase each to size 2: ["__","~~"]

      s: # Swap and replace all "__" with "_" and all "~~" with "~"

      # in the (implicit) input-string

      Ç # Convert the remaining characters to unicode values

      ü- # Calculate the difference between each pair

      т+ # Add 100 to each

      •6_üê{↕ # Push compressed integer 1781179816800959

      ƵΔ # Push compressed integer 180

      в # Convert the larger integer to Base-180 as list:

      # [52,66,69,100,103,131,179]

      å # Check for each if it's in the difference-list

      # (1 if present; 0 if not)

      O # Sum the truthy values

      _ # Check if this sum is exactly 0 (1 if 0; 0 otherwise)

      # (and output this result implicitly)



      See this 05AB1E tip of mine (sections How to comrpess large integers? and How to compress integer lists?) to understand why •6_üê{↕ is 1781179816800959, ƵΔ is 180 and •6_üê{↕ƵΔв is [52,66,69,100,103,131,179].



      Additional explanation:



      There are 16 ($2^4$) possible pairs of characters we have to verify. If we convert each character to its unicode value, and calculate the differences, we would get these differences. Because compressed integer lists in 05AB1E has to have positive integers only, I add 100 to each. The invalid pairs and their corresponding values are then: ["/_", 52]; ["~", 66], ["_~", 69], ["//", 100], ["\", 100], ["_", 103], ["~_", 131], ["~/", 179], which is why I have the compressed integer list in my code containing these values.

      Since __ and ~~ will just like // and \ result in 0 (or 100 after I add 100), I first remove any adjacent duplicates of ~ and _ in the input-string, before calculating and verifying the pair-differences.









      share|improve this answer






















      $endgroup$










































        2
























        $begingroup$




        Python 3, 80 78 bytes



        I don't realy do many python code golfs but I thought I could give it a try




        • -2 bytes: realised not(any()) is the same as all(not()) and could move the not into the r-string


        def f(x):*l,=map(r'_/~'.find,x);return 1-any((i^j//2)%2for i,j in zip(l,l[1:]))



        Try it online!




        Python 3.8 (pre-release), 71 bytes



        I wanted to try out the new := expression assignment





        lambda x:all((i^j//2)%2for i,j in zip(l:=[*map(r'~_/'.find,x)],l[1:]))



        Try it online!









        share|improve this answer






















        $endgroup$










































          1
























          $begingroup$




          Jelly, 14 bytes



          Supports (and expects) the character in the input string. Returns $0$ or $1$.



          O*Ɲ×12%29%15ḂẠ



          Try it online!



          O*Ɲ×12%29%15ḂẠ  - main link, taking a string          e.g. "_/"

          O - get ASCII codes --> [92, 95, 47]

          *Ɲ - exponentiation on all pairs --> [92**95, 95**97]

          ×12 - multiply by 12 --> [(92**95)*12, (95**97)*12]

          %29 - modulo 29 --> [11, 24]

          %15 - modulo 15 --> [11, 9]

          Ḃ - least significant bit (i.e. parity) --> [1, 1]

          Ạ - all values equal to 1? --> 1









          share|improve this answer






















          $endgroup$










































            0
























            $begingroup$




            Dart, 94 bytes



            f(s)=>!(r'//,\,~/,_,~_,_~,/_,~'.split(',').map((t)=>s.contains(t)).fold(false,(p,e)=>p|e));



            Try it online!









            share|improve this answer


















            $endgroup$


























              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

              });





              }

              });













              Discrete Games is a new contributor. Be nice, and check out our Code of Conduct.




















              draft saved


              draft discarded



































              StackExchange.ready(

              function () {

              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodegolf.stackexchange.com%2fquestions%2f181708%2fwould-this-string-work-as-string%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

















              6
























              $begingroup$




              Ruby -n, 30 bytes





              p !/[_\][\‾]|[/‾][_/]/



              Try it online!



              Reduces all of the string-breaking sequences to two cases using Regex character classes.









              share|improve this answer


















              $endgroup$


















              • 2









                $begingroup$

                You can save 4 bytes by using ~ instead of . I'm not sure if it matters for this challenge, since the character count is the same.

                $endgroup$

                – iamnotmaynard

                36 mins ago






























              6
























              $begingroup$




              Ruby -n, 30 bytes





              p !/[_\][\‾]|[/‾][_/]/



              Try it online!



              Reduces all of the string-breaking sequences to two cases using Regex character classes.









              share|improve this answer


















              $endgroup$


















              • 2









                $begingroup$

                You can save 4 bytes by using ~ instead of . I'm not sure if it matters for this challenge, since the character count is the same.

                $endgroup$

                – iamnotmaynard

                36 mins ago


























              6






















              6














              6






              $begingroup$




              Ruby -n, 30 bytes





              p !/[_\][\‾]|[/‾][_/]/



              Try it online!



              Reduces all of the string-breaking sequences to two cases using Regex character classes.









              share|improve this answer


















              $endgroup$






              Ruby -n, 30 bytes





              p !/[_\][\‾]|[/‾][_/]/



              Try it online!



              Reduces all of the string-breaking sequences to two cases using Regex character classes.









              share|improve this answer





















              share|improve this answer



              share|improve this answer














              answered 1 hour ago













              histocrathistocrat



              19.1k43172







              19.1k43172














              • 2









                $begingroup$

                You can save 4 bytes by using ~ instead of . I'm not sure if it matters for this challenge, since the character count is the same.

                $endgroup$

                – iamnotmaynard

                36 mins ago

























              • 2









                $begingroup$

                You can save 4 bytes by using ~ instead of . I'm not sure if it matters for this challenge, since the character count is the same.

                $endgroup$

                – iamnotmaynard

                36 mins ago














              2







              2







              $begingroup$

              You can save 4 bytes by using ~ instead of . I'm not sure if it matters for this challenge, since the character count is the same.

              $endgroup$

              – iamnotmaynard

              36 mins ago







              $begingroup$

              You can save 4 bytes by using ~ instead of . I'm not sure if it matters for this challenge, since the character count is the same.

              $endgroup$

              – iamnotmaynard

              36 mins ago



















              5
























              $begingroup$



              JavaScript (ES6), 45 bytes



              The naive way.





              s=>!///|\\|_~|~_|~/|_\|/_|\~/.test(s)



              Try it online!









              share|improve this answer






















              $endgroup$


























              • $begingroup$

                So this is checking all the invalid pairings, making sure they don't exist in the string? Smart.

                $endgroup$

                – Discrete Games

                1 hour ago





















              • $begingroup$

                @DiscreteGames Yes, exactly. (Except that I forgot 2 of them. Now fixed.)

                $endgroup$

                – Arnauld

                1 hour ago






























              5
























              $begingroup$



              JavaScript (ES6), 45 bytes



              The naive way.





              s=>!///|\\|_~|~_|~/|_\|/_|\~/.test(s)



              Try it online!









              share|improve this answer






















              $endgroup$


























              • $begingroup$

                So this is checking all the invalid pairings, making sure they don't exist in the string? Smart.

                $endgroup$

                – Discrete Games

                1 hour ago





















              • $begingroup$

                @DiscreteGames Yes, exactly. (Except that I forgot 2 of them. Now fixed.)

                $endgroup$

                – Arnauld

                1 hour ago


























              5






















              5














              5






              $begingroup$



              JavaScript (ES6), 45 bytes



              The naive way.





              s=>!///|\\|_~|~_|~/|_\|/_|\~/.test(s)



              Try it online!









              share|improve this answer






















              $endgroup$





              JavaScript (ES6), 45 bytes



              The naive way.





              s=>!///|\\|_~|~_|~/|_\|/_|\~/.test(s)



              Try it online!









              share|improve this answer

























              share|improve this answer



              share|improve this answer










              edited 1 hour ago







































              answered 1 hour ago













              ArnauldArnauld



              78.9k795327







              78.9k795327






















              • $begingroup$

                So this is checking all the invalid pairings, making sure they don't exist in the string? Smart.

                $endgroup$

                – Discrete Games

                1 hour ago





















              • $begingroup$

                @DiscreteGames Yes, exactly. (Except that I forgot 2 of them. Now fixed.)

                $endgroup$

                – Arnauld

                1 hour ago

































              • $begingroup$

                So this is checking all the invalid pairings, making sure they don't exist in the string? Smart.

                $endgroup$

                – Discrete Games

                1 hour ago





















              • $begingroup$

                @DiscreteGames Yes, exactly. (Except that I forgot 2 of them. Now fixed.)

                $endgroup$

                – Arnauld

                1 hour ago


























              $begingroup$

              So this is checking all the invalid pairings, making sure they don't exist in the string? Smart.

              $endgroup$

              – Discrete Games

              1 hour ago







              $begingroup$

              So this is checking all the invalid pairings, making sure they don't exist in the string? Smart.

              $endgroup$

              – Discrete Games

              1 hour ago



















              $begingroup$

              @DiscreteGames Yes, exactly. (Except that I forgot 2 of them. Now fixed.)

              $endgroup$

              – Arnauld

              1 hour ago







              $begingroup$

              @DiscreteGames Yes, exactly. (Except that I forgot 2 of them. Now fixed.)

              $endgroup$

              – Arnauld

              1 hour ago



















              3
























              $begingroup$



              Python 3, 126 bytes



              lambda s,d={'‾':'‾','_':'/_','/':'‾','\':'/_'}:len(s)<2or all([s[i+1] in d[s[i]]for i in range(len(s)-1)if s[i]in d])









              share|improve this answer


















              $endgroup$


































                3
























                $begingroup$



                Python 3, 126 bytes



                lambda s,d={'‾':'‾','_':'/_','/':'‾','\':'/_'}:len(s)<2or all([s[i+1] in d[s[i]]for i in range(len(s)-1)if s[i]in d])









                share|improve this answer


















                $endgroup$






























                  3






















                  3














                  3






                  $begingroup$



                  Python 3, 126 bytes



                  lambda s,d={'‾':'‾','_':'/_','/':'‾','\':'/_'}:len(s)<2or all([s[i+1] in d[s[i]]for i in range(len(s)-1)if s[i]in d])









                  share|improve this answer


















                  $endgroup$





                  Python 3, 126 bytes



                  lambda s,d={'‾':'‾','_':'/_','/':'‾','\':'/_'}:len(s)<2or all([s[i+1] in d[s[i]]for i in range(len(s)-1)if s[i]in d])









                  share|improve this answer





















                  share|improve this answer



                  share|improve this answer














                  answered 1 hour ago













                  Henry THenry T



                  1716







                  1716





































                      3
























                      $begingroup$




                      C (gcc), 93 bytes





                      w,o,r;k(char*_){for(r=0;w=*_,o=*++_;)r|=w-126&&w>47?w-95&&w-92?0:o>47&&o-95:o-92&&o<126;_=r;}



                      Try it online!









                      share|improve this answer


















                      $endgroup$


































                        3
























                        $begingroup$




                        C (gcc), 93 bytes





                        w,o,r;k(char*_){for(r=0;w=*_,o=*++_;)r|=w-126&&w>47?w-95&&w-92?0:o>47&&o-95:o-92&&o<126;_=r;}



                        Try it online!









                        share|improve this answer


















                        $endgroup$






























                          3






















                          3














                          3






                          $begingroup$




                          C (gcc), 93 bytes





                          w,o,r;k(char*_){for(r=0;w=*_,o=*++_;)r|=w-126&&w>47?w-95&&w-92?0:o>47&&o-95:o-92&&o<126;_=r;}



                          Try it online!









                          share|improve this answer


















                          $endgroup$






                          C (gcc), 93 bytes





                          w,o,r;k(char*_){for(r=0;w=*_,o=*++_;)r|=w-126&&w>47?w-95&&w-92?0:o>47&&o-95:o-92&&o<126;_=r;}



                          Try it online!









                          share|improve this answer





















                          share|improve this answer



                          share|improve this answer














                          answered 1 hour ago













                          Jonathan FrechJonathan Frech



                          6,41311040







                          6,41311040





































                              3
























                              $begingroup$




                              05AB1E, 29 bytes



                              „_~SD2×s:Çü-т+•6_üê{↕ƵΔвåO_



                              It sounded shorter in my head.. Will try to golf it down from here.



                              Try it online or verify all test cases.



                              Explanation:"





                              „_~S                          # Push the characters ["_","~"]

                              D2× # Duplicate it, and increase each to size 2: ["__","~~"]

                              s: # Swap and replace all "__" with "_" and all "~~" with "~"

                              # in the (implicit) input-string

                              Ç # Convert the remaining characters to unicode values

                              ü- # Calculate the difference between each pair

                              т+ # Add 100 to each

                              •6_üê{↕ # Push compressed integer 1781179816800959

                              ƵΔ # Push compressed integer 180

                              в # Convert the larger integer to Base-180 as list:

                              # [52,66,69,100,103,131,179]

                              å # Check for each if it's in the difference-list

                              # (1 if present; 0 if not)

                              O # Sum the truthy values

                              _ # Check if this sum is exactly 0 (1 if 0; 0 otherwise)

                              # (and output this result implicitly)



                              See this 05AB1E tip of mine (sections How to comrpess large integers? and How to compress integer lists?) to understand why •6_üê{↕ is 1781179816800959, ƵΔ is 180 and •6_üê{↕ƵΔв is [52,66,69,100,103,131,179].



                              Additional explanation:



                              There are 16 ($2^4$) possible pairs of characters we have to verify. If we convert each character to its unicode value, and calculate the differences, we would get these differences. Because compressed integer lists in 05AB1E has to have positive integers only, I add 100 to each. The invalid pairs and their corresponding values are then: ["/_", 52]; ["~", 66], ["_~", 69], ["//", 100], ["\", 100], ["_", 103], ["~_", 131], ["~/", 179], which is why I have the compressed integer list in my code containing these values.

                              Since __ and ~~ will just like // and \ result in 0 (or 100 after I add 100), I first remove any adjacent duplicates of ~ and _ in the input-string, before calculating and verifying the pair-differences.









                              share|improve this answer






















                              $endgroup$


































                                3
























                                $begingroup$




                                05AB1E, 29 bytes



                                „_~SD2×s:Çü-т+•6_üê{↕ƵΔвåO_



                                It sounded shorter in my head.. Will try to golf it down from here.



                                Try it online or verify all test cases.



                                Explanation:"





                                „_~S                          # Push the characters ["_","~"]

                                D2× # Duplicate it, and increase each to size 2: ["__","~~"]

                                s: # Swap and replace all "__" with "_" and all "~~" with "~"

                                # in the (implicit) input-string

                                Ç # Convert the remaining characters to unicode values

                                ü- # Calculate the difference between each pair

                                т+ # Add 100 to each

                                •6_üê{↕ # Push compressed integer 1781179816800959

                                ƵΔ # Push compressed integer 180

                                в # Convert the larger integer to Base-180 as list:

                                # [52,66,69,100,103,131,179]

                                å # Check for each if it's in the difference-list

                                # (1 if present; 0 if not)

                                O # Sum the truthy values

                                _ # Check if this sum is exactly 0 (1 if 0; 0 otherwise)

                                # (and output this result implicitly)



                                See this 05AB1E tip of mine (sections How to comrpess large integers? and How to compress integer lists?) to understand why •6_üê{↕ is 1781179816800959, ƵΔ is 180 and •6_üê{↕ƵΔв is [52,66,69,100,103,131,179].



                                Additional explanation:



                                There are 16 ($2^4$) possible pairs of characters we have to verify. If we convert each character to its unicode value, and calculate the differences, we would get these differences. Because compressed integer lists in 05AB1E has to have positive integers only, I add 100 to each. The invalid pairs and their corresponding values are then: ["/_", 52]; ["~", 66], ["_~", 69], ["//", 100], ["\", 100], ["_", 103], ["~_", 131], ["~/", 179], which is why I have the compressed integer list in my code containing these values.

                                Since __ and ~~ will just like // and \ result in 0 (or 100 after I add 100), I first remove any adjacent duplicates of ~ and _ in the input-string, before calculating and verifying the pair-differences.









                                share|improve this answer






















                                $endgroup$






























                                  3






















                                  3














                                  3






                                  $begingroup$




                                  05AB1E, 29 bytes



                                  „_~SD2×s:Çü-т+•6_üê{↕ƵΔвåO_



                                  It sounded shorter in my head.. Will try to golf it down from here.



                                  Try it online or verify all test cases.



                                  Explanation:"





                                  „_~S                          # Push the characters ["_","~"]

                                  D2× # Duplicate it, and increase each to size 2: ["__","~~"]

                                  s: # Swap and replace all "__" with "_" and all "~~" with "~"

                                  # in the (implicit) input-string

                                  Ç # Convert the remaining characters to unicode values

                                  ü- # Calculate the difference between each pair

                                  т+ # Add 100 to each

                                  •6_üê{↕ # Push compressed integer 1781179816800959

                                  ƵΔ # Push compressed integer 180

                                  в # Convert the larger integer to Base-180 as list:

                                  # [52,66,69,100,103,131,179]

                                  å # Check for each if it's in the difference-list

                                  # (1 if present; 0 if not)

                                  O # Sum the truthy values

                                  _ # Check if this sum is exactly 0 (1 if 0; 0 otherwise)

                                  # (and output this result implicitly)



                                  See this 05AB1E tip of mine (sections How to comrpess large integers? and How to compress integer lists?) to understand why •6_üê{↕ is 1781179816800959, ƵΔ is 180 and •6_üê{↕ƵΔв is [52,66,69,100,103,131,179].



                                  Additional explanation:



                                  There are 16 ($2^4$) possible pairs of characters we have to verify. If we convert each character to its unicode value, and calculate the differences, we would get these differences. Because compressed integer lists in 05AB1E has to have positive integers only, I add 100 to each. The invalid pairs and their corresponding values are then: ["/_", 52]; ["~", 66], ["_~", 69], ["//", 100], ["\", 100], ["_", 103], ["~_", 131], ["~/", 179], which is why I have the compressed integer list in my code containing these values.

                                  Since __ and ~~ will just like // and \ result in 0 (or 100 after I add 100), I first remove any adjacent duplicates of ~ and _ in the input-string, before calculating and verifying the pair-differences.









                                  share|improve this answer






















                                  $endgroup$






                                  05AB1E, 29 bytes



                                  „_~SD2×s:Çü-т+•6_üê{↕ƵΔвåO_



                                  It sounded shorter in my head.. Will try to golf it down from here.



                                  Try it online or verify all test cases.



                                  Explanation:"





                                  „_~S                          # Push the characters ["_","~"]

                                  D2× # Duplicate it, and increase each to size 2: ["__","~~"]

                                  s: # Swap and replace all "__" with "_" and all "~~" with "~"

                                  # in the (implicit) input-string

                                  Ç # Convert the remaining characters to unicode values

                                  ü- # Calculate the difference between each pair

                                  т+ # Add 100 to each

                                  •6_üê{↕ # Push compressed integer 1781179816800959

                                  ƵΔ # Push compressed integer 180

                                  в # Convert the larger integer to Base-180 as list:

                                  # [52,66,69,100,103,131,179]

                                  å # Check for each if it's in the difference-list

                                  # (1 if present; 0 if not)

                                  O # Sum the truthy values

                                  _ # Check if this sum is exactly 0 (1 if 0; 0 otherwise)

                                  # (and output this result implicitly)



                                  See this 05AB1E tip of mine (sections How to comrpess large integers? and How to compress integer lists?) to understand why •6_üê{↕ is 1781179816800959, ƵΔ is 180 and •6_üê{↕ƵΔв is [52,66,69,100,103,131,179].



                                  Additional explanation:



                                  There are 16 ($2^4$) possible pairs of characters we have to verify. If we convert each character to its unicode value, and calculate the differences, we would get these differences. Because compressed integer lists in 05AB1E has to have positive integers only, I add 100 to each. The invalid pairs and their corresponding values are then: ["/_", 52]; ["~", 66], ["_~", 69], ["//", 100], ["\", 100], ["_", 103], ["~_", 131], ["~/", 179], which is why I have the compressed integer list in my code containing these values.

                                  Since __ and ~~ will just like // and \ result in 0 (or 100 after I add 100), I first remove any adjacent duplicates of ~ and _ in the input-string, before calculating and verifying the pair-differences.









                                  share|improve this answer

























                                  share|improve this answer



                                  share|improve this answer










                                  edited 35 mins ago







































                                  answered 58 mins ago













                                  Kevin CruijssenKevin Cruijssen



                                  40.7k566210







                                  40.7k566210





































                                      2
























                                      $begingroup$




                                      Python 3, 80 78 bytes



                                      I don't realy do many python code golfs but I thought I could give it a try




                                      • -2 bytes: realised not(any()) is the same as all(not()) and could move the not into the r-string


                                      def f(x):*l,=map(r'_/~'.find,x);return 1-any((i^j//2)%2for i,j in zip(l,l[1:]))



                                      Try it online!




                                      Python 3.8 (pre-release), 71 bytes



                                      I wanted to try out the new := expression assignment





                                      lambda x:all((i^j//2)%2for i,j in zip(l:=[*map(r'~_/'.find,x)],l[1:]))



                                      Try it online!









                                      share|improve this answer






















                                      $endgroup$


































                                        2
























                                        $begingroup$




                                        Python 3, 80 78 bytes



                                        I don't realy do many python code golfs but I thought I could give it a try




                                        • -2 bytes: realised not(any()) is the same as all(not()) and could move the not into the r-string


                                        def f(x):*l,=map(r'_/~'.find,x);return 1-any((i^j//2)%2for i,j in zip(l,l[1:]))



                                        Try it online!




                                        Python 3.8 (pre-release), 71 bytes



                                        I wanted to try out the new := expression assignment





                                        lambda x:all((i^j//2)%2for i,j in zip(l:=[*map(r'~_/'.find,x)],l[1:]))



                                        Try it online!









                                        share|improve this answer






















                                        $endgroup$






























                                          2






















                                          2














                                          2






                                          $begingroup$




                                          Python 3, 80 78 bytes



                                          I don't realy do many python code golfs but I thought I could give it a try




                                          • -2 bytes: realised not(any()) is the same as all(not()) and could move the not into the r-string


                                          def f(x):*l,=map(r'_/~'.find,x);return 1-any((i^j//2)%2for i,j in zip(l,l[1:]))



                                          Try it online!




                                          Python 3.8 (pre-release), 71 bytes



                                          I wanted to try out the new := expression assignment





                                          lambda x:all((i^j//2)%2for i,j in zip(l:=[*map(r'~_/'.find,x)],l[1:]))



                                          Try it online!









                                          share|improve this answer






















                                          $endgroup$






                                          Python 3, 80 78 bytes



                                          I don't realy do many python code golfs but I thought I could give it a try




                                          • -2 bytes: realised not(any()) is the same as all(not()) and could move the not into the r-string


                                          def f(x):*l,=map(r'_/~'.find,x);return 1-any((i^j//2)%2for i,j in zip(l,l[1:]))



                                          Try it online!




                                          Python 3.8 (pre-release), 71 bytes



                                          I wanted to try out the new := expression assignment





                                          lambda x:all((i^j//2)%2for i,j in zip(l:=[*map(r'~_/'.find,x)],l[1:]))



                                          Try it online!









                                          share|improve this answer

























                                          share|improve this answer



                                          share|improve this answer










                                          edited 21 mins ago







































                                          answered 32 mins ago













                                          KroppebKroppeb



                                          1,306210







                                          1,306210





































                                              1
























                                              $begingroup$




                                              Jelly, 14 bytes



                                              Supports (and expects) the character in the input string. Returns $0$ or $1$.



                                              O*Ɲ×12%29%15ḂẠ



                                              Try it online!



                                              O*Ɲ×12%29%15ḂẠ  - main link, taking a string          e.g. "_/"

                                              O - get ASCII codes --> [92, 95, 47]

                                              *Ɲ - exponentiation on all pairs --> [92**95, 95**97]

                                              ×12 - multiply by 12 --> [(92**95)*12, (95**97)*12]

                                              %29 - modulo 29 --> [11, 24]

                                              %15 - modulo 15 --> [11, 9]

                                              Ḃ - least significant bit (i.e. parity) --> [1, 1]

                                              Ạ - all values equal to 1? --> 1









                                              share|improve this answer






















                                              $endgroup$


































                                                1
























                                                $begingroup$




                                                Jelly, 14 bytes



                                                Supports (and expects) the character in the input string. Returns $0$ or $1$.



                                                O*Ɲ×12%29%15ḂẠ



                                                Try it online!



                                                O*Ɲ×12%29%15ḂẠ  - main link, taking a string          e.g. "_/"

                                                O - get ASCII codes --> [92, 95, 47]

                                                *Ɲ - exponentiation on all pairs --> [92**95, 95**97]

                                                ×12 - multiply by 12 --> [(92**95)*12, (95**97)*12]

                                                %29 - modulo 29 --> [11, 24]

                                                %15 - modulo 15 --> [11, 9]

                                                Ḃ - least significant bit (i.e. parity) --> [1, 1]

                                                Ạ - all values equal to 1? --> 1









                                                share|improve this answer






















                                                $endgroup$






























                                                  1






















                                                  1














                                                  1






                                                  $begingroup$




                                                  Jelly, 14 bytes



                                                  Supports (and expects) the character in the input string. Returns $0$ or $1$.



                                                  O*Ɲ×12%29%15ḂẠ



                                                  Try it online!



                                                  O*Ɲ×12%29%15ḂẠ  - main link, taking a string          e.g. "_/"

                                                  O - get ASCII codes --> [92, 95, 47]

                                                  *Ɲ - exponentiation on all pairs --> [92**95, 95**97]

                                                  ×12 - multiply by 12 --> [(92**95)*12, (95**97)*12]

                                                  %29 - modulo 29 --> [11, 24]

                                                  %15 - modulo 15 --> [11, 9]

                                                  Ḃ - least significant bit (i.e. parity) --> [1, 1]

                                                  Ạ - all values equal to 1? --> 1









                                                  share|improve this answer






















                                                  $endgroup$






                                                  Jelly, 14 bytes



                                                  Supports (and expects) the character in the input string. Returns $0$ or $1$.



                                                  O*Ɲ×12%29%15ḂẠ



                                                  Try it online!



                                                  O*Ɲ×12%29%15ḂẠ  - main link, taking a string          e.g. "_/"

                                                  O - get ASCII codes --> [92, 95, 47]

                                                  *Ɲ - exponentiation on all pairs --> [92**95, 95**97]

                                                  ×12 - multiply by 12 --> [(92**95)*12, (95**97)*12]

                                                  %29 - modulo 29 --> [11, 24]

                                                  %15 - modulo 15 --> [11, 9]

                                                  Ḃ - least significant bit (i.e. parity) --> [1, 1]

                                                  Ạ - all values equal to 1? --> 1









                                                  share|improve this answer

























                                                  share|improve this answer



                                                  share|improve this answer










                                                  edited 8 mins ago







































                                                  answered 25 mins ago













                                                  ArnauldArnauld



                                                  78.9k795327







                                                  78.9k795327





































                                                      0
























                                                      $begingroup$




                                                      Dart, 94 bytes



                                                      f(s)=>!(r'//,\,~/,_,~_,_~,/_,~'.split(',').map((t)=>s.contains(t)).fold(false,(p,e)=>p|e));



                                                      Try it online!









                                                      share|improve this answer


















                                                      $endgroup$


































                                                        0
























                                                        $begingroup$




                                                        Dart, 94 bytes



                                                        f(s)=>!(r'//,\,~/,_,~_,_~,/_,~'.split(',').map((t)=>s.contains(t)).fold(false,(p,e)=>p|e));



                                                        Try it online!









                                                        share|improve this answer


















                                                        $endgroup$






























                                                          0






















                                                          0














                                                          0






                                                          $begingroup$




                                                          Dart, 94 bytes



                                                          f(s)=>!(r'//,\,~/,_,~_,_~,/_,~'.split(',').map((t)=>s.contains(t)).fold(false,(p,e)=>p|e));



                                                          Try it online!









                                                          share|improve this answer


















                                                          $endgroup$






                                                          Dart, 94 bytes



                                                          f(s)=>!(r'//,\,~/,_,~_,_~,/_,~'.split(',').map((t)=>s.contains(t)).fold(false,(p,e)=>p|e));



                                                          Try it online!









                                                          share|improve this answer





















                                                          share|improve this answer



                                                          share|improve this answer














                                                          answered 21 mins ago













                                                          ElcanElcan



                                                          32115







                                                          32115



































                                                              Discrete Games is a new contributor. Be nice, and check out our Code of Conduct.




















                                                              draft saved


                                                              draft discarded

































                                                              Discrete Games is a new contributor. Be nice, and check out our Code of Conduct.
























                                                              Discrete Games is a new contributor. Be nice, and check out our Code of Conduct.




















                                                              Discrete Games is a new contributor. Be nice, and check out our Code of Conduct.























                                                              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%2f181708%2fwould-this-string-work-as-string%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









                                                              Would this string work as string? Rating: 4.5 Diposkan Oleh: Admin

                                                              0 komentar:

                                                              Posting Komentar

                                                              Popular Posts