6
\$\begingroup\$

You will write a Program which writes the Second Program.

Each program has one Input; which may be a command line argument, or be read from stdin. A Input is a single word made up of upper and/or lowercase letters (a-z)

Each program has Output; which may be to a file, or to stdout.

The Program (which you post here)

  • accepts the Input Greeting, e.g. "Hello"
  • the Output contains the source code of another program, which is described below

The Second Program

  • accepts a Input of Name, e.g. "John"
  • MUST NOT contain the Greeting in a format that could be read by an average computer programmer
  • when executed makes the Output in the format of {Greeting} {Name}, e.g. "Hello John"
  • MUST NOT use an encoding library or function, including but not limited to

    • base64/base32/baseN (unless manually implemented)
    • cryptography (unless manually implemented)

"not be read by an average computer programmer" is ambiguous, but here are some examples for the Greeting "Hello". Use common sense, and I'll downvote if you do one of those Well he didn't say "He" + "ll" + "o" was against the rules

  • Good

    • "Dqkta"
    • [9,3,5,1,6,1,5]
    • ↛↝↧
    • a^|12..7
    • ..--..--!!--.--.----.-,,--.
  • Bad

    • "Hello"
    • "hEllo"
    • "h3110"
    • "He" + "llo"
    • ["H", "e", "l", "l", "o"]
    • "H_e_l_l_o"

Scoring:

  • usual codegolf, least bytes wins
  • addition command line arguments cost the usual 1 point
    • no command line arguments allowed for the Second Program
  • scoring only applies to the first Program (the one you post here)

Please also include an example generated program and a description. If you're confused, see my example answer bellow.

\$\endgroup\$
  • 2
    \$\begingroup\$ is "olleH" good enough? \$\endgroup\$ – John Dvorak Oct 16 '13 at 4:50
  • \$\begingroup\$ @JanDvorak Not if your layout settings are RTL ;-) \$\endgroup\$ – Howard Oct 16 '13 at 4:56
  • \$\begingroup\$ Nope. Another way to look at it is, "Here's the Second Program; and here are 5 possible greetings that could be in it". If someone could tell which of the 5 was used; it's not good enough. \$\endgroup\$ – Brigand Oct 16 '13 at 4:57
  • \$\begingroup\$ Are the greetings mixed case, or can we just accept lowercase? \$\endgroup\$ – user8777 Oct 16 '13 at 5:32
  • 2
    \$\begingroup\$ Does the second program need to be in the same language as the first? \$\endgroup\$ – plannapus Oct 16 '13 at 11:38
2
\$\begingroup\$

GolfScript, 15 / 11 characters

{)}%`'{(}%" "@'

Performs the same obfuscation as the example program. The resulting code for input Howdy is then

"Ipxez"{(}%" "@

For both programs input must be supplied on STDIN while output goes to STDOUT.

If it's ok to convert the string to codes only you can also take the 11 character solution

{}/32]`'\+'

(Thanks to Peter for an idea to save two more characters).

\$\endgroup\$
  • \$\begingroup\$ Wow, nice! I was hoping it'd be a bit more difficult :-) I probably should have picked a single difficult encoding, instead of just "unreadable". \$\endgroup\$ – Brigand Oct 16 '13 at 4:41
  • \$\begingroup\$ @FakeRainBrigand I didn't think that simple shifting was allowed and had a much more complex idea in mind before I read your example. \$\endgroup\$ – Howard Oct 16 '13 at 4:44
  • \$\begingroup\$ @FakeRainBrigand And the difficult part is still to be done, namely beating the 12 character solution Peter will come around with in a few minutes. \$\endgroup\$ – Howard Oct 16 '13 at 4:46
  • \$\begingroup\$ Your 13-character solution can save two by replacing " "+ with 32 before the ]. I've only looked at this task briefly, and currently am lagging behind on 17. \$\endgroup\$ – Peter Taylor Oct 16 '13 at 21:46
6
\$\begingroup\$

APL(Dyalog), 16/20

Losing to GS again...

'⍞,⍨⊂⎕UCS',⎕UCS⍞

This may break the "no cryptography" rule. ⎕UCS is a function to convert characters to unicode code points and back.

Example
First input: Hello
First output: ⍞,⍨⊂⎕UCS 72 101 108 108 111
Second input: John
Second output: Hello John (Note the space before "Hello")


'⎕AV[','],⊂⍞',⍨⎕AV⍳⍞

Similar idea with the cryptography is manually implemented: Convert to/from index of some pre-defined character array (⎕AV) which includes all upper and lower alphabets.

\$\endgroup\$
3
\$\begingroup\$

Tcl, 111

puts "binary scan [join [lmap a [split $argv {}] {format %c [expr [scan $a %c]+256]}] {}]Ġ\$argv a* a;puts \$a"

Exploits the way how Tcl converts strings to bytearrays.

The output for Howdy is

binary scan ňůŷŤŹĠ$argv a* a;puts $a
\$\endgroup\$
3
\$\begingroup\$

Brainfuck 122 120 109 106

+++++++[>++++++>+++++++++++++>++++<<<-]>+<,[[>.<-]>+++.>.<-.>++.--<--<,]>....>>[<<.>>-]<<+++.>.<--.++.>++.
\$\endgroup\$
  • \$\begingroup\$ +1 Neat, but could you explain some of the parts? I have trouble understanding why there is two times ,. Also what it the purpose of this ><<? Shouldn't it be just <? \$\endgroup\$ – plannapus Oct 17 '13 at 9:02
  • \$\begingroup\$ @plannapus Sorry. I fogot to delete the >< when I modified my code. The first , is to ensure that the byte at the pointer is nonzero. \$\endgroup\$ – alephalpha Oct 17 '13 at 9:15
3
\$\begingroup\$

R 113 109 97 characters

cat(unlist(sapply(utf8ToInt(scan(,"",n=1)),function(x)c(rep("+",x),".>"))),rep("+",32),".>+[,.]")

Takes an input as stdin and output a BrainF**k program that prints the input of the first program, a space and then takes a second input and output it, character by character, until an EOF character (or an empty input depending on the BF interpreter used).

Example output with first input Salut:

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + .> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + .> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + .> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + .> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + .> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + .>+[,.]

which you can test here.
Initial input can include printable ASCII characters from ! onwards (spaces don't work because by default scan() uses spaces as separators). Example for $!"§&:

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + .> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + .> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + .> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + .> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + .> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + .> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + .>+[,.]
\$\endgroup\$
  • \$\begingroup\$ This is really cool! I still can't rap my head around these stack languages. \$\endgroup\$ – Brigand Oct 16 '13 at 21:02
2
\$\begingroup\$

Here's a simple example. It's not competitive, but shows how it should work. This is JavaScript which runs on Node.js

var i, charCode, Greeting = process.argv[2], obfuscated = '';

// We're just doing a regular upshift of characters
// a becomes b, etc.
for ( i = 0; i < Greeting.length; i++ ) {
    charCode = Greeting.charCodeAt(i);
    obfuscated += String.fromCharCode(charCode + 1);
}

// You'll want to compress this somehow
var code = [
    "var i, deObfuscated = '';", "var Name = process.argv[2];", "var Greeting = '" + obfuscated + "';",
    "for (i=0; i<Greeting.length; i++) {", "charCode = Greeting.charCodeAt(i);",
    "deObfuscated += String.fromCharCode(charCode - 1);}", "console.log(deObfuscated + ' ' + Name)"];

console.log(code.join('\n'));

I'll call this file Program.js. It can be tested like so:

$ node Program.js Howdy > Second.js
$ node Second.js Partner
Howdy Partner

Second.js contains this. Notice how "Howdy" doesn't appear visibly in this code.

var i, deObfuscated = '';
var Name = process.argv[2];
var Greeting = 'Ipxez';
for (i=0; i<Greeting.length; i++) {
charCode = Greeting.charCodeAt(i);
deObfuscated += String.fromCharCode(charCode - 1);}
console.log(deObfuscated + ' ' + Name)
\$\endgroup\$
2
\$\begingroup\$

Ruby, 63

$><<"puts ''<<"+gets.chop.each_codepoint.to_a*'<<'+"<<' '+gets"

Output for Hello:

puts ''<<72<<101<<108<<108<<111<<' '+gets

Output for asdfASDF1234!@#$<>,.:

puts ''<<97<<115<<100<<102<<65<<83<<68<<70<<49<<50<<51<<52<<33<<64<<35<<36<<60<<62<<44<<46<<' '+gets
\$\endgroup\$
1
\$\begingroup\$

PHP, 58 61 64 74 Bytes

<?=0?~0 ." $argv[1]":strtr(file(__FILE__)[0],[~$argv[1]]);

The script replaces all 0 in its own source code with the inverted greeting. If run as php greeter.php Hello, the output is:

<?=ÀÜôôÉ?~ÀÜôôÉ ." $argv[1]":strtr(file(__FILE__)[ÀÜôôÉ],[~$argv[1]]);

If you run this as php greeter2.php John, the output with full error reporting is

PHP Notice:  Use of undefined constant ÀÜôôÉ - assumed 'ÀÜôôÉ'
PHP Notice:  Use of undefined constant ÀÜôôÉ - assumed 'ÀÜôôÉ'
Hello John

otherwise, just Hello John

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.