Skip to main content
re-wrote the code, I know the language better now.
Source Link
cnamejj
  • 2.8k
  • 10
  • 11

Ly, 4646 29 bytes

<"false">ia>ia[sp<l=iayr>iay&s<l[0I=![<&o;]pp>]<[<&o;]"true"&o[0u;]pprp]1u

Try it online!

Input expected is two lines, one word per line.Try it online!

I didn't see aknow Ly entry and I'm trying to learn that language better, so why not? now. :)

First, store "false" in At a stackhigh level, since we need it twicethis code constructs two stacks, then switch back to the default stack.

<"false">

Then read each line into it's own stack, as codepointswith a sorted (by codepoint) list of characters in the associated input string, and sort them.

>ia>ia

The loop compareswith the top of stack of eachlength of those two stacks using the "backup cell" to facilitatestring included as another entry on the cross-stack comparisonslist.

[sp<l=![<&o;]pp>]

The sp<l=! bit stores the current topOne stack, deletes it, switches stacks, loads is reversed and then the value we storedtwo are concatenated. Once that setup is done, them compares it to what was the code loops comparing the top and bottom of the stack. And since we only care if they are different it logically negates The first time the results to makecodepoints aren't the [ conditional kick in.

So that bitsame, the code write out a [<&o;]0 switched to the stack where we stashed "false", prints it, and exits the program.

All If the loop has to do after that is clean-up the stack and switch back to the one driving the comparisons with pp>.

Once all the characters on the first word stack have been compared toexhausts the second word stack, the code has to make sure the second work stack wasn't shorter.

<[<&o;]

That works by switching to the stack that wasn't driving the loop < and runningstrings are anagrams so the code in thewrites out a [1 block if it's not empty. If that code is invoked, it switches to the "false" string stack, prints it and exits the program.

If we survived both those conditional exits, the strings areIt's still nowhere near the same length and haveshortest, but the same characters. So we just print "true" and exit.way it works might be interesting to people?

"true"&o # parse the first string
 i                             - read in one line
  a                            - sort by codepoint value
   y                           - push the stack length
    r                          - reverse the stack
  # parse the second string
     >                         - switch to a new stack
      i                        - read in one line
       a                       - sort by coidepoint
        y                      - push the stack length
         &s                    - stash the entire stack
 # setup for processing 
           <                   - back to stack with string 1
            l                  - append the parsed second string
 # compare pairs of codepoints while stack isn't empty
             [             ]   - loop, process one char per iteration
              0I               - copy bottom of stack
                =!             - compare top two negate
                  [   ]p       - if/then, if they don't match
                   0u;         - print "0" and exit
                        prp    - delete pair we just checked
 # if lengths and all the codepoints matched...
                            1u - success! print "1" 

Ly, 46 bytes

<"false">ia>ia[sp<l=![<&o;]pp>]<[<&o;]"true"&o

Try it online!

Input expected is two lines, one word per line.

I didn't see a Ly entry and I'm trying to learn that language better, so why not? :)

First, store "false" in a stack, since we need it twice, then switch back to the default stack.

<"false">

Then read each line into it's own stack, as codepoints, and sort them.

>ia>ia

The loop compares the top of stack of each of those two stacks using the "backup cell" to facilitate the cross-stack comparisons.

[sp<l=![<&o;]pp>]

The sp<l=! bit stores the current top stack, deletes it, switches stacks, loads the value we stored, them compares it to what was the top of the stack. And since we only care if they are different it logically negates the results to make the [ conditional kick in.

So that bit [<&o;] switched to the stack where we stashed "false", prints it, and exits the program.

All the loop has to do after that is clean-up the stack and switch back to the one driving the comparisons with pp>.

Once all the characters on the first word stack have been compared to the second word stack, the code has to make sure the second work stack wasn't shorter.

<[<&o;]

That works by switching to the stack that wasn't driving the loop < and running the code in the [ block if it's not empty. If that code is invoked, it switches to the "false" string stack, prints it and exits the program.

If we survived both those conditional exits, the strings are the same length and have the same characters. So we just print "true" and exit.

"true"&o

Ly, 46 29 bytes

iayr>iay&s<l[0I=![0u;]pprp]1u

Try it online!

I know Ly better now. :) At a high level, this code constructs two stacks, each with a sorted (by codepoint) list of characters in the associated input string, with the length of the string included as another entry on the list.

One stack is reversed and then the two are concatenated. Once that setup is done, the code loops comparing the top and bottom of the stack. The first time the codepoints aren't the same, the code write out a 0 and exits. If the loop exhausts the stack, the strings are anagrams so the code writes out a 1 and exits.

It's still nowhere near the shortest, but the way it works might be interesting to people?

 # parse the first string
 i                             - read in one line
  a                            - sort by codepoint value
   y                           - push the stack length
    r                          - reverse the stack
  # parse the second string
     >                         - switch to a new stack
      i                        - read in one line
       a                       - sort by coidepoint
        y                      - push the stack length
         &s                    - stash the entire stack
 # setup for processing 
           <                   - back to stack with string 1
            l                  - append the parsed second string
 # compare pairs of codepoints while stack isn't empty
             [             ]   - loop, process one char per iteration
              0I               - copy bottom of stack
                =!             - compare top two negate
                  [   ]p       - if/then, if they don't match
                   0u;         - print "0" and exit
                        prp    - delete pair we just checked
 # if lengths and all the codepoints matched...
                            1u - success! print "1" 
Source Link
cnamejj
  • 2.8k
  • 10
  • 11

Ly, 46 bytes

<"false">ia>ia[sp<l=![<&o;]pp>]<[<&o;]"true"&o

Try it online!

Input expected is two lines, one word per line.

I didn't see a Ly entry and I'm trying to learn that language better, so why not? :)

First, store "false" in a stack, since we need it twice, then switch back to the default stack.

<"false">

Then read each line into it's own stack, as codepoints, and sort them.

>ia>ia

The loop compares the top of stack of each of those two stacks using the "backup cell" to facilitate the cross-stack comparisons.

[sp<l=![<&o;]pp>]

The sp<l=! bit stores the current top stack, deletes it, switches stacks, loads the value we stored, them compares it to what was the top of the stack. And since we only care if they are different it logically negates the results to make the [ conditional kick in.

So that bit [<&o;] switched to the stack where we stashed "false", prints it, and exits the program.

All the loop has to do after that is clean-up the stack and switch back to the one driving the comparisons with pp>.

Once all the characters on the first word stack have been compared to the second word stack, the code has to make sure the second work stack wasn't shorter.

<[<&o;]

That works by switching to the stack that wasn't driving the loop < and running the code in the [ block if it's not empty. If that code is invoked, it switches to the "false" string stack, prints it and exits the program.

If we survived both those conditional exits, the strings are the same length and have the same characters. So we just print "true" and exit.

"true"&o