Skip to main content
deleted 99 characters in body
Source Link
Dennis
  • 210.6k
  • 41
  • 370
  • 825

How it works

“ṾiЀƓv”v  Main link. No arguments.

“ṾiЀƓv”   Set the left argument and the return value to s := 'ṾiЀƓv'.
        v  Execute the string s as a monadic Jelly program with argument s.

 Ṿ         Uneval; yield a string representation of s, i.e., r := '“ṾiЀƓv”'.
     Ɠ     Read one line from STDIN and evaluate it like Python would.
  iЀ      Find the index of each character in the input in r.
      v    Eval the list of indices as a monadic Jelly program with argument s.
           Why?
             This is the shortest way to add the character 'v' to the string s,
             meaning that we can use r without having to append anything.
           What?
             The v atom vectorizes at depth 1 for its left argument, meaning that
             it acts on arrays of numbers and/or characters. When fed an array of
             integers, it first converts them to strings, then concatenates the
             strings and evaluates them as a Jelly program. For example, the array
             [1, 2, 3] gets cast to the string '123', then evaluates, yielding 123.
             Something slightly different happens if the array starts with a 0. For
             example, the array [0, 1, 2] gets cast to '012' just as before, but
             Jelly views '0' and '12' as two separate tokens; numeric literals
             cannot start with a 0. Since the Jelly program is monadic, the first
             token – '0' – sets the return value to 0. Since the second token –
             '12' – is also a niladic link, the previous return value is printed
             before changing the return value to 12. Then, the program finishes
             and the last return value is printed implicitly.

How it works

“ṾiЀƓv”v  Main link. No arguments.

“ṾiЀƓv”   Set the left argument and the return value to s := 'ṾiЀƓv'.
        v  Execute the string s as a monadic Jelly program with argument s.

 Ṿ         Uneval; yield a string representation of s, i.e., r := '“ṾiЀƓv”'.
     Ɠ     Read one line from STDIN and evaluate it like Python would.
  iЀ      Find the index of each character in the input in r.
      v    Eval the list of indices as a monadic Jelly program with argument s.
           Why?
             This is the shortest way to add the character 'v' to the string s,
             meaning that we can use r without having to append anything.
           What?
             The v atom vectorizes at depth 1 for its left argument, meaning that
             it acts on arrays of numbers and/or characters. When fed an array of
             integers, it first converts them to strings, then concatenates the
             strings and evaluates them as a Jelly program. For example, the array
             [1, 2, 3] gets cast to the string '123', then evaluates, yielding 123.
             Something slightly different happens if the array starts with a 0. For
             example, the array [0, 1, 2] gets cast to '012' just as before, but
             Jelly views '0' and '12' as two separate tokens; numeric literals
             cannot start with a 0. Since the Jelly program is monadic, the first
             token – '0' – sets the return value to 0. Since the second token –
             '12' – is also a niladic link, the previous return value is printed
             before changing the return value to 12. Then, the program finishes
             and the last return value is printed implicitly.
deleted 99 characters in body
Source Link
Dennis
  • 210.6k
  • 41
  • 370
  • 825

Jelly, 1010 9 bytes

“iЀƓṾv”vṾ“ṾiЀƓv”v

Uses 1-based indexing and yields 0 for not found. Input is a string (Python syntax) from STDIN.

Try it online!Try it online!

Jelly, 10 bytes

“iЀƓṾv”vṾ

Uses 1-based indexing and yields 0 for not found. Input is a string (Python syntax) from STDIN.

Try it online!

Jelly, 10 9 bytes

“ṾiЀƓv”v

Try it online!

Source Link
Dennis
  • 210.6k
  • 41
  • 370
  • 825

Jelly, 10 bytes

“iЀƓṾv”vṾ

Uses 1-based indexing and yields 0 for not found. Input is a string (Python syntax) from STDIN.

Try it online!