Your Language in a Box

8

2

Now with BONUS for run-time placement.

Write a program to fill a text box with the identifiers used in your program while keeping your program small. With all the identifiers you have used (excluding those you created) in your program, fill a 12x6 box with as many as you can. You get extra points for identifiers that cross over (crossword style), but they can't join end to end.

Output

Your program should print (to stdout) a 12x6 character box with your packed identifiers and a # border. The box should have columns labeled with letter A-L and the rows 1-6 (spaced like the example below). Then print a line for each identifier used. Each line will have the location of the first letter, the identifier itself, and the score. The score is equal to the number of letters in the identifier with a possible '+bonus' added. The identifier gets a 5 point bonus for each letter shared with a crossing identifier. The final line reports 'TOTAL: ' and the sum of the identifier scores. An example output for a possible Python program would look like this:

   ABCDEFGHIJKL
  ##############
1 #  pinsert   #
2 #  o         #
3 #  print     #
4 #    not     #
5 #            #
6 #import      #
  ##############
C1 pop 3+5
D1 insert 6
C3 print 5+10
E3 in 2+10
E4 not 3+5
A6 import 6
TOTAL: 55

Notes:

  • Identifiers can be unattached (like import above).
  • You cannot join pop and print inline with poprint.
  • The string in inside insert cannot be used. Joining words must be orthogonal.
  • Identifiers can be placed next to each other (like pop and insert above).

Your answer should include your program output with your source code and a title consisting of the language name and your score.

Score

Your score for the challenge will the the puzzle score squared divided by the size of your source code (in bytes). Eg: The puzzle above with a 300 byte program would score 55*55/300 = 10.08. Highest score wins.

Rules

  • You can use any identifier in your program that is not defined by you. Keywords, class names, method names, library names, and built-in function names are examples of eligible identifiers.
  • EDITED: You may only use standard libraries that are included with the minimum language release. Extended language packages and the use of external libraries (are now) forbidden. The huge range of libraries with extensive lists of identifiers would unbalance this challenge. If you are unsure of how this works with your language, please leave a question in the comments.
  • Identifiers must consist of [a-zA-Z_] characters only and have at least 2 characters.
  • You may only use each identifier once in the puzzle.
  • Identifiers can only be used left to right or downwards.

Dynamic Bonus!

If your code determines where to place identifiers at run time, the shared letter bonus will be 20 instead of 5. You may list which identifiers will used, but your code must decide where in the box to place them. Your code must also calculate and print the score list. If your placements depend on the ordering of the identifier list, hard-coded pairings, or other non-dynamic placement short-cuts, you are not eligible for the Dynamic Bonus.

In the example output above, the puzzle score for a run-time placement program would become 145. Then if the code was 800 bytes, the score would be 145*145/800 = 26.28.

The Dynamic Bonus is designed to reward clever algorithms instead of static hard-coded solution strings, and compensate for the larger resulting source code size.

EDITS:

  • Changed libraries used to only those in the minimum language release.
  • Added the dynamic bonus option.

Logic Knight

Posted 2015-02-08T04:22:38.863

Reputation: 6 622

Just to be clear, greater score is better, right? – Digital Trauma – 2015-02-08T06:01:28.247

1Correct. Jam as many unique identifiers into the box while keeping your program as small as possible -> best score. – Logic Knight – 2015-02-08T06:21:56.217

Does this challenge actually involve programming? – feersum – 2015-02-08T07:58:08.383

Perhaps I should make this more clear. You must write and execute a program that outputs the text requirement. The text in the output depends on the identifiers used in the program you write. – Logic Knight – 2015-02-08T08:03:05.993

1FYI, some libraries involving SIMD or Shader defines all combinations of xyzw / rgba / stpq :) – kennytm – 2015-02-08T10:27:16.250

@KennyTM I realise now that free libraries may be abused. I have changed the question to allow only standard libraries. I apologise to any who have done work that is now prohibited. – Logic Knight – 2015-02-08T11:27:49.733

Is it right that builtin methods count as well, since you've used list.pop and list.insert? – grc – 2015-02-08T12:37:22.593

@grc: Yes. Identifiers such as builtin methods can be used in the puzzle if used in your program. They are identifiers from the standard language (and obviously not created by you) so are allowed. – Logic Knight – 2015-02-08T13:20:10.697

Can words be placed in sequence (ex. popprint)? – Doorknob – 2015-02-08T14:26:06.353

@Doorknob: Yes. Words can be touching, end to end, or otherwise. – Logic Knight – 2015-02-08T15:13:00.370

Lets say my language has keywords: ab, cd, ef, abc, def. Can I score for all of them (for a total of 12 points) with a row abcdef? – nutki – 2015-02-09T08:52:38.297

@nutki: no. You may not embed words in other words or connect them in a line. Words may only be connected orthogonally. There are however many possible sharing letters (I count 4) in your example which would score well. – Logic Knight – 2015-02-09T12:04:19.120

Do you have to use the keywords actively? (I mean you could write a do-loop with nothing in it just so you can use the keyword) – dwana – 2015-02-09T15:07:59.983

The identifiers used must be used correctly for your language. They must be executed or at least be able to be executed (you can't just list the keywords you want to use). It is not required that the code does anything useful. – Logic Knight – 2015-02-09T15:57:36.720

Answers

2

STATA, 387^2 / 677 = 221.2

I got lazy and just wanted to output something that works before trying to get it with optimal score. I'll probably update it later as I fit more words in, and I'm open to suggestions from anyone that uses STATA (which doesn't seem very popular on CodeGolf). STATA is really good about having a lot of two letter commands/parameters. Also, usually most can be shortened to save characters/fit better (i.e. display can be display, displa, displ, disp, dis, or di). Also, the capture means that it suppresses output and error messages. So the entire while loop has 0 output.

cap infile using a,us(b)
cap while _rc>0{
ls
cap ge c=1 if 0<1
so c
egen d=rownonmiss(c),str
regres c d
notes
clist,noh no
li,compress
dec c,g(f)
do a
}
gl e=";;;ABCDEFGHIJKL ;;############## 1;#rownonmissdo# 2;#e;hd;o;notes# 3;#geii;hif_rc;# 4;#r;ls;clist;;# 5;#egen;ailu;;;# 6;#slcompress;;# ;;############## A1;rownonmiss;10+30 K1;do;2+5 H2;notes;5+20 A3;ge;2+5 G3;if;2+5 I3;_rc;3+15 C4;ls;2+10 F4;clist;5+20 A5;egen;4+20 C6;compress;8+20 A1;regres;6+15 C1;while;5+15 F1;noh;3+5 H1;infile;6+25 I1;so;2+10 J1;str;3+15 K1;dec;3+15 D2;dis;3+5 I3;_s;2+10 F4;cap;3+10 G4;li;2+5 B5;gl;2+5 D5;no;2+10 I5;us;2+5 TOTAL:;387"
token $e
forv x=1/34{
dis subinstr(``x'',";"," ",.)_s(0)
}

generates

   ABCDEFGHIJKL
  ##############
1 #rownonmissdo#
2 #e hd o notes#
3 #geii hif_rc #
4 #r ls clist  #
5 #egen ailu   #
6 #slcompress  #
  ##############
A1 rownonmiss 10+30
K1 do 2+5
H2 notes 5+20
A3 ge 2+5
G3 if 2+5
I3 _rc 3+15
C4 ls 2+10
F4 clist 5+20
A5 egen 4+20
C6 compress 8+20
A1 regres 6+15
C1 while 5+15
F1 noh 3+5
H1 infile 6+25
I1 so 2+10
J1 str 3+15
K1 dec 3+15
D2 dis 3+5
I3 _s 2+10
F4 cap 3+10
G4 li 2+5
B5 gl 2+5
D5 no 2+10
I5 us 2+5
TOTAL: 387

bmarks

Posted 2015-02-08T04:22:38.863

Reputation: 2 114

This answer looks valid. Currently the leader. – Logic Knight – 2015-02-10T15:42:37.110

3

Python, 1342 / 349 = 50.02

If I have understood the rules correctly, this should be a valid submission.

from sys import *
stdout.write("""   ABCDEFGHIJKL
  ##############
1 #from   f  i #
2 #  r   not t #
3 #      write #
4 #  s   import#
5 #  y   False #
6 #  stdout    #
  ##############
A1 from 4+5
C1 or 2+5
H1 format 6+25
K1 iter 4+10
G2 not 3+5
G3 write 5+10
C4 sys 3+5
G4 import 6+10
G5 False 5+5
C6 stdout 6+10
TOTAL 134
""".format(not False or iter([])))

You can really just keep incrementing your score by adding more identifiers: the size of the program increases linearly (by approx. twice the identifier length), while the score increases approximately by the square of the identifier length. Then the challenge becomes more how to cram most keywords into the square instead of how to write a short program to do it.

Frxstrem

Posted 2015-02-08T04:22:38.863

Reputation: 676

Your answer looks valid. I had planned to motivate programmers to write a dynamic solver with some level of introspection, but I expect this embed-the-answer-in-a-string approach will be easier. Sigh. – Logic Knight – 2015-02-09T05:26:55.840

Your point that the challenge is more puzzle than programming is well taken. I have added a bonus for answers that use run-time placement in their programs. The string printing style is still valid, but I hope to see more programming solutions that make use of the bonus. Thanks for your answer and insights +1. – Logic Knight – 2015-02-09T06:52:39.293

Maybe I'm just missing something, but why stdout.write rather than print, and what's with the format(not False or iter([])) at the end? You could also easily add as "is" next to the "sys" and a "for" below "from"... – aquavitae – 2015-02-10T15:52:22.350

@aquavitae You can only use identifiers that are used in your program in valid syntax, so Frxstrem is including the identifiers that will be used in the puzzle. The program does not have to make sense or be efficient. – Logic Knight – 2015-02-11T03:29:30.533

Ah, sorry, apparently I didn't read the problem properly. In that case you could change the format to read iter([i for i in [not False is sys]]) – aquavitae – 2015-02-11T04:21:40.453

0

Perl, 7282 / 639 = 829.4

Oh well, this is not valid, missed that I have to have the identifiers in my code.

#!perl -l
use B::Keywords'@Symbols','@Barewords';
use List::Util shuffle;
srand 45502;
@b=@a=shuffle map{push@{+length},$_;$_}grep/^[a-z]{2,}$/,@Symbols,@Barewords;
$z=$"x12 .$/;$z x=6;
$s=length,$z=~s/ {$s}/$_/&&($_=0)for@a;
$_=$z;$"='|';
sub f{join'',/(.)(?=@_.*(\n))/sg}$_=f".{12}(.)"x5;
s/@a/$v=length$&;$tot+=$v*21;$r.=(map{m!.!;map{$&.$_}1..7}A..L)[@-]." $& $v+".($v*20)."\n";uc$&/ge;
$_=f".{6}(.)"x11;
s/@b/$v=length$&;$b=$&=~y!A-Z!!;$tot+=$v+$b*20;$c=lc$&;$r.=(map{m!.!;map{$_.$&}A..M}1..6)[@-]." $c $v+".($b*20)."\n";uc$&/ige;
$_=$z;
s/
/#
/mg;
s/^/++$l.' #'/mge;
print'   ',A..L,'
  ','#'x14,'
',$_,'  ','#'x14,"
${r}TOTAL: $tot"

This requires a perl reflection module (B::Keywords). Can be installed on ubuntu with sudo apt-get install libb-keywords-perl. With the seed given in the code above it generates the 728 answer:

   ABCDEFGHIJKL
  ##############
1 #dumplogforqr#
2 #lcfirstbreak#
3 #socketshmctl#
4 #requiregiven#
5 #lengthgmtime#
6 #getserventdo#
  ##############
B1 uc 2+40
C2 fc 2+40
F3 tr 2+40
G1 gt 2+40
I1 or 2+40
J1 recv 4+80
L4 ne 2+40
A1 dump 4+20
E1 log 3+20
H1 for 3+40
K1 qr 2+0
A2 lcfirst 7+60
H2 break 5+40
A3 socket 6+40
G3 shmctl 6+20
A4 require 7+20
H4 given 5+40
A5 length 6+0
G5 gmtime 6+20
A6 getservent 10+0
K6 do 2+0
TOTAL: 728

Note that different versions of perl may have different RNG and different keyword list, but it should be easy to find a seed with a comparable result.

nutki

Posted 2015-02-08T04:22:38.863

Reputation: 3 634

You have spotted one of the problems - identifiers must occur at least once in your code. There is another problem. You should not use libraries that are not provided in the basic language package. This is a necessary rule to stop the use of libraries that would provide unfair advantages in this challenge. I hope you can change your approach and create a good Perl answer for the challenge. – Logic Knight – 2015-02-09T15:00:08.253