Questions tagged [golfscript]

GolfScript is a stack oriented esoteric programming language aimed at solving problems in as few keystrokes as possible.

GolfScript is a stack oriented esoteric programming language aimed at solving problems (holes) in as few keystrokes as possible. It also aims to be simple and easy to write.

Short code is achieved by using single symbols to represent high level operations (such as map, join, array size, etc). Being stack based allows for functions and other manipulations to work without the need for explicit variables, however variables still exist and are useful for more complicated stack manipulations.

A syntax description, Tutorial and Examples are available at golfscript.com

There are interpreters for GolfScript:

14 questions
3
votes
1 answer

How do i find the index of a string in Golfscript?

Given a string "ABCDE", how do i find the index of occurrence of another string "C" in Golfscript? ? operator doesn't seem to work (http://www.golfscript.com/golfscript/builtin.html#?): "C" "ABCDE" ?
Sathish
  • 20,660
  • 24
  • 63
  • 71
3
votes
1 answer

How does this GolfScript code print 1000 digits of pi?

How does this code work? ;'' 6666,-2%{2+.2/@*\/10.3??2*+}* `1000<~\; It seem to use an array @* and a cycle {/**/}, but what is 6666? what is \/?
Stepan
  • 1,391
  • 18
  • 40
3
votes
1 answer

Why do Golfscript examples use pop-and-discard at the start?

;'2706 410' ~{.@\%.}do; From the GCD example. It looks like the pop and discard at the start will do nothing, so why is it there?
user181351
2
votes
1 answer

Error in nested while loop for golfscript

Are nested while loops broken in golfscript or do I not know how to use them? I want to iterate Q from 5 to 0, and for each iteration, iterate Z from 10 to 0. The single loops work well separately, and they seem self-contained (not relying on the…
2
votes
1 answer

How to pass arguments to a golfscript program from command line

I'd like to know how to pass arguments to a golfscript program from the command line. I'm using ruby interpreter that I downloaded from golfscript.com. From what I understood from googling a bit, in ruby you pass arguments like this ruby…
tohanov
  • 36
  • 2
2
votes
1 answer

read in a file containing numbers and do squaring before print out on one line

I am learning golfscript, and I want to read in a file containing numbers and do squaring before print out on one line. For example, I have a file like the following 1 2 3 4 Then I need to print out 1 4 9 16 How can I do this?
Beatle
  • 43
  • 2
2
votes
1 answer

There is nothing innately slow about GolfScript. (...) Analysis could be done to remove most if not all stack use. Explain?

From http://www.golfscript.com/golfscript/syntax.html , Ruby is slow to start with so GolfScript is even slower. There is nothing innately slow about GolfScript. Except for the string evaluate method, everything could be statically compiled…
1
vote
1 answer

I can't understand this comparing code in Golfscript

I saw ~.2$<@@if this code being called comparing code. It does work, but I know @ means Rotates the top 3 elements of the stack so that the 3rd down is now on top. and I can't understand how it works. Can anyone please explain what @ is in this…
dbld
  • 998
  • 1
  • 7
  • 17
1
vote
2 answers

How do you add a single backslash to a string in Golfscript?

I'm having a bit of an issue trying to do an ascii art challenge in GS, since it requires you finishing a line with the \ symbol. The problem is that "\"p breaks the program since it thinks you escaped a quote, and "\\"p prints two backslashes. I've…
Mathgeek
  • 174
  • 1
  • 6
1
vote
1 answer

golfscript nested while loops

Are nested while loops broken in golfscript or do I not know how to use them? I want to iterate Q from 5 to 0, and for each iteration, iterate Z from 10 to 0. The single loops work well separately, and they seem self-contained (not relying on the…
Claudiu
  • 224,032
  • 165
  • 485
  • 680
1
vote
1 answer

ways to read a text file in golfscript and print out its content

'#{File.read("file")}' puts Does not work. Is it possible to read in the content of a text file in GolfScript?
Beatle
  • 43
  • 2
0
votes
0 answers

Why does the stack view depend entirely on the variable "n" to be rendered?

One in golscript can view the stack easily by pressing enter in the shell. But there is a default variable that changing it to a value that does not contain "\n" removes this behavior. Why is this happening? Example of the behavior: > 1 [1] > 2 3…
Daniel Briceño
  • 116
  • 1
  • 3
0
votes
1 answer

how to replace characters or remove them in golfscript efficiently

If I have a character list already, how can I remove certain character, or replace all occurrences of such character with another character?
Beatle
  • 43
  • 2
-1
votes
1 answer

Trailing `1` in GolfScript factorial code

I'm trying out the first GolfScript code from here: 4{:n;1:c;{n 1>}{n c*:c;n 1-:n;}while c}:f;f This outputs 241, which has a redudant 1 at the end. I can't even remove this using ; at the end of the code. Is this a bug?
Jay Lee
  • 1,684
  • 1
  • 15
  • 27