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
12 Answers 12
05AB1E, 42 ÷わる 2 =わ 21 +たす 1 +たす 1 +たす 1 =わ 24
Hi, Hello code:
"Hi,ŸTM!"25Åɦ¦"+-+
"©"| |
"®««"ŸTM,Þ¡!"a\\\
Odd numbers code:
"Hi,ŸTM!"25Åɦ¦"+-+
"©"| |
"®««"ŸTM,Þ¡!"a\\
Box code:
"Hi,ŸTM!"25Åɦ¦"+-+
"©"| |
"®««"ŸTM,Þ¡!"a\
Hello, bye code:
"Hi,ŸTM!"25Åɦ¦"+-+
"©"| |
"®««"ŸTM,Þ¡!"a
Uses CP-1252 encoding.
-
\$\begingroup\$ I had a few golf suggestions to golf it to score 19.5, but ended up posting it as a separated answer. \$\endgroup\$Kevin Cruijssen– Kevin Cruijssen2022年12月08日 10:00:52 +00:00Commented Dec 8, 2022 at 10:00
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!
-
\$\begingroup\$ @ev3commander I just make a list containing all the outputs and then take the first element of it.
tremoves the first element of a list, so by adding multiplets, I can get the output I want with a distance of only1. \$\endgroup\$Maltysen– Maltysen2016年05月22日 20:55:32 +00:00Commented May 22, 2016 at 20:55
Jelly, 23
First program, 40 bytes
""©ĊĠȦẋạ»
5r25m2
"+-+¶| "ȮṖṚ
"(ʠƤ,ụȤ»
1£
Second program, edit distance 1
""©ĊĠȦẋạ»
5r25m2
"+-+¶| "ȮṖṚ
"(ʠƤ,ụȤ»
2£
Third program, edit distance 1
""©ĊĠȦẋạ»
5r25m2
"+-+¶| "ȮṖṚ
"(ʠƤ,ụȤ»
3£
Fourth program, edit distance 1
""©ĊĠȦẋạ»
5r25m2
"+-+¶| "ȮṖṚ
"(ʠƤ,ụȤ»
4£
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).
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"]);
-
\$\begingroup\$ Why does it require a es6 browser unless you didn't transpire with Babel ;_; \$\endgroup\$Downgoat– Downgoat2016年05月23日 14:30:17 +00:00Commented May 23, 2016 at 14:30
-
\$\begingroup\$ @Downgoat that particular solution uses guillemots, which transpire to graves, an es6 feature \$\endgroup\$Conor O'Brien– Conor O'Brien2016年05月23日 15:50:05 +00:00Commented May 23, 2016 at 15:50
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"+-+"
-
\$\begingroup\$ What the FOG is this language? Lame pun aside, a link to its specification would be nice :) \$\endgroup\$Aaron– Aaron2016年05月23日 15:59:08 +00:00Commented May 23, 2016 at 15:59
-
\$\begingroup\$ @Aaron sure, I'll add that. \$\endgroup\$Riker– Riker2016年05月23日 16:13:00 +00:00Commented May 23, 2016 at 16:13
-
\$\begingroup\$ You dirty upvote beggar ! "/s" \$\endgroup\$Aaron– Aaron2016年05月23日 19:24:16 +00:00Commented May 23, 2016 at 19:24
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
-
\$\begingroup\$ I kinda miss a
main = print ...to make a program. \$\endgroup\$Bergi– Bergi2016年05月22日 21:28:26 +00:00Commented 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– nimi2016年05月22日 21:31:20 +00:00Commented May 22, 2016 at 21:31
-
\$\begingroup\$ Oh right, but I still miss the
printfor output. Or do you mean that your expressions are zero-arity functions whose result is printed when ran with GHCI? :-) \$\endgroup\$Bergi– Bergi2016年05月22日 21:35:16 +00:00Commented May 22, 2016 at 21:35 -
1\$\begingroup\$ @Bergi: Functions may output via their return value. \$\endgroup\$nimi– nimi2016年05月22日 21:38:43 +00:00Commented May 22, 2016 at 21:38
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!
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.
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.
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]
-
\$\begingroup\$ Can you use a list comprehension for the odd numbers? And why not range? \$\endgroup\$Riker– Riker2016年05月23日 19:05:45 +00:00Commented May 23, 2016 at 19:05
-
\$\begingroup\$ @EᴀsᴛᴇʀʟʏIʀᴋ It's actually longer than you think. \$\endgroup\$Erik the Outgolfer– Erik the Outgolfer2016年05月23日 19:06:54 +00:00Commented 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– Riker2016年05月23日 19:19:41 +00:00Commented May 23, 2016 at 19:19 -
\$\begingroup\$ @EᴀsᴛᴇʀʟʏIʀᴋ yep. \$\endgroup\$Erik the Outgolfer– Erik the Outgolfer2016年05月23日 19:20:37 +00:00Commented May 23, 2016 at 19:20
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".
05AB1E (legacy), score: (削除) 19.5 (削除ここまで) 18.5 (31 bytes / 2 + 1 + 1 + 1)
"ŸTM,Þ¡!"a"+-+\n| "ûTÝ·5+"ŒÞ,ŸTM!"- try it online;"ŸTM,Þ¡!"a"+-+\n| "ûTÝ·5+"ŒÞ,ŸTM!"\- try it online;"ŸTM,Þ¡!"a"+-+\n| "ûTÝ·5+"ŒÞ,ŸTM!"\\- try it online;"ŸTM,Þ¡!"a"+-+\n| "ûTÝ·5+"ŒÞ,ŸTM!"\\\- 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:
"ŸTM,Þ¡!"a # Fourth output:
"ŸTM,Þ¡!" # Push dictionary string "hello, bye!"
a # 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]
"ŒÞ,ŸTM!" # First output:
"ŒÞ,ŸTM!" # 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 "ŸTM,Þ¡!" is "hello, bye!" and "ŒÞ,ŸTM!" is "Hi, Hello!".
a (sentence capitalize) is the reason for using the legacy version of 05AB1E, since this builtin is .a in the new version of 05AB1E.
Explore related questions
See similar questions with these tags.
"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\$