golf.ps

27 views
Skip to first unread message

luser- -droog

unread,
Nov 6, 2011, 3:03:43 PM11/6/11
to
<<0[[0 1 9{}for]{ %numbers is numbers
scale %letters is commands
moveto
lineto
closepath
fill
showpage
}]{{1 index 1 add}forall}forall pop
/*{{(36#?)dup 3 4 3 roll put token pop exch pop load exec}forall}
>>begin
72 72(a11b12c22c21cdef)*

Ross Presser

unread,
Nov 7, 2011, 2:10:57 PM11/7/11
to
A strange way to draw a black square.

Eli the Bearded

unread,
Nov 7, 2011, 8:27:19 PM11/7/11
to
In comp.lang.postscript, luser- -droog <mij...@yahoo.com> wrote:
> <<0[[0 1 9{}for]{ %numbers is numbers
...

I get "Error: /undefined in *"

Elijah
------
Ghostview 1.5 / GPL Ghostscript 8.64

luser- -droog

unread,
Nov 8, 2011, 1:41:16 AM11/8/11
to
On Nov 7, 7:27 pm, Eli the Bearded <*...@eli.users.panix.com> wrote:
> In comp.lang.postscript, luser- -droog  <mijo...@yahoo.com> wrote:> <<0[[0 1 9{}for]{ %numbers is numbers
>
> ...
>
> I get "Error: /undefined in *"
>
> Elijah
> ------
> Ghostview 1.5 / GPL Ghostscript 8.64

Well, that's disappointing. It *ought* to work.
I'm at a loss to guess what might have gone wrong.
It doesn't *have* to be star. Do other punctuation
symbols cause you trouble as names?

luser- -droog

unread,
Nov 8, 2011, 4:34:55 AM11/8/11
to

Eli the Bearded

unread,
Nov 8, 2011, 7:34:25 PM11/8/11
to
In comp.lang.postscript, luser- -droog <mij...@yahoo.com> wrote:
> Well, that's disappointing. It *ought* to work.
> I'm at a loss to guess what might have gone wrong.
> It doesn't *have* to be star. Do other punctuation
> symbols cause you trouble as names?

Yes. I tried _ . ^ & and even g

Elijah
------
didn't try anything fancy like control or highbit

luser- -droog

unread,
Nov 8, 2011, 8:16:12 PM11/8/11
to
On Nov 8, 6:34 pm, Eli the Bearded <*...@eli.users.panix.com> wrote:
> In comp.lang.postscript, luser- -droog  <mijo...@yahoo.com> wrote:
>
> > Well, that's disappointing. It *ought* to work.
> > I'm at a loss to guess what might have gone wrong.
> > It doesn't *have* to be star. Do other punctuation
> > symbols cause you trouble as names?
>
> Yes. I tried _ . ^ & and even g
>
> Elijah
> ------
> didn't try anything fancy like control or highbit

If you post a dump of the dictionary, it might give us more
information.
currentdict {exch == ==} forall

luser- -droog

unread,
Nov 10, 2011, 4:16:12 PM11/10/11
to
On Nov 8, 3:34 am, luser- -droog <mijo...@yahoo.com> wrote:

> The "grown-up" version is here:http://codegolf.stackexchange.com/questions/1197/

I seem to have hit a dead end with this, but I think I've got some
interesting failures.

I started by trying to stuff more logic into the interpreter itself,
by rewriting the prototype to create and use a derived font.


/q{0 0 moveto 1 0 lineto 1 1 lineto 0 1 lineto closepath}def
/X<</FontType 3/FontBBox[0 0 1 1]/FontMatrix[1 0 0 1 0 0]
/Encoding StandardEncoding
/BuildChar{
1 0 0 0 1 1 setcachedevice
.001 setlinewidth
q stroke
dup 35 eq { pop
q fill
}{
.3 .1 moveto
.1 .1 scale
/Times-Roman 8 selectfont
(?)dup 0 4 3 roll put show
}ifelse pop}
>>definefont pop /X 30 selectfont
40 700 moveto {
currentfile 2{dup token pop exch}repeat pop pop
{
currentfile =string readline{
dup length 0 ne{
show currentpoint exch pop 30 sub 40 exch moveto
}{clear exit}ifelse
}{clear exit}ifelse
}loop
/Times-Roman 8 selectfont
{
40 700 moveto
currentfile =string readline{
dup 0 get 35 ne{
cvx exec
1 sub 30 mul 2 add exch
1 sub -30 mul 22 add rmoveto
( )cvs show
}{clear}ifelse
}{clear exit}ifelse
}loop showpage
}exec


Then I created a "Lexicon", an array of all the needed tokens
packed as tightly as I could manage while still assigning ascii
codes with *some* mnemonic value (I tried it without attention
to mnemonics and it was a real mess). And encoded each line
as a string.


<<32{
%! " # $ % &
{/X<</FontType/FontBBox/FontMatrix/Encoding
% ' ( ) *
StandardEncoding/BuildChar/Times-Roman>>
% + , -. / 0 1 2 3 4
-30(--N5-P55P-5P{)0(\)=K).001(DEN).1(ikm).3(!"#9$F--55z%F5--5--
z)
% 56 78 9: ;< => ? @ A B C D E
1(&')2()3()4()8()30()32()35 40 700
% FG H I J K
[setcachedevice()setlinewidth definefont selectfont
% L M N O P Q R S T U V W
scale()moveto()lineto()rmoveto()stroke fill show currentpoint
% X Y Z [ \ ] ^ _ ` a b c d e f g h
dup()eq()ne()exch()pop()roll()put()get ifelse length
% i j k l m n o
currentfile()=string()readline token repeat
% p q r s t u v w x y
z{ | } ~
cvs cvx exec clear exit sub mul add showpage forall]closepath
22
}pop %lexicon
%/X<</FontType 3/FontBBox[0 0 1 1]/FontMatrix[1 0 0 1 0 0]
(4)*
%/Encoding StandardEncoding
(6)*
%/BuildChar{
(\()*{
%1 0 0 0 1 1 setcachedevice %.001 setlinewidth %q stroke
(5---55G)* (/I)* (,T)*
%dup 35 eq { pop
(XCZ)*{(`)*
%q fill
(,U)*
}{
%.3 .1 moveto
(31N)*
%.1 .1 scale
(11L)*
%/Times-Roman 8 selectfont
%(\)=K)*
(.)*
(?) %dup 0 4 3 roll put show
(X-;9bdV)*
%}ifelse pop}
}(g`)*}
%>>definefont pop /X 30 selectfont
(*J`!?K)*
%40 700 moveto
%(DEN)*
(0)*
%currentfile 2{dup token pop exch}repeat pop pop
(i7)*{(Xn`^)*}(o``)*
{
%currentfile =string readline{
%(ikm)*{
(2)*{
%dup length 0 ne{
(Xh-\\)*{
%show currentpoint exch pop 30 sub 40 exch moveto
(VW^`?uD^N)*
%}{clear exit}ifelse
}
%{(s)* exit}ifelse
{c x}i
%}{clear exit}ifelse
}
%{(s)* exit}ifelse
{c x}i
}loop
%/Times-Roman 8 selectfont
(.)*
{
%40 700 moveto
(0)*
%currentfile =string readline{
(2)*{
%dup 0 get 35 ne{
(X-fC\\)*{
%cvx exec
(qr)*
%1 sub 30 mul 2 add exch
(5u?v7w^)*
%1 sub -30 mul 22 add rmoveto
(5u+v|wR)*
( )%cvs show
(pV)*
}{c}i
}{c x}i
}l(x)*
}1 index 1 add 1 index 0 get{dup type /stringtype eq{[exch/* cvx]cvx}
if 1 index 1 add}forall pop
%/q{0 0 moveto 1 0 lineto 1 1 lineto 0 1 lineto closepath}
%/q{(--N5-P55P-5P{)*}
/*{{load exec}forall}
/c{clear}/i{ifelse}/x{exit}/l{loop}
pstack
>> dup{exch dup type /integertype eq{( )dup 0 4 3 roll put print }{=}ifelse ==}forall
begin( )*


But it seems the overhead of constructing/decoding plus the massive
increase of distinct tokens means this packs up even larger than
my first version with no special trickery! This one's 911 chars,
the early one was 905.

But I think these techniques could be useful if the program itself
had more to do. Compression *ought* to make things smaller under
the right circumstances.


Appendix. Here's the data file for running these. Just append it to
the program and ghostscript will show you the NYT Crossword No. 1105.

15 15
# #


# ##
## # #
# #
# #
#
# #
# #
K# # ##
## I #
L
N
S# #

#i m n figure(number), row, col
1 1 1
2 1 2
3 1 3
4 1 4
5 1 5
6 1 7
7 1 8
8 1 9
9 1 11
10 1 12
11 1 13
12 1 14
13 1 15
14 2 1
15 2 6
16 2 10
17 3 1
18 4 1
19 4 9
20 5 3
21 5 7
22 5 8
23 5 11
24 5 14
25 5 15
26 6 1
27 6 2
28 6 6
29 6 10
30 6 12
31 7 1
32 7 5
33 7 10
34 7 11
35 8 1
36 8 4
37 8 9
38 9 1
39 9 8
40 9 13
41 10 1
42 10 6
43 10 7
44 10 12
45 11 1
46 11 5
47 11 7
48 11 11
49 12 3
50 12 6
51 12 9
52 12 10
53 12 14
54 12 15
55 13 1
56 13 2
57 13 8
58 14 1
59 15 1
60 15 7
60 15 11

Eli the Bearded

unread,
Nov 10, 2011, 8:27:14 PM11/10/11
to
In comp.lang.postscript, luser- -droog <mij...@yahoo.com> wrote:
> If you post a dump of the dictionary, it might give us more
> information.
> currentdict {exch == ==} forall

Just that? Not that in the golf.ps file?

/.localcsdefaults
false
/a8
{148 210 {/statusdict --.systemvar-- --begin-- .setpagesize --end--} --exec--}
/isob4
{709 1001 {/statusdict --.systemvar-- --begin-- .setpagesize --end--} --exec--}
/jisb5
{516 729 {/statusdict --.systemvar-- --begin-- .setpagesize --end--} --exec--}
/archC
{1296 1728 {/statusdict --.systemvar-- --begin-- .setpagesize --end--} --exec--}

Elijah
------
hasn't had time to check back here

luser- -droog

unread,
Nov 11, 2011, 12:03:56 AM11/11/11
to
On Nov 10, 7:27 pm, Eli the Bearded <*...@eli.users.panix.com> wrote:
> In comp.lang.postscript, luser- -droog  <mijo...@yahoo.com> wrote:
>
> > If you post a dump of the dictionary, it might give us more
> > information.
> >     currentdict {exch == ==} forall
>
> Just that? Not that in the golf.ps file?
>

Oh, no. *In* the golf.ps file, just after 'begin'.
I don't really have high hopes of figuring this out remotely,
but seeing what's actually in the dictionary would be the
first step.

My only guess at the moment is that somehow a space character
crept in between the slash and the star, and that it's the
first star that's being executed. If so, then adding the
dictionary dump will trigger the same undefined error as
before. Otherwise, at least we can see what *is* in there.

Eli the Bearded

unread,
Nov 11, 2011, 7:50:26 PM11/11/11
to
In comp.lang.postscript, luser- -droog <mij...@yahoo.com> wrote:
> Oh, no. *In* the golf.ps file, just after 'begin'.

%!
currentdict {exch == ==} forall

<<0[[0 1 9{}for]{ %numbers is numbers
scale %letters is commands
moveto
lineto
closepath
fill
showpage
}]{{1 index 1 add}forall}forall pop
/&{{(36#?)dup 3 4 3 roll put token pop exch pop load exec}forall}
72 72(a11b12c22c21cdef)&

> I don't really have high hopes of figuring this out remotely,
> but seeing what's actually in the dictionary would be the
> first step.

The text box for the alert doesn't offer a scroll bar, so it had a
lot of text I didn't see before. I think I copied it all this time.

/a4small
{595 842 {/statusdict --.systemvar-- --begin-- .setpagesize --end--} --exec--}
/a7
{210 297 {/statusdict --.systemvar-- --begin-- .setpagesize --end--} --exec--}
/b3
{1001 1417 {/statusdict --.systemvar-- --begin-- .setpagesize --end--} --exec--}
/jisb4
{729 1032 {/statusdict --.systemvar-- --begin-- .setpagesize --end--} --exec--}
/archD
{1728 2592 {/statusdict --.systemvar-- --begin-- .setpagesize --end--} --exec--}
/a4
{595 842 {/statusdict --.systemvar-- --begin-- .setpagesize --end--} --exec--}
/a6
{297 420 {/statusdict --.systemvar-- --begin-- .setpagesize --end--} --exec--}
/isob3
{1001 1417 {/statusdict --.systemvar-- --begin-- .setpagesize --end--} --exec--}
/jisb3
{1032 1460 {/statusdict --.systemvar-- --begin-- .setpagesize --end--} --exec--}
/archE
{2592 3456 {/statusdict --.systemvar-- --begin-- .setpagesize --end--} --exec--}
/defaultfontname
/Times-Roman
/a3
{842 1191 {/statusdict --.systemvar-- --begin-- .setpagesize --end--} --exec--}
/a5
{420 595 {/statusdict --.systemvar-- --begin-- .setpagesize --end--} --exec--}
/b2
{1417 2004 {/statusdict --.systemvar-- --begin-- .setpagesize --end--} --exec--}
/jisb2
{1460 2064 {/statusdict --.systemvar-- --begin-- .setpagesize --end--} --exec--}
/c6
{323 459 {/statusdict --.systemvar-- --begin-- .setpagesize --end--} --exec--}
/=string
(x255Unicode\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\00
0\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000...)
/Fontmap
-dict-
/11x17
{792 1224 {/statusdict --.systemvar-- --begin-- .setpagesize --end--} --exec--}
/img_utils_dict
-dict-
/a2
{1191 1684 {/statusdict --.systemvar-- --begin-- .setpagesize --end--} --exec--}
/isob2
{1417 2004 {/statusdict --.systemvar-- --begin-- .setpagesize --end--} --exec--}
/.currentresourcefile
null
/.runstdin
{{(%stdin) --run--} execute0}
/jisb1
{2064 2920 {/statusdict --.systemvar-- --begin-- .setpagesize --end--} --exec--}
/localdicts
-dict-
/c5
{459 649 {/statusdict --.systemvar-- --begin-- .setpagesize --end--} --exec--}
/AGM_preserve_spots
false
/help
{(Enter PostScript commands. '\(filename\) run' runs a file, 'quit' exits.\n) --print-- --flush--}
/a1
{1684 2384 {/statusdict --.systemvar-- --begin-- .setpagesize --end--} --exec--}
/b1
{2004 2835 {/statusdict --.systemvar-- --begin-- .setpagesize --end--} --exec--}
/jisb0
{2920 4127 {/statusdict --.systemvar-- --begin-- .setpagesize --end--} --exec--}
/c4
{649 918 {/statusdict --.systemvar-- --begin-- .setpagesize --end--} --exec--}
/pa4
{595 792 {/statusdict --.systemvar-- --begin-- .setpagesize --end--} --exec--}
/a0
{2384 3370 {/statusdict --.systemvar-- --begin-- .setpagesize --end--} --exec--}
/isob1
{2004 2835 {/statusdict --.systemvar-- --begin-- .setpagesize --end--} --exec--}
/b6
{354 499 {/statusdict --.systemvar-- --begin-- .setpagesize --end--} --exec--}
/c3
{918 1298 {/statusdict --.systemvar-- --begin-- .setpagesize --end--} --exec--}
/halfletter
{396 612 {/statusdict --.systemvar-- --begin-- .setpagesize --end--} --exec--}
/note
{612 792 {/statusdict --.systemvar-- --begin-- .setpagesize --end--} --exec--}
/.pdfcvstring
()
/b0
{2835 4008 {/statusdict --.systemvar-- --begin-- .setpagesize --end--} --exec--}
/isob6
{354 499 {/statusdict --.systemvar-- --begin-- .setpagesize --end--} --exec--}
/c2
{1298 1837 {/statusdict --.systemvar-- --begin-- .setpagesize --end--} --exec--}
/flse
{612 936 {/statusdict --.systemvar-- --begin-- .setpagesize --end--} --exec--}
/lettersmall
{612 792 {/statusdict --.systemvar-- --begin-- .setpagesize --end--} --exec--}
/isob0
{2835 4008 {/statusdict --.systemvar-- --begin-- .setpagesize --end--} --exec--}
/b5
{499 709 {/statusdict --.systemvar-- --begin-- .setpagesize --end--} --exec--}
/c1
{1837 2599 {/statusdict --.systemvar-- --begin-- .setpagesize --end--} --exec--}
/flsa
{612 936 {/statusdict --.systemvar-- --begin-- .setpagesize --end--} --exec--}
/letter
{612 792 {/statusdict --.systemvar-- --begin-- .setpagesize --end--} --exec--}
/a10
{73 105 {/statusdict --.systemvar-- --begin-- .setpagesize --end--} --exec--}
/.echo.mode
true
/isob5
{499 709 {/statusdict --.systemvar-- --begin-- .setpagesize --end--} --exec--}
/GS_PDF_ProcSet
-dict-
/c0
{2599 3677 {/statusdict --.systemvar-- --begin-- .setpagesize --end--} --exec--}
/archA
{648 864 {/statusdict --.systemvar-- --begin-- .setpagesize --end--} --exec--}
/legal
{612 1008 {/statusdict --.systemvar-- --begin-- .setpagesize --end--} --exec--}
/a9
{105 148 {/statusdict --.systemvar-- --begin-- .setpagesize --end--} --exec--}
/b4
{709 1001 {/statusdict --.systemvar-- --begin-- .setpagesize --end--} --exec--}
/jisb6
{363 516 {/statusdict --.systemvar-- --begin-- .setpagesize --end--} --exec--}
/archB
{864 1296 {/statusdict --.systemvar-- --begin-- .setpagesize --end--} --exec--}
/ledger
{1224 792 {/statusdict --.systemvar-- --begin-- .setpagesize --end--} --exec--}
/#copies
1
/.localcsdefaults
false
/a8
{148 210 {/statusdict --.systemvar-- --begin-- .setpagesize --end--} --exec--}
/isob4
{709 1001 {/statusdict --.systemvar-- --begin-- .setpagesize --end--} --exec--}
/jisb5
{516 729 {/statusdict --.systemvar-- --begin-- .setpagesize --end--} --exec--}
/archC
{1296 1728 {/statusdict --.systemvar-- --begin-- .setpagesize --end--} --exec--}

> first star that's being executed. If so, then adding the
> dictionary dump will trigger the same undefined error as
> before. Otherwise, at least we can see what *is* in there.

Well, there it is.

Elijah
------
in over his head here

luser- -droog

unread,
Nov 11, 2011, 8:46:11 PM11/11/11
to
On Nov 11, 6:50 pm, Eli the Bearded <*...@eli.users.panix.com> wrote:
> In comp.lang.postscript, luser- -droog  <mijo...@yahoo.com> wrote:
>
> > Oh, no. *In* the golf.ps file, just after 'begin'.
>
> %!
> currentdict {exch == ==} forall
>
> <<0[[0 1 9{}for]{ %numbers is numbers
>     scale %letters is commands
>     moveto
>     lineto
>     closepath
>     fill
>     showpage}]{{1 index 1 add}forall}forall pop
>
> /&{{(36#?)dup 3 4 3 roll put token pop exch pop load exec}forall}

>>begin %<---You lost a line here! This creates and pushes the dict.

> 72 72(a11b12c22c21cdef)&
>
> > I don't really have high hopes of figuring this out remotely,
> > but seeing what's actually in the dictionary would be the
> > first step.
>
> The text box for the alert doesn't offer a scroll bar, so it had a
> lot of text I didn't see before. I think I copied it all this time.
>
> /a4small
> {595 842 {/statusdict --.systemvar-- --begin-- .setpagesize --end--} --exec--}
> [...]

This is just the contents of userdict.
Not what we needed, but no harm done.

> > first star that's being executed. If so, then adding the
> > dictionary dump will trigger the same undefined error as
> > before. Otherwise, at least we can see what *is* in there.
>
> Well, there it is.

I think it's enough.
It looks like it was *my* blunder to put >> at the beginning
of a line. Your newsreader must have done something to it.

Eli the Bearded

unread,
Nov 11, 2011, 10:21:52 PM11/11/11
to
In comp.lang.postscript, luser- -droog <mij...@yahoo.com> wrote:
> It looks like it was *my* blunder to put >> at the beginning
> of a line. Your newsreader must have done something to it.

Oh, yes, my newreader does hide lines like that unless I tell it
to be verbose. I didn't even consider trying that. :^(

Elijah
------
double quoted is normally ignorable, and ^>> is normally double quoted
Reply all
Reply to author
Forward
0 new messages