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)

4
votes
1answer
329 views

What is the shortest infinite loop statement?

I'm working on a golf for Java and I need an infinite loop. Obviously, I don't want to spend any more bytes than I have to, especially in such an expressive language. Assuming I have some code I want ...
17
votes
0answers
949 views

Tips for providing high-quality answers in popularity contests [migrated]

We have lots of tips for golfing in specific languages, but what about other types of challenge? Has anyone wondered how to improve their popularity-contest answers? What general tips do you have ...
9
votes
1answer
392 views

Shortening a long number

When dealing with long numbers when code golfing, getting the length of your code down can be difficult, so do you have any tips for making a number shorter and easier to manage? For example, the ...
4
votes
0answers
82 views

Tips for golfing in INTERCAL

What general tips do you have for golfing in INTERCAL? I'm looking for ideas which can be applied to code golf challenges and are also at least somewhat specific to INTERCAL (i.e. "remove comments" is ...
5
votes
9answers
145 views

Tips for golfing in CoffeeScript

What tricks do you know to make CoffeeScript code shorter? CoffeeScript is language that compiles into JavaScript ("transpiles" into ES3, to be exact). The golden rule is "It's just JavaScript", ...
5
votes
3answers
322 views

GolfScript, CJam, or Pyth? [duplicate]

Which language usually produces shorter golfed code: Pyth, CJam or Golfscript? In asking this, I do not mean which has a prettier syntax or which has the most useful commands, I mean overall, which ...
7
votes
1answer
195 views

Golfing with User Agents

Usually when performing an internet challenge, there's no problem with having to specify a user agent, but when it comes to dealing with Google, it changes. Google blacklists the Urllib user agent, ...
2
votes
0answers
94 views

Golfing Delayed Expansion Variables in Batch

Enabling delayed expansion variables in Batch chews up a lot of bytes. The shortest I have managed to make it is: @!! 2>nul||cmd/q/v/c%0&&exit/b Saving 11 bytes over @echo ...
13
votes
1answer
415 views

Golfing with Python Import

When is it beneficial to use inline, single use importing in Python? For example: __import__("x").doSomething() Is the above ever shorter than the below? import x x.doSomething() Or from x ...
5
votes
2answers
400 views

Convert a string representation of a number to int[] in C#

What is the shortest C# statement that will convert a string representation of a number to an int[] that contains each digit? string number = "1234"; number.Array.ConvertAll(line.ToCharArray(), c ...
2
votes
1answer
137 views

all non-empty sublists partitionings of a list

I had to write a code for finding all non-empty sublists partitionings of a list: def f(s): if s: for j in range(1,len(s)+1): for p in f(s[j:]): yield ...
11
votes
7answers
419 views

Tips for golfing in TI-BASIC

What general tips do you have for golfing in TI-BASIC for the TI-83/84+ series calculators? I'm looking for ideas which can be applied to code-golf problems and which are also at least somewhat ...
9
votes
7answers
395 views

Tips for golfing in sed

What general tips do you have for golfing in sed? I'm looking for ideas which can be applied to code-golf problems and which are also at least somewhat specific to sed (e.g. "remove comments" is not ...
0
votes
1answer
98 views

Improving a Rubik's Cube scrambler's byte count

Okay, I recently wrote a Javascript Rubik's Cube scrambler that outputs a 25-move scramble. It's 135 bytes. The Gist is here, but for reference, I have the formatted code: function(){ ...
12
votes
3answers
786 views

Is there a shorter way to get user input in python?

This is not a challenge. I'm wondering if it's at all possible to get user input into two separate variables in python (2 or 3) with less than 19 bytes. These are all the shortest I can get: ...
6
votes
2answers
302 views

Generalized integer casting in Python

Background I have a string in Python which I want to convert to an integer. Normally, I would just use int: >>> int("123") 123 Unfortunately, this method is not very robust, as it only ...
2
votes
1answer
192 views

Minimum of a Polynomial in Python

What is the shortest amount of code that can find the minimum of an inputted polynomial? I realize that you can import packages like Numpy and others, but using only user defined functions, what is ...
11
votes
5answers
277 views

Tips for golfing in K

K is a programming language in the APL family designed by Arthur Whitney. While the official interpreter is closed-source and commercial, a trial version with a workspace limit of 32 bits of ...
8
votes
4answers
260 views

Tips for golfing in LOLCODE

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

Tips for golfing in Befunge 93 [duplicate]

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

How can I use cmp(a,b) with Python3?

I want to compare a and b. How can I use cmp(a,b) with Python3 ?
5
votes
4answers
415 views

How could I reduce the length of this code?

I need to reduce the length of this code in Python 3 as much as possible (even if it will be less readable): a,b,x,y=[int(i) for i in input().split()] while 1: r='' if y<b:r='S';y+=1 if ...
9
votes
1answer
412 views

Concatenate lists of strings item-wise in Python

This is a tips question for golfing in python. Suppose you have two lists of strings, and you want to concatenate the corresponding entries from each list. E.g. with a=list("abcd") and ...
-1
votes
1answer
127 views

How can I rename .split or .join in python? [duplicate]

I can rename a built in module like this: r=range list(range(10)) [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] but whenever I rename .split, I get an error: s=split NameError: name 'split' is not defined How ...
5
votes
3answers
602 views

Leibniz golf in C#

I'm starting with golf code. But im only do C# so I know wont be a breaking record, but I want give it a try. Leibniz Challenge is here The first line contains the number of test cases (N) which is ...
5
votes
4answers
130 views

Tips for golfing in Element

Since my use of Element has increased recently, I am interested in tips for golfing programs written in it. What general tips do you have for golfing in Element? I'm looking for ideas that can be ...
13
votes
2answers
312 views

Tips for golfing in The Shakespeare Programming Language

What general tips do you have for golfing in The Shakespeare Programming Language? I'm looking for ideas which can be applied to code-golf problems and which are also at least somewhat specific to SPL ...
6
votes
2answers
232 views

Tips for golfing in whitespace

What general tips do you have for golfing in Whitespace? I'm looking for ideas which can be applied to code-golf problems and which are also at least somewhat specific to Whitespace (e.g. "remove ...
16
votes
3answers
2k views

Is there a shorter way to assign one of two variables in Python?

This is a tips question for golfing in python. In multiple golfs I've done in Python, a fixed value is assigned to one of two variables chosen by a Boolean. The chosen variable is overwritten by the ...
24
votes
14answers
3k views

Tips for Regex Golf

Similar to our threads for language-specific golfing tips: what are general tricks to shorten regular expressions? I can see three uses of regex when it comes to golfing: classic regex golf ("here ...
11
votes
1answer
1k views

Am I code-golfing properly?

I am curious if I am Code Golfing properly. I set the challenge for myself to make a small hashing program into a single statement in Python. I first started off with: from itertools import ...
6
votes
3answers
746 views

Tips for golfing in ><> (Fish)

Since I've been seeing more ><> submissions floating around lately, I thought it might be a good idea to have a tips page. Please stick to one tip per post, unless they are closely related. ...
8
votes
1answer
1k views

Python 3 - Tried Golfing My Assignment

Note: This isn't as much a golfing challenge; it is more so asking for golfing suggestions. Recently I had a Python assignment for my web development class, in order to check whether we could code. ...
1
vote
2answers
229 views

Code Golf: Leibniz Series

This is the same question as Solve the CodeSprint4 Leibniz code golf challenge in Python in 66 characters. The variation is that I'm a C programmer. My code for the above question is: #include ...
5
votes
2answers
346 views

C golfing tips - returning 0 without return statement

I'm looking for some solution in returning values in main function, I need to shorten my program more, return 0 takes too much characters of my code, I need to return 0, or my code fails. I know that ...
-1
votes
1answer
215 views

Books Algorithm Dealing with Square Digit Sums

A little context: Book has 411 Pages Read a random number of pages on the first day which is unknown Number of pages to read next day is the square of the sum of the digits of the page ...
8
votes
5answers
1k views

All primes from 0 to 1000

Is it possible to make this C code smaller? It prints out all primes from 0 to 1000. C, 89 chars int i,p,c;for(i=2;i<1e3;i++){c=0;for(p=2;p<i;p++)if(i%p==0)c++;if(c==0)printf("%u\n",i);}
4
votes
6answers
2k views

Print all odd numbers from 0 to 100000

My teacher gave me a simple problem which I should solve with a code tiny as possible. I should print all odd numbers from 0 to 100000 into a HTML document using javascript. for(var y = 0; y < ...
3
votes
2answers
508 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', ...
9
votes
0answers
154 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 ...
6
votes
3answers
424 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 ...
12
votes
1answer
197 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
4answers
460 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 ...
18
votes
18answers
3k 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
147 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
379 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
175 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 ...
21
votes
22answers
2k 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
510 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 ...
9
votes
1answer
257 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 ...