Skip to main content
added 195 characters in body
Source Link
george
  • 1.8k
  • 17
  • 27

Python 3, 147 179 151 Bytes

This method doesn't work for test cases containing ABCDEF due to the "g-97" statement.

x=[ord(i) for i in input()];c=chr
print("".join([c(g)*(not(c(g).isalpha())) or(c(x[g-97])*(g>97)or c(x[g-65]-32))for g in[ord(i)for i in input()]]))

There must be a shorter way to do this using mapping, but I haven' quite figured the mapping function out yet. Golf'ed down from an original 180 just a shame its not quite a one liner.

x=[ord(i)for i in input()];y=[ord(i) for i in input()];t=""
for i in range(len(y)):
    g=y[i]
    if 122>g>97:t+=chr(x[g-97])
    else:t+=chr(g)*(not(90>g>65))or chr(x[g-65]-32)
print(t)

New method gets it to work with fewer bytes:

x=[ord(i)for i in input()];c=chr
print("".join([(c(x[g-97])if 123>g>96 else c(x[g-65]-32))if c(g).isalpha()else c(g)for g in[ord(i)for i in input()]]))

Movatica has a shorter solution using the string library. And using := I could reduced my answer to a one-liner at the expense of a few bytes

Python 3, 147 179 151 Bytes

This method doesn't work for test cases containing ABCDEF due to the "g-97" statement.

x=[ord(i) for i in input()];c=chr
print("".join([c(g)*(not(c(g).isalpha())) or(c(x[g-97])*(g>97)or c(x[g-65]-32))for g in[ord(i)for i in input()]]))

There must be a shorter way to do this using mapping, but I haven' quite figured the mapping function out yet. Golf'ed down from an original 180 just a shame its not quite a one liner.

x=[ord(i)for i in input()];y=[ord(i) for i in input()];t=""
for i in range(len(y)):
    g=y[i]
    if 122>g>97:t+=chr(x[g-97])
    else:t+=chr(g)*(not(90>g>65))or chr(x[g-65]-32)
print(t)

New method gets it to work with fewer bytes:

x=[ord(i)for i in input()];c=chr
print("".join([(c(x[g-97])if 123>g>96 else c(x[g-65]-32))if c(g).isalpha()else c(g)for g in[ord(i)for i in input()]]))

Python 3, 147 179 151 Bytes

This method doesn't work for test cases containing ABCDEF due to the "g-97" statement.

x=[ord(i) for i in input()];c=chr
print("".join([c(g)*(not(c(g).isalpha())) or(c(x[g-97])*(g>97)or c(x[g-65]-32))for g in[ord(i)for i in input()]]))

There must be a shorter way to do this using mapping, but I haven' quite figured the mapping function out yet. Golf'ed down from an original 180 just a shame its not quite a one liner.

x=[ord(i)for i in input()];y=[ord(i) for i in input()];t=""
for i in range(len(y)):
    g=y[i]
    if 122>g>97:t+=chr(x[g-97])
    else:t+=chr(g)*(not(90>g>65))or chr(x[g-65]-32)
print(t)

New method gets it to work with fewer bytes:

x=[ord(i)for i in input()];c=chr
print("".join([(c(x[g-97])if 123>g>96 else c(x[g-65]-32))if c(g).isalpha()else c(g)for g in[ord(i)for i in input()]]))

Movatica has a shorter solution using the string library. And using := I could reduced my answer to a one-liner at the expense of a few bytes

Adding solution
Source Link
george
  • 1.8k
  • 17
  • 27

Python 3, 148147 179 152151 Bytes

This method doesn't work for test cases containing ABCDEF due to the "g-97" statement.

x=[ord(i) for i in input()];c=chr
print("".join([c(g)*(not(c(g).isalpha())) or(c(x[g-97])*(g>97)or c(x[g-65]-32))for g in[ord(i)for i in input()]]))

There must be a shorter way to do this using mapping, but I haven' quite figured the mapping function out yet. Golf'ed down from an original 180 just a shame its not quite a one liner.

x=[ord(i) for i in input()];y=[ord(i) for i in input()];t=""
for i in range(len(y)):
    g=y[i]
    if 122>g>97:t+=chr(x[g-97])
    else:t+=chr(g)*(not(90>g>65))or chr(x[g-65]-32)
print(t)

New method gets it to work with fewer bytes:

x=[ord(i) for i in input()];c=chr
print("".join([(c(x[g-97])if 123>g>96 else c(x[g-65]-32))if c(g).isalpha()else c(g)for g in[ord(i)for i in input()]]))

Python 3, 148 179 152 Bytes

This method doesn't work for test cases containing ABCDEF due to the "g-97" statement.

x=[ord(i) for i in input()];c=chr
print("".join([c(g)*(not(c(g).isalpha())) or(c(x[g-97])*(g>97)or c(x[g-65]-32))for g in[ord(i)for i in input()]]))

There must be a shorter way to do this using mapping, but I haven' quite figured the mapping function out yet. Golf'ed down from an original 180 just a shame its not quite a one liner.

x=[ord(i) for i in input()];y=[ord(i) for i in input()];t=""
for i in range(len(y)):
    g=y[i]
    if 122>g>97:t+=chr(x[g-97])
    else:t+=chr(g)*(not(90>g>65))or chr(x[g-65]-32)
print(t)

New method gets it to work with fewer bytes:

x=[ord(i) for i in input()];c=chr
print("".join([(c(x[g-97])if 123>g>96 else c(x[g-65]-32))if c(g).isalpha()else c(g)for g in[ord(i)for i in input()]]))

Python 3, 147 179 151 Bytes

This method doesn't work for test cases containing ABCDEF due to the "g-97" statement.

x=[ord(i) for i in input()];c=chr
print("".join([c(g)*(not(c(g).isalpha())) or(c(x[g-97])*(g>97)or c(x[g-65]-32))for g in[ord(i)for i in input()]]))

There must be a shorter way to do this using mapping, but I haven' quite figured the mapping function out yet. Golf'ed down from an original 180 just a shame its not quite a one liner.

x=[ord(i)for i in input()];y=[ord(i) for i in input()];t=""
for i in range(len(y)):
    g=y[i]
    if 122>g>97:t+=chr(x[g-97])
    else:t+=chr(g)*(not(90>g>65))or chr(x[g-65]-32)
print(t)

New method gets it to work with fewer bytes:

x=[ord(i)for i in input()];c=chr
print("".join([(c(x[g-97])if 123>g>96 else c(x[g-65]-32))if c(g).isalpha()else c(g)for g in[ord(i)for i in input()]]))
Adding solution
Source Link
george
  • 1.8k
  • 17
  • 27

Python 3, 148 179179 152 Bytes

This method doesn't work for test cases containing ABCDEF due to the "g-97" statement.

x=[ord(i) for i in input()];c=chr
print("".join([c(g)*(not(c(g).isalpha())) or(c(x[g-97])*(g>97)or c(x[g-65]-32))for g in[ord(i)for i in input()]]))

There must be a shorter way to do this using mapping, but I haven' quite figured the mapping function out yet. Golf'ed down from an original 180 just a shame its not quite a one liner.

x=[ord(i) for i in input()];y=[ord(i) for i in input()];t=""
for i in range(len(y)):
    g=y[i]
    if 122>g>97:t+=chr(x[g-97])
    else:t+=chr(g)*(not(90>g>65))or chr(x[g-65]-32)
print(t)

New method gets it to work with fewer bytes:

x=[ord(i) for i in input()];c=chr
print("".join([(c(x[g-97])if 123>g>96 else c(x[g-65]-32))if c(g).isalpha()else c(g)for g in[ord(i)for i in input()]]))

Python 3, 148 179 Bytes

This method doesn't work for test cases containing ABCDEF due to the "g-97" statement.

x=[ord(i) for i in input()];c=chr
print("".join([c(g)*(not(c(g).isalpha())) or(c(x[g-97])*(g>97)or c(x[g-65]-32))for g in[ord(i)for i in input()]]))

There must be a shorter way to do this using mapping, but I haven' quite figured the mapping function out yet. Golf'ed down from an original 180 just a shame its not quite a one liner.

x=[ord(i) for i in input()];y=[ord(i) for i in input()];t=""
for i in range(len(y)):
    g=y[i]
    if 122>g>97:t+=chr(x[g-97])
    else:t+=chr(g)*(not(90>g>65))or chr(x[g-65]-32)
print(t)

Python 3, 148 179 152 Bytes

This method doesn't work for test cases containing ABCDEF due to the "g-97" statement.

x=[ord(i) for i in input()];c=chr
print("".join([c(g)*(not(c(g).isalpha())) or(c(x[g-97])*(g>97)or c(x[g-65]-32))for g in[ord(i)for i in input()]]))

There must be a shorter way to do this using mapping, but I haven' quite figured the mapping function out yet. Golf'ed down from an original 180 just a shame its not quite a one liner.

x=[ord(i) for i in input()];y=[ord(i) for i in input()];t=""
for i in range(len(y)):
    g=y[i]
    if 122>g>97:t+=chr(x[g-97])
    else:t+=chr(g)*(not(90>g>65))or chr(x[g-65]-32)
print(t)

New method gets it to work with fewer bytes:

x=[ord(i) for i in input()];c=chr
print("".join([(c(x[g-97])if 123>g>96 else c(x[g-65]-32))if c(g).isalpha()else c(g)for g in[ord(i)for i in input()]]))
I code bad
Source Link
george
  • 1.8k
  • 17
  • 27
Loading
Source Link
george
  • 1.8k
  • 17
  • 27
Loading