3
\$\begingroup\$

Create a program that outputs "Hi, Hello!" in k bytes. By altering n bytes, the code should output all odd numbers in the range 5 <= x <= 25. Changing another m bytes should result in a code that prints the following frame in ASCII-art:

+-+
| |
+-+

Change another o bytes, and print Hello, bye!.

m, n and o are calculated in Levenshtein distance (cumulative). n is the distance from the first to the second code. m is the distance between the second and third and so on.

The score of your submission will be 0.5*k + n + m + o.

As an example:

The code that prints `Hi, Hello!` is 30 bytes.              15
Add two bytes and remove one and print the odd numbers     + 3
Alter three bytes in place, and add one to print the box   + 4
Remove four bytes and print `Hello, bye!`                  + 4
Total score:                                                26

Rules

  • All codes must be in the same language
  • You have to follow the given order (i.e. the first code prints Hi, Hello, the second prints the numbers etc.)
  • The strings and ASCII-box must be exactly as specified. The list of digits can be on any suitable format
\$\endgroup\$
3
  • \$\begingroup\$ One small point is that "Hello, bye!" (the longer of the 2 strings) is only 13 bytes even with the quotes, giving savings of 6.5 when you remove it, and the distance between it and the other string is 9, making it worthless to take it out. \$\endgroup\$
    – Maltysen
    May 22, 2016 at 21:11
  • \$\begingroup\$ You could use 6 bytes extra to have "Hi, Hello!, bye!" or something in there in the original code, thus 3 extra "points". You need a byte to comment it out, but you might be able to combine it with another comment somehow. Comment it in and out would only cost a byte or two. Some commenting is probably necessary anyway, so it is might be possible to get those extra bytes "cheaper". \$\endgroup\$ May 22, 2016 at 21:38
  • 4
    \$\begingroup\$ @StewieGriffin so this was my last :-( FWIW, I've found many of your previous challenges very good. This one may not be the best, but I don't see why it has so many downvotes \$\endgroup\$
    – Luis Mendo
    May 23, 2016 at 12:07

12 Answers 12

6
\$\begingroup\$

05AB1E, 42 ÷ 2 = 21 + 1 + 1 + 1 = 24

Hi, Hello code:

”Hi,Ÿ™!”25Åɦ¦"+-+
"©"| |
"®««“Ÿ™,Þ¡!“ª\\\

Try it online!.


Odd numbers code:

”Hi,Ÿ™!”25Åɦ¦"+-+
"©"| |
"®««“Ÿ™,Þ¡!“ª\\

Try it online!.


Box code:

”Hi,Ÿ™!”25Åɦ¦"+-+
"©"| |
"®««“Ÿ™,Þ¡!“ª\

Try it online!


Hello, bye code:

”Hi,Ÿ™!”25Åɦ¦"+-+
"©"| |
"®««“Ÿ™,Þ¡!“ª

Try it online!.

Uses CP-1252 encoding.

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

Pyth - 49 46 44/2 + 1 + 1 + 1 = 25

Hello code:

h["Hi, Hello!":5lG2"+-+
| |
+-+""Hello, bye!

Odd numbers code:

ht["Hi, Hello!":5lG2"+-+
| |
+-+""Hello, bye!

Box code:

htt["Hi, Hello!":5lG2"+-+
| |
+-+""Hello, bye!

Bye Code:

httt["Hi, Hello!":5lG2"+-+
| |
+-+""Hello, bye!
\$\endgroup\$
1
  • \$\begingroup\$ @ev3commander I just make a list containing all the outputs and then take the first element of it. t removes the first element of a list, so by adding multiple ts, I can get the output I want with a distance of only 1. \$\endgroup\$
    – Maltysen
    May 22, 2016 at 20:55
3
\$\begingroup\$

Jelly, 23

First program, 40 bytes

“"©ĊĠȦẋạ»
5r25m2
“+-+¶| ”ȮṖṚ
“(ʠƤ,ụȤ»
1£

Try it online!

Second program, edit distance 1

“"©ĊĠȦẋạ»
5r25m2
“+-+¶| ”ȮṖṚ
“(ʠƤ,ụȤ»
2£

Try it online!

Third program, edit distance 1

“"©ĊĠȦẋạ»
5r25m2
“+-+¶| ”ȮṖṚ
“(ʠƤ,ụȤ»
3£

Try it online!

Fourth program, edit distance 1

“"©ĊĠȦẋạ»
5r25m2
“+-+¶| ”ȮṖṚ
“(ʠƤ,ụȤ»
4£

Try it online!

How it works

In all Jelly programs, every line defines a link. The last one is the main link and is executed automatically by the interpreter.

The quick £ inspects the number before it and calls the link on that line, so it suffices to place the four individual programs on different lines and call the appropriate one.

First program

“"©ĊĠȦẋạ»

This simply uses Jelly's built-in compression, constructing the string as Hi, (bare string), Hello (dictionary word) and ! (bare string).

Second program

5r25m2

5 sets the left argument to 5, r25 creates a range up to 25 and m2 selects every second element.

Third program

“+-+¶| ”ȮṖṚ

“+-+¶| ” sets the left argument to that string, Ȯ prints it explicitly, removes the last character and reverses the result. The reversed string gets printed implicitly.

Fourth program

“(ʠƤ,ụȤ»

Akin to the first program, this compresses the output string as Hello (dictionary word), , (bare string), bye (dictionary word, leading space) and ! (bare string).

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

J, 33 31

3{(a,', bye!');(<' ');(>:+:i.13);'Hi, ',(a=:'Hello'),'!'
2{(a,', bye!');(<' ');(>:+:i.13);'Hi, ',(a=:'Hello'),'!'
1{(a,', bye!');(<' ');(>:+:i.13);'Hi, ',(a=:'Hello'),'!'
0{(a,', bye!');(<' ');(>:+:i.13);'Hi, ',(a=:'Hello'),'!'

We select the element from the boxed list that we need.

Old solution, 33 bytes

'Hi, Hello!'
'Hi']>:+:i.13
'Hi']<' '
'Hello, bye!'

Calculated here, requires ES6 browser

'Hi, Hello!'    12 / 2 = 6
'Hi']>:+:i.13    + l.d. 10
'Hi']<' '        + l.d.  8
'Hello, bye!'    + l.d.  9
                      = 33

Requires the console interpreter for 'Hi']<' ', which uses the fact that displayed boxed items use the required ASCII border; we just box a space in this case.


Bonus code in jolf:

u+~:/lFx2~m]x0_1d~LH.xhS

Just call this with an array containing your solutions to calculate the scores! Alternatively, open up the console and type in:

jolf("u+~:/lFx2~m]x0_1d~LH.xhS", ["p1", "p2", "p3", "p4"]);
\$\endgroup\$
2
  • \$\begingroup\$ Why does it require a es6 browser unless you didn't transpire with Babel ;_; \$\endgroup\$
    – Downgoat
    May 23, 2016 at 14:30
  • \$\begingroup\$ @Downgoat that particular solution uses guillemots, which transpire to graves, an es6 feature \$\endgroup\$ May 23, 2016 at 15:50
3
\$\begingroup\$

Fuzzy Octo Guacamole, 58/2 + 1 + 1 + 1 = 32 byte-points

"Hi, Hello!""Hello, bye!"%@0{25*!5[X2a]@}"+-+"X"| |"X"+-+"

This code as-is prints Hi, Hello!. By changing the % to a space ( ), you get Hello, bye!. By changing the first @ to a space ( ), you get the list of odd numbers, starting with 5 and ending with 25.. And finally, by changing the 0 to a space, , you get +-+\n| |\n+-+.

The 4 pieces of code (iterated removals):

"Hi, Hello!""Hello, bye!"%@0{25*!5[X2a]@}"+-+"X"| |"X"+-+"
"Hi, Hello!""Hello, bye!" @0{25*!5[X2a]@}"+-+"X"| |"X"+-+"
"Hi, Hello!""Hello, bye!"  0{25*!5[X2a]@}"+-+"X"| |"X"+-+"
"Hi, Hello!""Hello, bye!"   {25*!5[X2a]@}"+-+"X"| |"X"+-+"
\$\endgroup\$
3
  • \$\begingroup\$ What the FOG is this language? Lame pun aside, a link to its specification would be nice :) \$\endgroup\$
    – Aaron
    May 23, 2016 at 15:59
  • \$\begingroup\$ @Aaron sure, I'll add that. \$\endgroup\$
    – Riker
    May 23, 2016 at 16:13
  • \$\begingroup\$ You dirty upvote beggar ! "/s" \$\endgroup\$
    – Aaron
    May 23, 2016 at 19:24
2
\$\begingroup\$

Haskell, 41

"Hi, Hello!"
--[5,7..25]
--"+-+\n| |\n+-+"
--"Hello, bye!"

--"Hi, Hello"
[5,7..25]
--"+-+\n| |\n+-+"
--"Hello, bye!"

--"Hi,Hello"
--[5,7..25]
"+-+\n| |\n+-+"
--"Hello, bye!"

--"Hi,Hello"
--[5,7..25]
--"+-+\n| |\n+-+"
"Hello, bye!"

The initial program is 58 bytes, i.e. a score of 29. Each of the successors adds -- and removes -- for a score of 4, so the total is 29 + 3*4 = 41.

Haskell 33.5

If returning the list of numbers as a String, i.e. "[5,7,9,11,13,15,17,19,21,23,25]" is fine, then

["Hi, Hello!",show[5,7..25],"+-+\n| |\n+-+","Hello, bye!"]!!0
["Hi, Hello!",show[5,7..25],"+-+\n| |\n+-+","Hello, bye!"]!!1
["Hi, Hello!",show[5,7..25],"+-+\n| |\n+-+","Hello, bye!"]!!2
["Hi, Hello!",show[5,7..25],"+-+\n| |\n+-+","Hello, bye!"]!!3

works for 61/2 + 1 + 1 +1 = 33.5

\$\endgroup\$
4
  • \$\begingroup\$ I kinda miss a main = print … to make a program. \$\endgroup\$
    – Bergi
    May 22, 2016 at 21:28
  • 1
    \$\begingroup\$ @Bergi: "program" usually means program or function. For programs we use the term "full program". \$\endgroup\$
    – nimi
    May 22, 2016 at 21:31
  • \$\begingroup\$ Oh right, but I still miss the print for output. Or do you mean that your expressions are zero-arity functions whose result is printed when ran with GHCI? :-) \$\endgroup\$
    – Bergi
    May 22, 2016 at 21:35
  • 1
    \$\begingroup\$ @Bergi: Functions may output via their return value. \$\endgroup\$
    – nimi
    May 22, 2016 at 21:38
2
\$\begingroup\$

Octave, 34

Managed to get it down to 62 bytes. A Levenshtein distance of 3 takes the score up to 34.

disp({'Hi, Hello!',["+-+\n| |\n+-+"],5:2:25,'Hello, bye!'}{1})

Using double quoted strings, we can use the newline character \n instead of the ASCII value 10.

Tests:

disp({'Hi, Hello!',["+-+\n| |\n+-+"],5:2:25,'Hello, bye!'}{1})
Hi, Hello!

disp({'Hi, Hello!',["+-+\n| |\n+-+"],5:2:25,'Hello, bye!'}{2})
+-+
| |
+-+

disp({'Hi, Hello!',["+-+\n| |\n+-+"],5:2:25,'Hello, bye!'}{3})
5    7    9   11   13   15   17   19   21   23   25

disp({'Hi, Hello!',["+-+\n| |\n+-+"],5:2:25,'Hello, bye!'}{4})
Hello, bye!
\$\endgroup\$
1
\$\begingroup\$

JavaScript, 80 ÷ 2 + 1 + 1 + 1 = 43

_=>[`Hi, Hello!`,`5 7 9 11 13 15 17 19 21 23 25`,`+-+
| |
+-+`,`Hello, bye!`][0]

Change the 0 to 1, 2, or 3 as appropriate. I tried generating the odd numbers but that cost me a byte.

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

Python 3, 69/2 + 1 + 1 + 1 = 37.5 points.

It's the same approach as the other answers, but in Python.

print(['Hi, Hello!',*range(5,27,2),'+-+\n| |\n+-+','Hello, bye!'][1])

Change the number to the one you want for a distance of 1.

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

Python 2, 66 / 2 + 1 + 1 + 1 = 36

Python 3 answer by @MorganThrapp

Hi, Hello!

print('Hi, Hello!',range(5,26,2),'+-+\n| |\n+-+','Hello, bye!')[0]

[5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25]

print('Hi, Hello!',range(5,26,2),'+-+\n| |\n+-+','Hello, bye!')[1]

+-+
| |
+-+

print('Hi, Hello!',range(5,26,2),'+-+\n| |\n+-+','Hello, bye!')[2]

Hello, bye!

print('Hi, Hello!',range(5,26,2),'+-+\n| |\n+-+','Hello, bye!')[3]
\$\endgroup\$
4
  • \$\begingroup\$ Can you use a list comprehension for the odd numbers? And why not range? \$\endgroup\$
    – Riker
    May 23, 2016 at 19:05
  • \$\begingroup\$ @EᴀsᴛᴇʀʟʏIʀᴋ It's actually longer than you think. \$\endgroup\$ May 23, 2016 at 19:06
  • 1
    \$\begingroup\$ Actually, can't you use range(5,26,2)? You don't need the list comprehension in python 2. \$\endgroup\$
    – Riker
    May 23, 2016 at 19:19
  • \$\begingroup\$ @EᴀsᴛᴇʀʟʏIʀᴋ yep. \$\endgroup\$ May 23, 2016 at 19:20
0
\$\begingroup\$

Mathematica, 74/2+1+1+1 = 40

s=##<>"!"&;s["Hi, ",h="Hello"][2Range@11+3,"+-+
| |
+-+",h~s~", bye"][[0]]

Creates a list whose elements are the four outputs, and then selects list element 0 to produce the first output; that 0 can be changed to 1, 2, or 3 to produce the other outputs. (The odd integers from 5 to 25 are output as a list.) Saved one byte by using the golfing trick where the head of a "list" is its element 0. Also saved a few bytes by defining a function s that concatenates its two arguments and adds an exclamation point, which allows me to reuse "Hello".

\$\endgroup\$
0
\$\begingroup\$

05AB1E (legacy), score: 19.5 18.5 (31 bytes / 2 + 1 + 1 + 1)

  1. “Ÿ™,Þ¡!“ª"+-+\n| "ûTÝ·5+”ŒÞ,Ÿ™!” - try it online;
  2. “Ÿ™,Þ¡!“ª"+-+\n| "ûTÝ·5+”ŒÞ,Ÿ™!”\ - try it online;
  3. “Ÿ™,Þ¡!“ª"+-+\n| "ûTÝ·5+”ŒÞ,Ÿ™!”\\ - try it online;
  4. “Ÿ™,Þ¡!“ª"+-+\n| "ûTÝ·5+”ŒÞ,Ÿ™!”\\\ - try it online.

Based on @Adnan's 05AB1E (legacy) answer, but further golfed. Since Adnan isn't really active anymore, I decided to post it as a separated answer.

Explanation:

“Ÿ™,Þ¡!“ª   # Fourth output:
“Ÿ™,Þ¡!“    #  Push dictionary string "hello, bye!"
        ª   #  Sentence capitalize it: "Hello, bye!"
"+-+\n| "û  # Third output:
"+-+\n| "   #  Push string "+-+\n| "
         û  #  Palindromize it to "+-+\n| |\n+-+"
TÝ·5+       # Second output:
TÝ          #  Push list [0,1,2,3,4,5,6,7,8,9,10]
  ·         #  Double each: [0,2,4,6,8,10,12,14,16,18,20]
   5+       #  Increase each by 5: [5,7,9,11,13,15,17,19,21,23,25]
”ŒÞ,Ÿ™!”    # First output:
”ŒÞ,Ÿ™!”    #  Push dictionary string "Hi, Hello!"
\           # (zero to three times) Discard the top of the stack
            # (implicitly output the top of the stack as result)

See this 05AB1E tip of mine (section How to use the dictionary?) to understand why “Ÿ™,Þ¡!“ is "hello, bye!" and ”ŒÞ,Ÿ™!” is "Hi, Hello!".

ª (sentence capitalize) is the reason for using the legacy version of 05AB1E, since this builtin is in the new version of 05AB1E.

\$\endgroup\$

Your Answer

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

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