Stack Exchange Network

Stack Exchange network consists of 174 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

Questions tagged [tips]

For questions asking for tips on a specific piece of code, to make it a better answer to a programming challenge that is on-topic on this site. Tag [tips] questions with other appropriate tags, such as [python][code-golf] or [king-of-the-hill].

0
votes
0answers
28 views

Autocomplete any text field (outside the program form) [on hold]

Don't blame me hard on the issue I have no clue how to solve, I'm new to this area, but I wanna know how one can build an autocomplete program, which would suggest a number of certain words from a ...
4
votes
3answers
596 views

Tips for golfing in Dart

Dart is an object oriented programming language borrowing from both Java and Javascript. What general tips do you have for golfing in Dart? I'm looking for ideas that can be applied to code golf ...
4
votes
0answers
113 views

Tips for golfing in Scratch

Scratch is a visual programming language. For the sake of counting bytes, Scratch is usually written in scratchblocks2 syntax. Post tips that specifically apply to Scratch or scratchblocks2.
1
vote
1answer
198 views

Programming in Bit [closed]

Control flow and tips in Bit I'm new to Bit, and I'm not sure about how to do certain things like loops, if statements, and other control flow, could someone explain those concepts to me at a ...
7
votes
2answers
454 views

Python: shortest way to interleave items from two lists

I'm trying to get the shortest way (character possible) to obtain List 3. List 1 and List 2 are already given to me as arguments and are the same length. ...
2
votes
0answers
173 views

Tips for golfing in TeaScript

TeaScript is a powerful JavaScript golfing language created by StackExchange, PPCG, user Downgoat. TeaScript compiles to JavaScript and contains many helpful features for golfing This question is to ...
4
votes
5answers
982 views

Reducing a Python Script [closed]

Does anyone have any suggestions as to how I could shorten this program? ...
11
votes
0answers
234 views

quine program in C using only macros [closed]

Asked on Stack Overflow, but they suggested to move it here A while ago I was reading about quines. It made me wonder if it possible to write a macro in C which will print itself, without writing any ...
12
votes
1answer
253 views

What's the shortest way to define an anonymous recursive function in Octave?

I love functional programming in Octave, but it's rather unwieldy in practice. I'm wondering about the shortest way to define an anonymous recursive function. I have some ideas, but I'm wondering if ...
7
votes
2answers
212 views

Tips for golfing in The Powder Toy

Have fun with this one, The Powder Toy is a interesting challenge for golf, especially with filt logic. The thing that makes TPT a challenge is the many many many many ways to approach a problem: <...
1
vote
0answers
159 views

Perl - convert ASCII art to use x operator [closed]

I would like to convert ASCII art to something that takes less bytes. I have string like this: my $string = ' ██ ████ █'; And I would convert ...
15
votes
3answers
979 views

How to swap elements in a vector using an anonymous function in Octave?

Swapping two elements in a vector/matrix is very simple in Octave: x='abcde'; x([4,1])=x([1,4]) x = dbcae Unfortunately, I have yet to find a way to do this ...
5
votes
2answers
166 views

Tips for golfing in Sesos

If you have any tips regarding golfing in Sesos, a language made by Dennis, and nobody else has covered them yet, please post them here! Only one tip is allowed per answer. Your tip should be at least ...
7
votes
2answers
707 views

Creating a function over multiple lines

I'm attempting to create a function over multiple lines. Parameters of the challenge: Function returns 'barbarian' Only 2 characters per line 40 lines maximum. I keep trying to use a fat arrow to ...
11
votes
2answers
227 views

Tips for golfing with numpy, scipy, or pylab

There's already a comprehensive list of tips for python here, so what I'm asking for are tips that specifically apply to using the numpy, ...
1
vote
2answers
199 views

Tips for golfing in Visual Basic .NET

This page is not for Visual Basic Tips Visual Basic .NET (VB.NET) is an multi-paradigm dialect of basic that was developed and released by Microsoft in 2002 as a replacement for Visual Basic. The ...
2
votes
2answers
166 views

Tips for golfing in Visual Basic

This page is not for Visual Basic .NET Tips or VBA tips Visual Basic (VB or VB6) is an object-oriented and event-driven dialect of basic that was developed and released by Microsoft in 1991. The last ...
1
vote
6answers
225 views

Tips for golfing Yabasic

Yabasic, or Yet Another Basic is a dialect of basic created by Marc-Oliver Ihm that may be run on Windows, Unix and PAL versions of the Sony PlayStation 2. Development for this language is ongoing. ...
5
votes
1answer
305 views

Help golfing this solution further

We are doing a PCG challenge at work, and I'm submitting answers in C#. This is a modification of the "M'Kay" challenge. My solution has been deemed correct by the requirements, I'm just trying to ...
13
votes
9answers
2k views

Tips for golfing in Clean

What general tips do you have for golfing in Clean? Please post only ideas that can be applied to code golf problems in general, and are at least somewhat specific to Clean. If you've never heard of ...
2
votes
4answers
121 views

Tips for golfing in uBasic

UBASIC is a freeware basic interpreter written by Yuji Kida at Rikkyo University in Japan, specialized for mathematical computing. It is considered to be a "ready-to-run" language that and is capable ...
13
votes
2answers
545 views

How to solve the total task on “return true to win” in 21 chars

There is a site called "Return True to Win" with interesting tasks for Javascript programmers. The goal is to find arguments to a given function that force it to return true. The following is one of ...
-4
votes
1answer
303 views

Number of leap years between two given years (inclusive) [closed]

Is there a better way to calculate the number of leap years between two given years? I want to make my code shorter (in Python). Do you have any suggestions? Here is my solution: ...
15
votes
6answers
593 views

Tips for golfing in Husk

Husk is a quite new golfing language, created by PPCG users Leo and Zgarb. It has begun being more and more competitive, often staying close or even beating languages known to be very terse, such as ...
15
votes
4answers
556 views

Tuple addition in pointfree

What is the shortest way we can express the function f(a,b)(c,d)=(a+c,b+d) in point-free notation? pointfree.io gives us ...
7
votes
1answer
112 views

Tips for Golfing in Standard ML

Standard ML (or golfier: SML) is a general-purpose, modular, functional programming language with compile-time type checking and type inference. (from Wikipedia) Though you almost certainly will ...
6
votes
2answers
136 views

How to improve Ruby code under some restrictions

I'm (still) trying to make another submission to the Largest Number Printable question, and I've got the following bit of code: ...
1
vote
0answers
255 views

Trying to optimize a solution to a puzzle with PHP [closed]

I got inspired by this: Print every character your program doesn't have But with the exception that the letters have to be between ASCII 32 to 126. We started fooling around with it at the office ...
12
votes
0answers
341 views

How to reduce EXE size of x86 ASM compiled with FASM?

As an exercise, I've created a simple solution for this challenge, in x86 Assembly Language. I'm running this with FASM on Windows. Here's my source code: ...
12
votes
12answers
475 views

Tips for golfing in QBasic

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

Tips for Golfing in SQLite?

I was looking for this page to help me enhance my first answer with SQLite, but I couldnt find one. So here we are! What general tips do you have for golfing in SQLite? I'm looking for ideas that can ...
13
votes
3answers
812 views

Advice for ruby

How can I shorten: p=gets.to_i a=gets b=gets.to_i If my input is an integer, followed by a string, followed by an integer?
12
votes
2answers
2k views

How can I shorten this python code?

Here is the code which I want to shorten. ...
3
votes
2answers
359 views

Golfing Newton's Method

I have the following code which I've written to emulate Newton's method for deriving the square root of a number: ...
69
votes
11answers
12k views

How on earth did llhuii output the Evil Numbers in 42 bytes of Python?

This is a tips question for golfing in Python concerning the Evil Numbers question on Anarchy Golf. An number is evil if its binary expansion has an even number of 1's. The challenge is to print the ...
5
votes
5answers
275 views

Tips for golfing in Proton

Proton is a quite new language created by PPCG user Hyper Neutrino. It is very similar to Python, and has similar syntax to the language Cheddar, hence there are some clever tricks you can use in ...
4
votes
3answers
278 views

Compare char to other chars in javascript

In my answer, I have this code: s.match(/[AEIOU]/) This seems too verbose to check if a string is one of A, ...
13
votes
1answer
1k views

Most common elements of a list in Python

This is a tips question for golfing in Python, which is on topic for main. I'm looking for the shortest way to get all of the most common elements of a list in Python, in the shortest way possible. ...
21
votes
16answers
1k views

Tips for golfing in x86/x64 machine code

I noticed that there's no such question, so here it is: Do you have general tips for golfing in machine code? If the tip only applies to a certain environment or calling convention, please specify ...
6
votes
2answers
167 views

lastIndexOf in CJam

For the question Find the highest unique digit , here is my answer : 9A,sqfe=W%X#- At the end I am essentially trying to achieve a lastIndexOf. I do that by ...
7
votes
1answer
408 views

Code Golfing Split String in Bash [closed]

Let us play a little golfing game. Given a single line of N space separated numbers from STDIN, one must output those numbers on N lines. So far, I came up with the three following bash solutions : ...
17
votes
9answers
1k views

SQL select number ranges

I found it quite hard to achieve a range of numbers as rows in MySQL. For example the range 1-5 is achieved by: ...
2
votes
2answers
181 views

Tips for Fastest Code challenges [closed]

What general tips do you have for how to answer fastest-code challenges? Please post one tip per answer. The objective of these challenges is to make the program that will run in the least amount of ...
18
votes
2answers
411 views

Tips for golfing in Kotlin

Given Google's recent announcement of official Kotlin support for Android development, I thought it might be timely to poll the community for some awesome golfing tips for this relatively new JVM ...
1
vote
1answer
722 views

A+B using C++ language

I'm golfing a program to sum two numbers in C++. Example: 10 3 13 I found out that this problem can be solved in 54 symbols (without spaces and so on) using C++....
5
votes
2answers
151 views

Tips for golfing in V

What general tips do you have for golfing in V? I'm looking for ideas which can be applied to code-golf problems and which are also at least somewhat specific to V (e.g. "remove comments" is not an ...
13
votes
2answers
601 views

Are there any functional programming languages designed for code-golfing?

Are there any functional programming languages designed for code golfing? I know that golfscript and CJam fulfill the same category for stack based, but I couldn't find a functional code golfing ...
28
votes
13answers
3k views

Tips for golfing in TeX/LaTeX

What tips do people have for golfing in TeX/LaTeX? Please post one tip per answer, each at least somewhat specific to TeX/LaTeX. Context: I noticed this answer and that there is no tips question for ...
19
votes
12answers
2k views

General tips for representing large numbers

Sometimes, while golfing, one needs to represent large number(s) in their code. Writing them as is can significantly increase the byte-count. What general1 tips do you have for representing long ...
9
votes
1answer
350 views

Tip? Short way to generate up to 12 repeated characters in JavaScript

'---------' '-'.repeat(9) // longer! '------------' (x='----')+x+x '-'.repeat(12) // same length Is there any cleverer way of generating strings of up to 12 ...