Anti-golfscript anti-golf: create a task where GolfScript or J is outgolfed by your (conventional) lang

29

4

You need to make three things:

  1. Statement of a task, T.
  2. Solution of the task in language not typically used for golfing, A.
  3. Solution of the task in language typically used for golfing, B. Don't try to just bloat up B to pump up the score, instead think as if B was written by your competitor.

Use common sense in defining typically used for golfing, try to maximize fun for other users.

Other users may propose better Bs (maybe including in other "golfy" languages).

Scoring is (length_in_bytes(B)+5)/(length_in_bytes(A)+5), more is better. (Maybe the scoring formula should be changed?..)

The main idea is to invent a task where languages that typically perform well in codegolf meet a problem. It can be sudden strength of a usual language in the given task or sudden weakness of some golflang.

Avoid tasks that mention specific programming languages, like Input a string and execute it as a Scheme code.

Vi.

Posted 2014-01-17T19:27:37.270

Reputation: 2 644

Question was closed 2016-04-19T14:27:50.680

1I suppose that you make this a popularity-contest instead of a code-golf. Otherwise people will complain that it is not a "shortest-code-wins". – Victor Stafusa – 2014-01-17T19:36:49.457

OK, changing to popularity-contest. You can also suggest better title or better scoring. – Vi. – 2014-01-17T19:38:21.793

I assume my previous question qualifies? https://codegolf.stackexchange.com/questions/18633/print-a-sinusoidal-wave-vertically The perl solution is 48 chars while the J solution is 54 chars

– user12205 – 2014-01-17T19:40:47.223

Numerator is supposed to be minimum of length_in_bytes for all suitable B's. – Vi. – 2014-01-17T19:41:16.287

@ace, Yes, linking to existing specific problems with specific solutions is OK; can be posted as answer (copied summary of the statement + links to A and B) – Vi. – 2014-01-17T19:42:33.997

1Do we get to specify lang B (as long as it is good at golfing)? Or can anyone say "here is a program in language <insert language name> and it has a very short solution of length <n>:"? – Justin – 2014-01-17T19:49:12.783

@Quincunx, As it currently has "popularity-contest", bending "use common sense to decide what is golf language and what is not" rule is just expected not to be upvoted. – Vi. – 2014-01-17T19:53:51.447

@Vi. Wasn't trying to bend that rule; just wondered if anyone can say "here is a shorter version in MY language" and wreck the score. – Justin – 2014-01-17T19:57:25.943

@Quincunx, If the task is based on "A suprising strength of some A" then yes; if on "A suprising weakness of some language for B" then no. The alternative solution can be posted in comments in any case, so others can calculate alternative score. – Vi. – 2014-01-17T20:00:18.847

1BTW some languages like Perl can be both on A side and on B side, depending on context. – Vi. – 2014-01-17T20:02:44.997

What if it's extremely difficult to do on B? I have perform OCR in mind which mathematica can do as shown here http://codegolf.stackexchange.com/a/17094/8766 but would be very difficult in languages not specifically built for it

– user80551 – 2014-01-26T18:22:36.503

@user80551, Then provide a proof that B 1. there exists implementation of the task in B; 2. each implementation of the task in B must take not less than N characters. – Vi. – 2014-01-26T18:25:38.757

@Vi. See the edit – user80551 – 2014-01-26T18:26:40.193

@user80551, OCR? There can't be short and golfable OCR algorithms? Actually you may write something like I believe it can't be done in less than 5000 bytes on languages B1, B2 or B3. If other savvy user disagrees, he/she may provide a counterexample (shorter working solution in B). This is less funny although... – Vi. – 2014-01-26T18:29:15.537

Why was this closed as off-topic? It seems to have an objective winning criterion to me? – pppery – 2019-04-14T16:19:24.120

Answers

14

My previous question, Print a sinusoidal wave (vertically), qualifies at this moment. I'm posting it here as a solution, also hoping that you guys can come up with some shorter solutions to my original question.

As required by Vi., I will post a summary of the question.

Print a continuous sinusoidal wave scrolling vertically on a terminal. The program should not terminate and should continuously scroll down the wave (except until SIGINT). You may assume overflow is not a problem (i.e. you may use infinite loops with incrementing counters, or infinite recursion).

The wave should satisfy the following properties:

  • Amplitude = 20 chars (peak amplitude)
  • Period = 60 to 65 lines (inclusive)
  • The output should only consist of spaces, newline and |
  • After each line of output, pause for 50ms

There is a sample output on my original question, but I'm not posting it here, because this will make my answer ridiculously long. My original question can be seen here: Print a sinusoidal wave (vertically)

Shortest A currently: a Perl solution with 48 chars: https://codegolf.stackexchange.com/a/18655/12205

print$"x(25+20*sin).'|
';$_+=.1;`sleep .05`;do$0

Shortest B currently: a J solution with 54 chars: https://codegolf.stackexchange.com/a/18649/12205

($:+&0.1[6!:3@]&0.05[2:1!:2~' |'#~1,~[:<.20*1+1&o.)0  




Currently, the score of this answer is 1.113 (an awfully low score)

user12205

Posted 2014-01-17T19:27:37.270

Reputation: 8 752

The current score according to current formula is approximately 1.113 – Vi. – 2014-01-17T19:54:43.717

@Vi. should I delete this answer or should I wait some time and see what happens? If the latter, how long should I wait? – user12205 – 2014-01-17T20:23:59.410

The statement states bytes, not characters. Converted to UTL-8, the APL solution made 61 bytes (70 for UTF-16). – Vi. – 2014-01-17T20:26:17.790

2You're claiming that Perl is not a language typically used for golfing, but it's the language which was first associated with the word golf! Ruby, at 56, looks like the real language A in the current answers to your questions. – Peter Taylor – 2014-01-18T10:44:39.180

8

Add two numbers

Get two numbers from STDIN, and add them together. You have to support floating point numbers, so 0.5 + 1.5 has to equal 2.

Perl 5 (with -E)

say<>+<>

GolfScript

n%'+'*'"#{
}"'n/\*~

Konrad Borowski

Posted 2014-01-17T19:27:37.270

Reputation: 11 185

In Pyth, this is just s.Q, and in O, jj+. – kirbyfan64sos – 2015-08-29T23:14:54.550

Calculated score as (24+5)/(8+2+5) = 1.9(3). -E also counted as program bytes. – Vi. – 2014-01-18T13:15:54.323

The same comment as I made to ace: you're claiming that Perl is not a language typically used for golfing, but it's the language which was first associated with the word golf! – Peter Taylor – 2014-01-18T13:55:08.977

And your GolfScript program doesn't work. A working program would be n%'+'*'"#{ }"'n/\*~ where the character between {} is a literal newline (not supported in comments). – Peter Taylor – 2014-01-18T13:56:32.137

@PeterTaylor, Compared with GolfScript, Perl is a "usual" language; compared with Java, it's a "golf" language. – Vi. – 2014-01-18T14:33:44.767

Score using PeterTaylor's golfscript variant: 1.6. I can although successfully run neither of variants with my GolfScript interpreter (md5 = 8bb179c2eb47060026a9a598a4263900). – Vi. – 2014-01-18T14:38:18.127

1The J for this isn't too bad, actually: +/".1!:1,~1. APL would probably be even smaller. – algorithmshark – 2014-03-25T23:55:56.297

8

Print 'Hello, World!' to the stdout.

PHP, 13 bytes

Hello, World!

Golfscript, 15 bytes

'Hello, World!'

Pyth, 14 bytes

"Hello, World!

georgeunix

Posted 2014-01-17T19:27:37.270

Reputation: 3 169

3Nicely topical. :) – AdmBorkBork – 2015-08-28T14:39:36.320

2New B: In HQ9+ H – Not that Charles – 2015-08-28T15:31:08.517

2But it's spelt incorrectly, @NotthatCharles – georgeunix – 2015-08-28T15:35:43.350

1@georgeunix Good point. You capitalized your "W". – Not that Charles – 2015-08-28T15:52:08.767

7

Score 48/37 or 1.(297)

T: write a code snippet that ends the program after exactly one hour (as close as possible, like within a second) of running. Don't worry about exceptions, they can be unhandled.

A: Java (32)

Thread.sleep(3600000);int a=1/0;

B: is for Befunge 98, requires the TIME fingerprint (43)

"EMIT"4(HMS00p01p02p#;gS-!01gM-!H-!++3-!j;@

This takes the Hour, Minute, and Second at the time of running, and puts the at cells 02, 01, and 00. Then, it skips over the ; to the second part. The second part works as follows:

g          get the value at 00
"EMIT"4(S) get the current time in seconds
-!         subtracts the values and changes a 0 to 1, anything else to 0

similarly for the Minute and Hour.

++  sums up the values
3-! i the sum is 3, we get a 1, otherwise, we get a 0.
j   jump over the next that many cells
;   skip code execution until the next ;
@   end program

Note that Befunge will automatically go back to the beginning of the line when the end of a line is reached.


As we can see, Befunge is not good when it comes to waiting for specific times. However, Java is not bad.

Justin

Posted 2014-01-17T19:27:37.270

Reputation: 19 757

Your befunge code isn't golfed well enough. You can just do "EMIT"4( at the beginning of your program, rather than every single time you need to get the time. Fixing this problem qould reduce your score to 1.3 – pppery – 2016-05-14T17:03:28.200

Also, I don't think you need self-modifying code for this. – pppery – 2016-05-14T17:10:05.297

In addition, your befunge will fail if run when the hour, minute, or second is exactly 59 (the ascii value of ';') – pppery – 2016-05-14T17:35:42.267

thought I'd make the code difference even bigger; now it is clear who is better. – Justin – 2014-01-17T21:45:00.157

9APL: ⎕DL 3600 – marinus – 2014-01-17T21:54:32.603

14Java usually reads as class Main{public static void main... – Vi. – 2014-01-17T22:00:00.800

3@Vi. see "code snippet". Basically, it requires the code that actually does the work, not more than that. – Justin – 2014-01-17T22:01:39.163

@marinus okay APL is good too, but Befunge is not. – Justin – 2014-01-17T22:02:05.917

This task is still a valid answer. To sleep in the GNU/Linux bash shell (as A), sleep 1h works, and is still shorter than (by byte count, otherwise of the same length as) the APL solution by @marinus :) – user12205 – 2014-01-17T22:03:56.347

Python's import time\ntime.sleep(3600) is also OK (as A) and is 28 bytes. – Vi. – 2014-01-17T22:04:18.753

@Vi. Ah, but python can be quite good at golfing. The Java code is also valid, so I'll keep it as that. – Justin – 2014-01-17T22:06:38.953

Tcl: after 3600000. Why do people bring brainfuck to claim that a certain task is hard to golf in a regular golf language? – Johannes Kuhn – 2014-01-18T03:36:33.257

@JohannesKuhn What are you talking about? Befunge (I'll assume that is what you meant) is the language I golf in. – Justin – 2014-01-18T03:38:57.033

2I don't know Befunge, but the Java snippet doesn't "end the program" as required by the spec. That would require either a System.exit(0); or wrapping your sleep in a main method. – Peter Taylor – 2014-01-18T09:40:40.447

@PeterTaylor Rather than the verbose System.exit(0), I can use int a=1/0 to terminate by exception. The Befunge snipped does end the program; eventually, the IP will reach the @. – Justin – 2014-01-18T09:45:10.813

1@Quincunx Why can't you just remove the int a= part? – Doorknob – 2014-01-18T13:09:34.687

3@DoorknobofSnow Fails to compile: error: not a statement – Bob – 2014-01-18T14:12:15.133

5

Output a certain text file (498.388888 points)

The goal output is here.

The Python 3.4.3 script to print it is 49 bytes:

for b in dir(__builtins__):print(eval(b).__doc__)

The naive CJam program equal to the goal output, by wrapping the output string in "..." and escaping each " that occurs in it, would be 26908 bytes.

Lynn

Posted 2014-01-17T19:27:37.270

Reputation: 55 648

Very clever, though it may run afoul of the "specific languages" restriction (which is vague, admittedly). – BMac – 2015-08-27T21:34:23.607

The closest rule is "avoid mentioning specific language". Python is not mentioned, but is clearly meaned. – Vi. – 2015-08-28T00:35:03.683

Yeah, this answer is a bit tongue-in-cheek, I sort of just wanted to point out that the rule is sort of a slippery slope. Imagine if I had "mangled" the output more -- say, taking the SHA1 checksum of each docstring -- it would be very weird to claim "this garbled bunch of hex digits is too language-specific" :) – Lynn – 2015-08-28T17:23:50.160

If I wanted to do a more "fair" answer, I'd probably use Mathematica. You can do a lot of extremely domain-specific things in it that would take thousands of bytes of CJam/Pyth/anything else. But sadly, I don't know the language. – Lynn – 2015-08-28T17:24:54.470

Link to output is dead. – pppery – 2019-10-19T16:42:13.193

4

Say "Hello world!" (50 / 26 ≈ 1.92)

Show a message box to say "Hello world!"

JavaScript

alert('Hello world!')

In a browser with support for DOM Level 0+.

Perl

use Win32;Win32::MsgBox('Hello world!','',48)

Running on ActivePerl with Win32::GUI.

Toothbrush

Posted 2014-01-17T19:27:37.270

Reputation: 3 197

alert isn't inherently part of JS, and the GolfScript program is just a comment. – Peter Taylor – 2014-01-26T22:31:31.500

I've changed the answer to use plain Perl. – Toothbrush – 2014-01-27T12:41:47.780

3

Output "Hello world!" until user presses "q", 1.842 105/44 = 2.386

  1. Print "Hello world!" (including newline).
  2. The user presses a key, which is not echoed to the screen.
  3. Repeat until the key pressed was "q".

QBasic (52 39 characters)

1?"Hello world!":IF"q"<>INPUT$(1)THEN 1

Since posting my original answer, I discovered that I could turn off autoformatting in QB64. :^D With the line number and ? shortcut for PRINT, this looks rather like a ternary expression in C-like languages.

First version:

PRINT "Hello world!"
IF INPUT$(1) <> "q" THEN RUN

Perl 5 (100 characters)

while("q"ne$e){print"Hello world!\n";system"stty cbreak -echo";$e=getc;system"stty -cbreak echo";}

The above will only work on (certain?) UNIX systems (tested on Ubuntu 12.04). It's possible that one could go cross-platform and get it down to 91 characters using the Term::ReadKey module, but I haven't tested it:

use Term::ReadKey;while("q"ne$e){print"Hello world!\n";ReadMode 3;$e=ReadKey 0;ReadMode 0;}

DLosc

Posted 2014-01-17T19:27:37.270

Reputation: 21 213

1

Hello, world (3 1/3 points)

Write program that outputs Hello World..

HQ9+ (1 character)

This is not language "typically used for golfing", so I believe it fits here. Works in this interpreter, by the way.

H

GolfScript (15 characters)

I doubt it can get any shorter, even if it's GolfScript.

"Hello World."

Konrad Borowski

Posted 2014-01-17T19:27:37.270

Reputation: 11 185

@Vi compared to Java, anything's a golflang. – programmer5000 – 2017-04-05T20:16:59.443

8I don't think HQ9+ suits as A language. It is designed for tricks/riddles/fun. Brainfuck/unlambda/other esoterical languages also does not seem to suit as A. – Vi. – 2014-01-19T21:02:33.287

@Vi.: But it's not typically used for golfing. – Konrad Borowski – 2014-01-19T21:03:19.260

4You can hovewer try to use HQ9+ as B language and beat it by Java or such... – Vi. – 2014-01-19T21:03:50.900

7Looks like there's a hierarchy: Compared to Java, Perl's a golflang. Compared to Perl, GolfScript is a golflang. Compared to GolfScript, HQ9+ is a golflang... – Vi. – 2014-01-19T21:06:23.880

@Vi.: I carefully checked your task description. HQ9+ is never used for golfing, except for two particular tasks - "99 bottles", and "Hello, world". Unless you can show some other task in which HQ9+ wins with any other programming language, I still think it fits the definition, even if it abuses it (hey, it's [tag:popularity-contest]). HQ9+ is simply not used for golfing stuff not related to those two tasks. So, it's not typically used for golfing. The second is obviously designed for CodeGolf - it's GolfScript. – Konrad Borowski – 2014-01-19T21:09:05.690

OK, considering it as "the best abuse of rules" nomination. – Vi. – 2014-01-19T21:10:49.113

@xfix one more case where HQ9+ is the best at golfing: Quines (when disallowing the empty program) – Justin – 2014-01-20T05:25:15.173

@Quincunx: Here, I win in GolfScript, Befunge, and PHP - 1. You wouldn't tell me that PHP is golfing language, and yet it has a short quine. Actually, in PHP, any single character is a quine. – Konrad Borowski – 2014-01-20T15:39:17.843

@xfix That is not a quine in Befunge. – Justin – 2014-01-20T16:57:43.350

@Quincunx: Uhm, yeah, my mistake. Well, bc then. – Konrad Borowski – 2014-01-20T17:12:11.267

0

Output "Hello world!", 33/97 = 2.94

Write a program that outputs Hello world!

Arduino or GML

Serial.print("Hello world!")

or

show_message("Hello world!")

Both are 28 characters.

GTB

I use GTB for golfing a lot (especially since I created it myself, and it is Turing complete). Unfortunately, there is only limited support for lowercase characters (because TI-84 calculator can't deal with it). This is probably the shortest GTB program that can output Hello world!

S;"lower",1,1)→_~"H"+S;"expr(",1,1)+_+_+S;"cos(",2,1)+" W"+S;" or ",2,2)+_+S;" and ",4,1)+"!

92 characters.

Timtech

Posted 2014-01-17T19:27:37.270

Reputation: 12 038

TI-BASIC's lowercase Hello World program is just "Hello, world with lowercase letters typed in using some sort of utility; additionally sub( does not work like that. – lirtosiast – 2015-06-07T15:24:29.297

Umm yeah, not sure what I was thinking when I wrote this answer, sorry about that. – Timtech – 2017-02-28T12:13:56.540

Does GTB version also output it to serial port? – Vi. – 2014-01-20T01:59:44.697

Is GTB version intentionally bloated up with various coss and exprs or it genuintely can't just output something in regular way? Or " character is actually not a string literal and confusing me... – Vi. – 2014-01-20T02:01:11.767

@Vi. It's not bloated up at all... it has to strip e from expr, two l from lower, o from cos, or from or, l from lower, and d from and. – Timtech – 2014-01-20T11:10:40.780

'Other users may propose better Bs (maybe including in other "golfy" languages). ' --- let me try golfscript: "Hello world!" – John Dvorak – 2014-04-13T09:01:00.500

@JanDvorak You're probably right. – Timtech – 2014-04-13T22:00:27.487

Never thought I'd see GML used here. – Sean Latham – 2014-09-05T23:34:09.023

@ipi I've used it in several other answers. – Timtech – 2014-09-08T17:41:07.860