12
2
The goal is to write a program that encodes an other program (input) with the fewest character possible.
Scoring
- The score is equal to the different number of characters needed for the output.
- Lower score is better.
Rules
- No target languages with a limited set of commands. (No Brainf**k, Whitespace etc)
Edit: I mean at least 26 significant characters,A
doesn't change the way a brainf**k program operates, so you can't count this character. Same applies to whitespace. - The target language must exist at the time where this question is written.
- You have to include a small explanation how you archive your score.
- The input program is valid.
- The encoded program must be a valid program in the same language as the input.
- The encoded program must do the same job as the original program.
- Your encoder must work for every valid program in that language.
- Include some sample input and output.
Notes
- The encoder might be written in any language, not only in the language it targets.
- This is not code-golf, readable programs are encouraged.
- The great goal is to see how many different characters are needed to write anything in that language. I disallowed BF etc because there would be no challenge.
- This was inspired by Print a string in as few distinct characters as possible, you could take it as metagolf for that question.
Example
In Java, you can use \uXXXX
instead other characters. A valid entry encodes every character from the input this way. This would have a score of 18. (\ 0-9a-f
)
Code in Tcl, encodes a Java program:
set res {}
foreach char [split [read stdin] {}] {
append res [format \\u%04x [scan $char %c]]
}
puts $res
sorry for the vote to close... thought this was a duplicate of http://codegolf.stackexchange.com/questions/6974/ but that one's python-specific.
– boothby – 2013-05-15T00:12:53.2902With you Java score and your encoder: I don't speak much Tcl, but doesn't
gets
read a single line of input only? And you missed theu
in your encoder (but on the other hand you don't need the space and thus the score remains the same). – Howard – 2013-05-15T04:40:20.120Maybe you should add a rule along the lines encoded program should (under reasonable constraints) perform the same task as the original version. It is never stated and thus I could transform anything to any (constant) program. – Howard – 2013-05-15T04:43:17.397
Do you rule out a simple conversion to binary, converting the digits to characters and removing the resulting spaces? – Graham – 2013-05-15T09:21:48.337
@Graham In which language would that result be a valid program? – Howard – 2013-05-15T09:50:12.777
@Howard I guess I should have read rule 5 more carefully if that means it should run as is in its encoded form :( – Graham – 2013-05-15T10:02:00.687
possible duplicate of Print a string in as few distinct characters as possible
– Peter Taylor – 2013-05-15T14:16:44.4334I'm voting to close this because it has a broken victory condition patched over by a very unclear ban on languages. If Unary wasn't banned, it'd score 1. If brainfuck wasn't banned, it'd score 7 (note that the language itself naturally has 8 commands + 248 comment characters). So where's the line between naturally having too few commands, and having enough to be legitimate. – None – 2016-12-28T11:10:23.863
1Even languages like Python have a limited set of commands. You can't "make a new one", you simply create a new function or something, but the reserved words stay the same. The definition of "command" is unclear. The question could possibly be fixed by not limiting languages (just don't upvote trivial answers), and requiring that the set of characters used must be a proper subset of those in the language. – mbomb007 – 2016-12-28T14:28:54.203
so a cat program submitted to this would have a score of 2^30? – Rohan Jhunjhunwala – 2016-12-28T16:55:57.520
Is CJam allowed? It has only 26 variables that can be redefined, which could contain blocks (commands). It's not limited to the original set of commands, but the maximum number of commands is still finite. – jimmy23013 – 2016-12-28T18:51:35.220
And how are subroutine labels in Whitespace, which are not significantly different from C functions, not new commands? – jimmy23013 – 2016-12-28T18:55:38.260
I hope my edit solves your concerns. – Johannes Kuhn – 2016-12-28T22:16:35.303
"at least 26 significant characters" seems to still allow a Beatnik-based answer with a score of 2... or even a Lenguage-based answer with a score of 1! (Neither language truly ignores any characters: Beatnik splits a program into chunks of consecutive alphabetical characters and executes commands based on their Scrabble scores, and a Lenguage program encodes a brainfuck program in its length disregarding any other information.) – Unrelated String – 2019-05-28T23:23:37.110
7Don't all programming languages have a "limited set of commands"? Where do you draw the line? – jpjacobs – 2014-09-15T10:53:08.027
try to make a new command in brainfuck. – Johannes Kuhn – 2014-09-16T15:59:39.707