6
\$\begingroup\$

Objective:

The task is to create two programs using the same or different programming languages. The sourcecodes will be combined in two different ways and the resulting sourcecodes can be in any programming languages. The four programs (original two + the two combinations) should output different things.

Rules:

  1. Your programs (all four) should not take any input (from user, filename, network or anything).
  2. The first program should output exactly Hello, nothing else.
  3. The second program should output exactly world, nothing else.
  4. The first combinated program should output Hello human!, nothing else.
  5. The second combinated program should output Hello computer!, nothing else.

Here is how the two combinated programs may be created:

First combined program:

  • Choose two numbers (equal or different) between 1 and 6 (that is: 2, 3, 4 or 5), the two numbers are called: n1 and n2.
  • Copy n1 number of characters from the first program and paste into the combined sourcecode
  • Copy n1 number of characters from the second program and paste into the combined sourcecode
  • Copy n2 number of characters from the first program and paste into the combined sourcecode
  • Copy n2 number of characters from the second program and paste into the combined sourcecode
  • Next, start over copy n1 number of characters again and so on. Copy from start to end from the sourcecodes, paste from start to end into the combined sourcecode.

Second combined program:

  • The sourcecode is the reverse of the first combined program sourcecode above. You may replace up to 3 characters at any place afterwards (optional). You can replace the up to 3 characters with any other characters. Replacing means 1 char for 1 char at up to 3 different positions on the sourcecode. The final sourcecode size in characters should therefor be exactly the same size as the first combined program size.

Example creating the combinated programs using numbers 3 and 4:

            First program:    {'Hello'}:p
           Second program:    /*         */ console.log ("World");
 First combinated program:    {'H/* ello    '}:   */ console.log ("World");
Second combinated program:    ;)"dlroW"( gol.elosnoc /*   :}'    olle */H'}

Be sure to declare all four programming languages that you use (even if they are all the same) and what numbers you have used when creating the first combinated sourcecode.

This is code-golf, shortest code in bytes for the two sourcecodes wins! Good luck, have fun!

\$\endgroup\$
3
  • 2
    \$\begingroup\$ +1. Your challenges are crazy; you make us work really hard on short pieces of code, you impose strict requirements, etc. \$\endgroup\$
    – Justin
    Jan 20, 2014 at 22:11
  • \$\begingroup\$ I'm going to guess it has to work for only 1 chosen combination of numbers, not all combinations? Also, if one of the programs runs out of characters during combination procedure, is the remainder of the other program just appended? \$\endgroup\$
    – Ayiko
    Jan 22, 2014 at 15:49
  • \$\begingroup\$ Yes, only 1 number combination needs to work and yes if one code run out of chars, the rest of the pther is appended last on first combinated source \$\endgroup\$ Jan 23, 2014 at 15:09

3 Answers 3

2
\$\begingroup\$

Befunge-93 x4; n1=5, n2=5; 100 75 chars

I put the 4 programs into 1 file for debugging: (it outputs a random one of the four programs)

 vv  |2345|2345|2345|2345|2345|2345|2345|2345|2345|2345|2345|2345|2345|2345|2345|2345|2345|2345|23
>??#@"oll""eH"   >:#0#,_ @    #
     |2345|2345|2345|2345|2345|2345|2345|2345|2345|2345|2345|2345|2345|2345|2345|2345|2345|2345|23
>? #@"dlr""ow"        >:#0#,_ @0"!namuh olleH">:#,_@#:>"Hello computer!"
     |2345|2345|2345|2345|2345|2345|2345|2345|2345|2345|2345|2345|2345|2345|2345|2345|2345|2345|23
 > #@"oll""dlr""eH" "ow"   >:#     0#,_   >:#@    0#,_ #@0"!namuh olleH">:#,_@#:>"Hello computer!"
     |2345|2345|2345|2345|2345|2345|2345|2345|2345|2345|2345|2345|2345|2345|2345|2345|2345|2345|23
  >#@"!retupmoc olleH">:#,_@#:>"Hello human!"0@# _,#0    @#:>   _,#0     #:>   "wo" "He""rld""llo"

The separate programs are: (one per line)

"oll""eH"   >:#0#,_ @    #
"dlr""ow"        >:#0#,_ @0"!namuh olleH">:#,_@#:>"Hello computer!"
"oll""dlr""eH" "ow"   >:#     0#,_   >:#@    0#,_ #@0"!namuh olleH">:#,_@#:>"Hello computer!"
"!retupmoc olleH">:#,_@#:>"Hello human!"0@# _,#0    @#:>   _,#0     #:>   "wo" "He""rld""llo"

Edit: This time, I took advantage of the replacement rule and replaced two characters in the second combination.

\$\endgroup\$
1
\$\begingroup\$

Befunge-98 × 4, 69 chars

Following @user12551's lead, I went with 4× Befunge (although -98 rather than -93). Program code is reversed on byte-level, line ending is LF, program #1 has no terminating newline.

Program 1:

"!namolleH"4k,@

Program 2:

"vdlrow"4k,@
      >"uh olleH"bk,@,ke"Hello computer!"

Combined 1 (n₁ = 5, n₂ = 2):

"!nam"volleHdl"4k,@row"4k,@
      >"uh olleH"bk,@,ke"Hello computer!"

Combined 2 (has a bunch of trailing spaces):

"!retupmoc olleH"ek,@,kb"Hello hu">      
@,k4"wor@,k4"ldHellov"man!"
\$\endgroup\$
1
\$\begingroup\$

Windows Command script x4; n1=2; n2=2 - 92 Bytes

1st script (marked eol and eof):

 %: !rupc leoh %\r\n
 % eo llhun!% \r\n
 %echo Hello\eof

2nd script (marked eol and eof):

 %&&etmoolH ce %\r\n
 %chHeo ma% % \r\n
echo world%  \eof

Results in:

 % %: &&!retupmoc olleH ohce % %
 % % echo Hello human!% % % 
 %ecechoho w Horelldlo% 

And reversed:

 %oldlleroH w ohohcece% 
 % % %!namuh olleH ohce % % 
% % echo Hello computer!&& :% % 
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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