Invert your code

-3

1

Challenge

Return the full contents of your program, but inverted. How do your invert something? Well,

Letters: Take the position of the letter in the alphabet, subtract from 26, and use the letter at that position and flip the case of the letter. E.g A becomes z, and p becomes J.

Digits: Subtract from 9. E.g 6 becomes 3 and 5 becomes 4

Brackets: The brackets (){}[]<> become their corresponding closing/opening bracket. E.g [ becomes ] and > becomes <

Other

  • & and | swap.
  • ' ' [space] and '\n' [newline] swap.
  • £ and $ swap, as do and ¥
  • ¢ and % swap
  • _ and - swap
  • " and ' swap
  • ? and ! swap
  • : and ; swap
  • / and \ swap
  • @ and # swap
  • ~ and ` swap
  • , and . swap
  • © and ® swap

All other characters become their Unicode inverse (subtract from 137,374). However, if the result is specified above, you must replace it again with the replacement provided. You only need to run a maximum of two replacements on each character, so no infinite loops.

Rules

  • Standard loopholes are disallowed

Good luck!

Geza Kerecsenyi

Posted 2019-02-22T10:38:20.033

Reputation: 1 892

Question was closed 2019-02-22T22:05:30.860

"the final product cannot be inverted any more" - but if you have one of the defined replacements (e.g. a letter) you can always invert it? So what do you really mean – ASCII-only – 2019-02-22T10:41:34.197

Also, I'd highly recommend against that arbitrary "at least 4 characters in length" restriction – ASCII-only – 2019-02-22T10:46:07.747

Sorry, that was an oversight on my part. Fixed. – Geza Kerecsenyi – 2019-02-22T10:46:22.120

The restriction on characters is just to avoid esoteric answers. – Geza Kerecsenyi – 2019-02-22T10:47:15.057

3Sure... but I highly doubt there is (or ever will be) a language that can do this in 4 bytes, and even if so, the solution wouldn't be very interesting so it's not really a problem. 4 characters... maybe, if you count combining marks on the same character as a single character, but that doesn't matter since we count in bytes here – ASCII-only – 2019-02-22T10:49:04.060

Removed char restrictions – Geza Kerecsenyi – 2019-02-22T11:30:22.837

2Would have been much better if it were a little simpler, with fewer rules of inversion. But that's just my opinion (which I am not supposed to have). – Arjun – 2019-02-22T11:46:11.663

1Why did you accept my answer?.. :S It's way too soon, and it's not even the shortest.. – Kevin Cruijssen – 2019-02-22T15:00:44.360

150 bytes but can't answer because on hold – Nahuel Fouilleul – 2019-02-24T21:19:49.157

R, 190 bytes; can't answer because on hold, but would like to see this challenge reopened. – Nick Kennedy – 2019-02-24T23:51:53.923

bash +tr, 104 bytes – Nahuel Fouilleul – 2019-02-25T08:36:27.720

1

Hi there! I see that this and your previous challenge have lots of comments beneath them asking for clarification or other improvements. Since you're rather new here, I would like to point out that we have a place for challenges to get refined before they get posted here. We call it The Sandbox. I've liked both of your challenges so far, so I hope you continue to stay on PPCG and enjoy all the time you spend here. :-)

– Giuseppe – 2019-02-25T20:48:38.710

Thanks for the help @Giuseppe. I've heard of/seen the sandbox before, but wasn't sure how to use it. Thanks though - I understand now. – Geza Kerecsenyi – 2019-02-26T21:39:30.070

Hi, I've edited your question to be a bit clearer. If there is anything I've done that you feel is not what you want, please correct me. In particular, I've removed the restrictions Any reasonable language is fine, unless the \ is part of a control character, the whole thing with the monkey emoji and the [tag:kolmogorov-complexity] tag. Hopefully this can be reopened and the solutions in the comments can be posted :) – Jo King – 2019-03-03T05:55:22.770

Answers

1

05AB1E, 147 bytes

0"D34çýεÐ.ïi9αëÐáQižiDyk52αèë']Qiº¦ë34ç39ç«UX„,.VYJćDŠåiX‡Y‡ëÇ•2S¹•αçJ]J"D34çýεÐ.ïi9αëÐáQižiDyk52αèë']Qiº¦ë34ç39ç«UX„,.VYJćDŠåiX‡Y‡ëÇ•2S¹•αçJ]J

Outputs:

9'x65,S0kSSxCQ47"[kS6560gd.,fcrxSdc7ir[r'x65,S0kSSxCQ47"[kS6560gd.,fcrxSdc7ir[r

Try it online.

If this can be done in 4 bytes without creating a new language doing this specific task I'd love to see it.. >.> Also, based on the characters to invert I almost have the feeling it's deliberately targeting 05AB1E.. xD Probably not the case, but almost all those characters are pretty frequently used builtins in 05AB1E..

Explanation:

-part:

The shortest for 05AB1E is this one: 0"D34çý"D34çý (14 bytes) provided by @OliverNi. My answer uses a modified version of that quine by adding at the ... here: 0"D34çý..."D34çý.... A short explanation of this quine:

0                 # Push a 0 to the stack (can be any digit)
 "D34çý"          # Push the string "D34çý" to the stack
        D         # Duplicate this string
         34ç      # Push 34 converted to an ASCII character to the stack: '"'
            ý     # Join everything on the stack (the 0 and both strings) by '"'
                  # (output the result implicitly)

Challenge part:

ε                 # Map each character in the string to:
 Ð.ïi             #  If it's an integer:
     9α           #   Get it's absolute difference with 9
 ëÐáQi            #  Else-if it's a regular letter ([A-Za-z]):
      žiD         #   Push "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" twice
         yk       #   Get the index of the current character
           52α    #   Get the absolute difference with 52
              è   #   And index it into the string again
 ë']Qi           '#  Else-if it's a "]":
      º           #   Mirror it to "]["
       ¦          #   And remove the first character so just "[" remains
  34ç             #  Push '"'
     39ç          #  Push "'"
        «         #  Merge them together: `"'`
         UX       #  Save it in variable `X`
  „,.             #  Push ",."
     VY           #  Save it in variable `Y`
       J          #  Join the character, `"'` and ",." together
        ć         #  Extract the head (the character)
         DŠ       #  Duplicate and triple-swap, so the stack becomes char, `"',.`, char
 ë         åi     #  Else-if the character is in this string:
             XÂ   #   Push variable `X` and its reverse
               ‡  #   Transliterate the character
             YÂ   #   Push variable `Y` and its reverse
               ‡  #   Transliterate the character
 ë                #  Else:
  Ç               #   Convert the character to its unicode value
   •2S¹•          #   Push compressed integer 137374
        α         #   Take the absolute difference between the two
         ç        #   Convert it to a character again
          J       #   Join (workaround because very high unicode characters are wrapped
                  #         in a list for some reason)
]                 # Close all if-else statements and map
 J                # Join every mapped character together to a single string
                  # (and output the result implicitly)

See this 05AB1E tip of mine (section How to compress large integers? to understand why •2S¹• is 137374.

Kevin Cruijssen

Posted 2019-02-22T10:38:20.033

Reputation: 67 575

1

Perl 6, 142 bytes

<my@a='a'..'z',@("<(|;~'@./£-".comb);my@b=@('Z'...'A'),@(Q'>)&:`"#,\=$_'.comb);"<$_>~~.EVAL".trans(pair((|@a,|@b),(|@b,|@a))).say>~~.EVAL

Try it online!

Avoids using most of the annoying to represent characters. I think this could be shorter

Jo King

Posted 2019-02-22T10:38:20.033

Reputation: 38 234