33
4
Given the 95 printable characters in ASCII plus newline, break it apart into two equal, 48 character groups (hereafter called group A and group B). Create a one-to-one mapping of your choice (you have total discretion) between the two groups. In other words, A
might map to a
, and vice versa, but A
might also map to >
and vice versa, if that's what you need for your program.
Once you've broken up ASCII into two groups, write two programs and/or functions, using only the characters in each group, respectively. In other words, write one program / function that only uses the characters in group A, and another program / function that only uses the characters in group B.
These programs must be able to receive one character as input. The program written with the characters in Group A should output / return the same character if the input was a group A character, and the mapped group A character if it received a group B character; the Group A program should always output a group A character. Similarly, the Group B program should output the same character if it's a group B character, and the mapped group B character if the input is a group A character.
That might not be so clear, so here's an example. If you assume that all capital letters are in group A, and all lowercase letters are in group B, and you've chosen that your one-to-one mapping for these letters are from one to the other, then: then here are some sample input/outputs:
Program A:
Input Output
A A
D D
a A
q Q
Program B:
Input Output
A a
D d
a a
q q
Other rules:
- The two programs do not need to be in the same language.
- They don't need to be both programs or both functions; one could be a program, the other a function, that is fine.
- They don't need to work the same way, be of similar length, anything like that; they simply must meet the the other rules above.
- Yes, only one of your programs may use newlines, and only one can use spaces (this could be the same, or a different program).
- You do not need to use all 48 characters in each program.
Standard loopholes are banned, as normal. All programs must be self contained, no files containing the mapping you choose.
Scoring criteria: code-golf. Specifically, the sum of the bytes of the text of the two programs.
Please post your answer like this:
Language - # bytes + Language - # bytes = # bytes
An unambiguous description of your mapping. If it's complicated, use a chart like this:
ABCDEFGHIJKLMNOPQRSTUVWXYZ (etc.) zyxwvutsrpqonmlkjihgfedcba (etc.)
Or, you can just explain it (first 48 maps to last 48 in sequence), followed by your answer as normal.
I'm going to try using the same language for both. :) – mbomb007 – 2015-09-05T00:32:53.927
I honestly think you should change the rules, restricting it to "both programs have to be the same language." Otherwise it's probably WAY too easy/broad. – mbomb007 – 2015-09-05T01:29:37.967
I actually wonder if this is possible in Self-modifying Brainfuck. You just have to have one program using
+
and>
, and the other using-
and<
. Then you have to try to generate the missing operators, such as a,
or.
in the program that cannot use them. – mbomb007 – 2015-09-05T01:37:06.320If the implementation can be via two different functions within one program, can they share common code (i.e. a global variable)? – Ruslan – 2015-09-05T04:31:41.453
They can't be two functions in one program. If you do two functions it has to be in two programs. – durron597 – 2015-09-05T04:32:53.420
@durron597 Thanks! Also, does the restriction to repeat characters apply to non-alphanumeric characters as well? For instance, if I use the "=" symbol in the first program, I can't use it in the second one? – Ruslan – 2015-09-05T04:37:10.990
@durron597 Sorry, last question... If I opt for the two "function" approach, does only code inside of the actual function that takes the character and returns the mapped one count, or does the whole program still count? If the latter is the case, then the same language would simply be impossible (i.e. if both programs can't have "void main() { ... }" or "#include", etc). – Ruslan – 2015-09-05T04:40:52.170
@Ruslan It's the whole program. And then maybe you should try a different programming language, one without includes or required brackets. See if it's possible in Python. I think it is. – mbomb007 – 2015-09-05T06:00:19.167
I mean, one of them should be in brainfuck :) – Jamie – 2015-09-05T09:17:26.640
1@Ruslan Try using SQL. It's not case sensitive and uses keywords (begin and end) for code blocks. If you use SQL Server 2014, you can use DBCC Bulk Insert for one program, and a procedure for the other one. In the first one, you can avoid using parentheses. Then use a select case when statement for both programs.
Also, I believe it's possible in Java by using the \u trick for a program replacing every character with unicode values and using a function for the other that doesn't use the letter u, a backslash, or numbers. – bmarks – 2015-09-05T18:07:43.657
4Hardest. Challenge. Ever. – Blackhole – 2015-09-05T18:19:14.007
Was knee-deep into a solution using JavaScript for both; got tired but I'm almost positive it's possible. Figured out that a function normally requiring parentheses can be written without them, by creating a new
Function
with tagged template syntax and executing it with another tagged template. Then just a lot of hexadecimal escapes inside the eval'd string..... TL;DR this challenge is extremely difficult. – jrich – 2015-09-05T21:55:28.503@Blackhole it's possible to complete if you use two sepearate languages: use Unary for one and Whitespace for the other. – bmarks – 2015-09-05T22:23:06.087
Exactly @bmarks with esolangs this is quite an easy challenge to complete... Doing it golfed is the hard part. – durron597 – 2015-09-05T22:32:57.837
@bmarks Yes, I also thought about SQL at first. But then one issue is spaces (although maybe I can find a way around that). – Ruslan – 2015-09-06T01:29:45.090
@Ruslan try using newlines in one and spaces in the other. I believe they are equivalent in T-SQL. – bmarks – 2015-09-06T01:31:41.300
Hmm, since the answer formatting is specified, I was expecting a leaderboard stack snippet :) – aditsu quit because SE is EVIL – 2015-09-08T18:16:33.487
@aditsu I suck at Javascript, but I welcome others to edit one in – durron597 – 2015-09-08T18:18:01.210