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].

Filter by
Sorted by
Tagged with
4
votes
1answer
241 views

How can I golf this JavaScript code, if at all?

I have some JavaScript code in a <script> HTML tag I'd like to golf, while still remaining in the tag. How can I golf that code, if at all? Here's the code: <...
3
votes
2answers
215 views

Tips for golfing in MathGolf

What general tips do you have for golfing in MathGolf? I'm looking for ideas that can be applied to code golf problems in general that are at least somewhat specific to MathGolf (for tips which can be ...
2
votes
5answers
186 views

Tips for golfing in Keg

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

Tips for golfing in 1+

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

Tips for golfing in MarioLANG

I recently saw this language in a challenge and it's awesome. Does anyone have some tips for golfing in it?
5
votes
1answer
254 views

Tips for golfing in Smalltalk

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

Tips for golfing in Grass

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

Golf my iteration function

Here is my ungolfed Ruby code for a function I want to try and golf: ...
7
votes
1answer
264 views

Convert a string containing integers to list of integers

What is the shortest way to convert a string containing integers separated by spaces to a list of integers? input : "-3 1 5 8 10" output : [-3, 1, 5, 8, 10] I regularly face this situation and I ...
11
votes
3answers
2k views

Print 'A' 1000 times with BrainFuck

What is the best BrainFuck code (in terms of code size) to print 'A' 1000 times ? My approach is: set 'A' to p[0] set 255 to p[1] to display 255 'A', 3 times set 235 to p[1] to display 235 'A' This ...
3
votes
0answers
84 views

Generating edge cases in programming puzzles [closed]

Not exactly sure if it belongs in this site, but I always have trouble thinking of all the certain edge cases in any kind of competitive programming or puzzles. For example, take this kind of ...
13
votes
7answers
2k views

Generate ladder of integers using the least number of unique characters (in C++)

I am new to the sport of code golf. I am trying to generate a ladder of integers using the least number of unique characters in C++. Let's say we are given an integer 4. We will generate the ...
3
votes
1answer
218 views

Tips for golfing in Turing Machine But Way Worse

What are some tips for golfing in Turing Machine But Way Worse, a language made by MilkyWay90 and ASCII-only? Tips should be Turing Machine But Way Worse-specific and not be trivial (For examples ...
22
votes
1answer
1k views

Is it possible to make a clamp function shorter than a ternary in JS?

Imagine this short function to clamp a number between 0 and 255: c = n => n > 0 ? n < 255 ? n : 255 : 0 Is this the shortest possible version of a clamp ...
5
votes
4answers
701 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 ...
7
votes
1answer
215 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.
0
votes
1answer
220 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 ...
9
votes
2answers
2k 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. ...
3
votes
0answers
194 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
1k views

Reducing a Python Script [closed]

Does anyone have any suggestions as to how I could shorten this program? ...
11
votes
0answers
292 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
286 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 ...
9
votes
2answers
308 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
186 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
1k 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 ...
4
votes
2answers
230 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 ...
9
votes
2answers
2k 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 ...
10
votes
2answers
274 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
228 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
200 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
282 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. ...
4
votes
1answer
360 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 ...
17
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
129 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
598 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
580 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
620 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 ...
16
votes
4answers
656 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 ...
6
votes
1answer
146 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 ...
7
votes
2answers
163 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
283 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 ...
14
votes
1answer
547 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
13answers
704 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 ...
9
votes
0answers
194 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
877 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
3k views

How can I shorten this python code?

Here is the code which I want to shorten. ...
3
votes
2answers
368 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: ...
71
votes
11answers
13k 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 ...
4
votes
5answers
281 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
290 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, ...