Post History
Python 3, 86 85 bytes The reasoning behind why this works is basically that 1. we can directly compare the ordinal values of characters (apparently) and 2. we only need that if a character is alph...
#2: Post edited
# Python 3, 86 bytes- The reasoning behind why this works is basically that 1. we can directly compare the ordinal values of characters (apparently) and 2. we only need that if a character is alphanumeric, then <pre>'A' < '`' < 'a'</pre>which is very interesting to think about.
- ---
- Solution:
- ```python
lambda m,k:''.join([c,chr((o:=64+32*('`'<c))+(ord(c)+k-o)%26)][c.isalpha()]for c in m)```
- # Python 3, <s>86</s> 85 bytes
- The reasoning behind why this works is basically that 1. we can directly compare the ordinal values of characters (apparently) and 2. we only need that if a character is alphanumeric, then <pre>'A' < '`' < 'a'</pre>which is very interesting to think about.
- Also, if we have an expression of the form `a+(b)<<c` or `a+b<<c`, apparently Python interprets that as `(a+b)<<c`, which is cool, but so weird.
- ---
- Solution:
- ```python
- lambda m,k:''.join([c,chr((o:=2+('`'<c)<<5)+(ord(c)+k-o)%26)][c.isalpha()]for c in m)
- ```
- [Try it online!](https://www.online-python.com/HKJDXk5Cup) I set the link to `Never expire`, but please notify me if the link doesn't work.
#1: Initial revision
# Python 3, 86 bytes The reasoning behind why this works is basically that 1. we can directly compare the ordinal values of characters (apparently) and 2. we only need that if a character is alphanumeric, then <pre>'A' < '`' < 'a'</pre>which is very interesting to think about. --- Solution: ```python lambda m,k:''.join([c,chr((o:=64+32*('`'<c))+(ord(c)+k-o)%26)][c.isalpha()]for c in m) ```