GolfScript Examples

These examples will not be of much use for learning the language, check out the tutorial and built-ins for simpler examples.

All examples have their input included after first popping the actual input.

More coming soon, maybe.

Hello, world!

Print "Hello, world!"
'Hello, world!'
 -> 82


gcd

Same program as that in the picture
;'2706 410'
~{.@\%.}do;
 -> 82


Grid Computing

As seen at codegolf.com. 21 byte solution.
;'01 34 46 31 55 21 16 88 87 87
32 40 82 40 43 96 08 82 41 86
30 16 24 18 04 54 65 96 38 48
32 00 99 90 24 75 89 41 04 01
11 80 31 83 08 93 37 96 27 64
09 81 28 41 48 23 68 55 86 72
64 61 14 55 33 39 40 18 57 59
49 34 50 81 85 12 22 54 80 76
18 45 50 26 81 95 25 14 46 75
22 52 37 50 37 40 16 71 52 17'
~]10/.zip+{{+}*}%$-1=
 -> 615


1000 digits of pi

29 bytes.
;''
6666,-2%{2+.2/@*\/10.3??2*+}*
`50<~\; #truncate for webpage purposes
 -> 31415926535897932384626433832795028841971693993751


Sudoku solver

Prints all possible solutions, exits with an error, but works. 77 bytes, but lots of room for improvement. See Mark Byers' sudoku page (down now but might be back up later).
;'2 8 4 3 7 5 1 6 9
0 0 9 2 0 0 0 0 7
0 0 1 0 0 4 0 0 2
0 5 0 0 0 0 8 0 0
0 0 8 0 0 0 9 0 0
0 0 6 0 0 0 0 4 0
9 0 0 1 0 0 5 0 0
8 0 0 0 0 7 6 0 4
4 2 5 6 8 9 7 3 1'
{9/[n]*puts}:p; #optional formatting

~]{:@0?:^~!{@p}*10,@9/^9/=-@^9%>9%-@3/^9%3/>3%3/^27/={+}*-{@^<\+@1^+>+}/1}do -> 284375169\ 639218457\ 571964382\ 152496873\ 348752916\ 796831245\ 967143528\ 813527694\ 425689731