Tips for either golfing or programming challenges. In most current cases it is for helpful tips and tricks how one could golf more effectively with a particular language.

learn more… | top users | synonyms (1)

1
vote
1answer
90 views

Shortest Code to Translate a PHP array

NOTE: This question was migrated from http://stackoverflow.com/q/27134588/1442685 PHP QUESTION Almost purely out of curiousity, how can I take an array like this: array( 'fruit' => 'banana', ...
6
votes
0answers
42 views

Tips for Golfing in Go

What general tips do you have for golfing in Go? I'm new to Code Golfing and looking for ideas that can be applied to code golf problems in general that are at least somewhat specific to Go. Idea ...
5
votes
3answers
248 views

Looking for shorter alternatives to `range(…)`

The best solution I've found so far for a golf code puzzle I'm working on includes two rather fat-looking invocations of range. I'm very new at code golf, especially in Python, so I could use a few ...
11
votes
1answer
152 views

Python advice: Portability of introspective function call

In Python, you can use the dir function on any object to get a list of the names of its instance functions: >>> dir('abc') ['__add__', '__class__', '__contains__', '__delattr__', '__doc__', ...
0
votes
3answers
152 views

JavaScript: Tricks to shorten onkeydown, setInterval etc

Are there any tricks to shorten defined function names like setInterval, onkeydown, onkeyup, createLinearGradient or even return? When using it more than once it's nice to put it as a string into a ...
12
votes
6answers
2k views

Tips for golfing in Pyth

Pyth is a Python-inspired procedural programming language, created by PPCG user isaacg. What general tips do you have for golfing in Pyth? I'm looking for ideas that can be applied to code golf ...
1
vote
4answers
109 views

Tips for Golfing in BBC BASIC

What general tips do you have for golfing in BBC BASIC? I'm looking for ideas that can be applied to code golf problems in general that are at least somewhat specific to BBC BASIC (e.g. "remove ...
4
votes
1answer
263 views

Javascript: Mini Space Invaders

I'm pretty new to code golfing, so I gave one of my first shots to a space invader clone called "Invas!on". It's a little less than 500 bytes, fully ASCII generated, and covers moving around and ...
4
votes
0answers
130 views

How to golf string output in Chef

I'm attempting to solve a programming golf style programming puzzle. I need to write an 18 character phrase in Chef in less than 32 "lines" of code. In this case, a line counts as an ingredient or an ...
11
votes
5answers
450 views

Tips for golfing in CJam

CJam is a GolfScript-inspired stack-based golfing language, created by PPCG user aditsu. So, in the vein of other language-specific tips questions: What general tips do you have for golfing in CJam? ...
3
votes
1answer
158 views

multiplication table in javascript [duplicate]

This javascript code: for(x=1;x<6;x++)for(y=1;y<6;y++)console.log((y==1?'\n':'')+x+'*'+y+'='+x*y); prints the following: 1*1=1 1*2=2 1*3=3 1*4=4 1*5=5 2*1=2 2*2=4 2*3=6 2*4=8 2*5=10 3*1=3 ...
8
votes
1answer
188 views

Golfscript Diagonal Array

Is there a way in Golfscript to bring all of the diagonals of an array into a single array? For example, for the array [[1 2 3][4 5 6][7 8 9]] return [[7][4 8][1 5 9][2 6][3]] (not necessarily ...
6
votes
5answers
422 views

Tips for golfing in Applescript

What tips do you have for golfing in Applescript? I'm looking for ideas that can be applied to code golf problems in general that are at least somewhat specific to Applescript (e.g. "remove comments" ...
14
votes
3answers
318 views

Tips for Golfing in ECMAScript 6

This is similar to other "Tips for golfing in <...>" but specifically targeting the ECMAScript 6 features in JavaScript. JavaScript inherently is a very verbose language, function(){}, .forEach(), ...
3
votes
0answers
101 views

Tips for golfing in OCaml

Inspired from the assortment of other 'Tips for golfing in language xyz'. As usual, please only suggest tips that are specific to OCaml and not programming in general. One tip per answer please.
0
votes
0answers
333 views

Is this the shortest possible Java quine? [duplicate]

Long ago, I found a Java quine online which uses a number of very clever tricks of the Java language (you can compile this at the command line, but it will not compile in most compilers--for obvious ...
12
votes
12answers
9k views

Smallest python script to print even numbers 0 to 100

I'm work on a problem which I set myself for fun, which is to create a python script which prints the even numbers from 0 to 100. The challenge is to make the script as small as possible. This is what ...
8
votes
1answer
546 views

Palindromic prime

I'm solving task, where: Input: A number as an integer. Output: The closest greater palindromic prime as an integer. I would appreciate hints how to make my solution shorter. Or directions if ...
6
votes
4answers
840 views

Tips for Golfing in T-SQL?

What general tips do you have for golfing in T-SQL? I'm looking for ideas that can be applied to code golf problems in general that are at least somewhat specific to T-SQL. Please post one tip per ...
2
votes
3answers
769 views

Check If Two or More Variables Are All Equal to Zero in JavaScript

What is the shortest way to check if two or more variables are equal to 0 in JavaScript? I'm curious to know if there's something shorter than if(!x&&!y&&!z){...}.
12
votes
6answers
483 views

Alias Member Functions in Python

In Python, one can save bytes by aliasing functions that are used repeatedly. For example: r=range a=r(100) b=r(200) c=r(300) However, when the functions are member functions together, I don't know ...
5
votes
2answers
197 views

Tips for golfing in Processing

Does anyone have any code-golf tips for golfing in Processing? It is a graphical extension of java, and is somewhat difficult to golf.
2
votes
8answers
258 views

Tips for golfing in LiveScript

What general tips do you have for golfing in LiveScript? I'm looking for ideas that can be applied to code golf problems in general that are at least somewhat specific to LiveScript (e.g. "remove ...
7
votes
0answers
549 views

X greater than 3 with at least 2 difference between X and Y

I am trying to golf down some C++. Is it possible to make this condition shorter? X > 3 & X - Y > 1 (Apart from removing whitespace, of course.) So, X is at least 4 but X >= Y + 2. X ...
6
votes
3answers
304 views

Tips for golfing in Julia

What general tips do you have for golfing in Julia? I'm looking for ideas that can be applied to code golf problems in general that are at least somewhat specific to Julia (e.g. "remove comments" is ...
10
votes
4answers
403 views

Tips for golfing in Lua

What general tips do you have for golfing in Lua? I'm looking for ideas that can be applied to code golf problems in general that are at least somewhat specific to Lua (e.g. "remove comments" is not ...
0
votes
0answers
195 views

Visual Studio settings for C# code golfing

Which setting in Visual Studio do you recommend to get the best experience for code-golf? Advanced: how to best apply these settings only temporarily (because I should also do some work with Visual ...
3
votes
2answers
234 views

Tips for golfing ASCII art

I think the ASCII art questions on Code Golf are fun to do but personally I think it can be pretty hard. Especially when the question is tagged as code-golf. I wonder if anyone here might have some ...
3
votes
2answers
240 views

Tips for Golfing in Batch

Windows Batch (CMD) is probably the least suitable language for code golfing. Avoid newline characters. If you're looking for the shortest code in bytes, as opposed to characters, you will want to ...
4
votes
1answer
179 views

Tips for golfing in Delphi

Codegolfing is incredibly fun to do, trying to solve the given problem is one thing but the real challenge is getting your code as short as possible. Some languages are perfect for golfing because of ...
2
votes
0answers
137 views

Tips for golfing in Io

What general tips do you have for golfing in Io? I'm looking for ideas that can be applied to code golf problems in general that are at least somewhat specific to Io (e.g. "remove comments" is not an ...
19
votes
10answers
778 views

Tips for golfing in Haskell

What general tips do you have for golfing in Haskell? I am looking for ideas that can be applied to code golf problems in general that are at least somewhat specific to Haskell. Please post only one ...
3
votes
2answers
151 views

Tips for golfing in Perl 6

What general tips do you have for golfing in Perl 6? I'm looking for ideas that can be applied to code golf problems in general that are at least somewhat specific to Perl 6 (e.g. "remove comments" is ...
10
votes
1answer
283 views

Tips for golfing in APL

I started one code golf challenge recently and it seems like the winner is GolfScript (surprise, surprise!). What's interesting is that there was another very strong competitor that had all chances to ...
13
votes
23answers
882 views

An improved version of GolfScript

I am planning to write an improved GolfScript for even shorter programs that can do more things. This is not a challenge; it is a request for feedback and tips on what I should do. (see tags) I'm not ...
3
votes
1answer
246 views

Tips for golfing in F#

What general tips do you have for golfing in F#? I'm looking for ideas that can be applied to code golf problems in general that are at least somewhat specific to F# (e.g. "remove comments" is not an ...
3
votes
8answers
199 views

Tips for golfing in Befunge 98

What general tips do you have for golfing in Befunge 98? I'm looking for ideas that can be applied to code golf problems in general that are at least somewhat specific to Befunge 98 (e.g. "remove ...
2
votes
3answers
215 views

Doing shorter comparisons in PowerShell

One of the annoying bits about PowerShell, which helps amplify its disadvantage against other languages in code-golf, is that there are no symbolic comparison or logical operators. A comparison that ...
10
votes
13answers
654 views

Tips for golfing in Bash

What general tips do you have for golfing in Bash? I'm looking for ideas that can be applied to code golf problems in general that are at least somewhat specific to Bash (e.g. "remove comments" is not ...
2
votes
2answers
276 views

Tips for golfing in AWK

What general tips do you have for golfing in AWK? I'm looking for ideas that can be applied to code golf problems in general that are at least somewhat specific to AWK. Please post one tip per answer. ...
4
votes
4answers
189 views

Tips for golfing in VBScript

What general tips do you have for golfing in VBScript? I'm looking for ideas that can be applied to code golf problems in general that are at least somewhat specific to VBScript. Please post one tip ...
4
votes
0answers
139 views

Tips for golfing in Octave

What general tips do you have for golfing in Octave? I'm looking for ideas that can be applied to code golf problems in general that are at least somewhat specific to Octave (e.g. "remove comments" is ...
3
votes
2answers
276 views

Tips for golfing in MATLAB

What general tips do you have for golfing in MATLAB? I'm looking for ideas that can be applied to code golf problems in general that are at least somewhat specific to MATLAB (e.g. "remove comments" is ...
8
votes
2answers
592 views

Tips for golfing in Brainfuck

What general tips do you have for golfing in Brainfuck? I'm looking for ideas that can be applied to code golf problems in general that are at least somewhat specific to Brainfuck (e.g. "remove ...
13
votes
9answers
812 views

Tips for golfing in Mathematica

What general tips do you have for golfing in Mathematica? I'm looking for ideas that can be applied to code golf problems in general that are at least somewhat specific to Mathematica (e.g. "remove ...
4
votes
4answers
289 views

Tips for golfing in Tcl

What general tips do you have for golfing in Tcl? I'm looking for ideas that can be applied to code golf problems in general that are at least somewhat specific to Tcl (e.g. "remove comments" is not ...
2
votes
11answers
1k views

recursive power algorithm

Have a look at my (javascript) version of a O(log(n)) xn algorithm: function pow(x,n) { return n==0?1:n==1?x:n==2?x*x:pow(pow(x,(n-n%2)/2),2)*(n%2==0?1:x); } Can you get it shorter?
1
vote
1answer
214 views

Code Golfing in high school computer science club? [closed]

This is not a code golf challenge. So, at my high school, we're starting a new computer science club, and personally I'd like it to be more than just writing Java stuff (AP Comp Sci curriculum). How ...
11
votes
8answers
460 views

Tips for golfing in Postscript?

As one of the less popular languages, it's difficult to find literature on the avant garde of postscript hackery. So what discoveries have the golfers here made to exploit the stack model (or other ...
5
votes
5answers
458 views

Language idea for golfing purposes

This question is probably not on-topic. If a moderator feels that it should be that way, turn this question into community wiki please. In order to raise the score of (my) code-golf submissions, I ...