Questions tagged [tips]
For questions asking for tips on golfing in a specific language, doing well in certain challenge tag, or improving a particular piece of code.
362
questions
1
vote
1
answer
157
views
Shorten this recursive even fibonacci implementation [closed]
I have the following Haskell code to generate the the values of the Fibonacci sequence which are even as an infinite list:
...
2
votes
0
answers
79
views
Tips for golfing in Thue
Anyone got tips for golfing in Thue. One tip per answer, and no tips aplicable to all languages (like remove comments)
4
votes
4
answers
198
views
Tips for golfing in (,) in-paren-comma
What tips do you have for golfing in (,)? I've found that there are so many ways to make code shorter, and I want more ways. I doubt there even are any tips for (,) that are applicable in the majority ...
5
votes
4
answers
201
views
Tips for golfing in Arturo
Arturo is a bytecode-compiled/interpreted, garbage-collected general-purpose language filling a role similar to JavaScript, Python and Ruby. It is centered around the concept of blocks, which hold ...
12
votes
2
answers
981
views
Can Bitshift Variations in C Minor be compressed down to less than 185 characters?
Bitshift Variations in C Minor by Robert Miles is a Code Golf music piece written in C (with some additional bash commands). It was originally presented in a 2016 Computerphile video Code Golf & ...
-2
votes
1
answer
414
views
What is the ABSOLOUTE shortest way to write this code?
So I got kinda bored and was wondering if it was possible to make this code shorter without modifying anything except a file named coin.py...
...
3
votes
6
answers
881
views
Tips for golfing in Thunno 2
Thunno 2 is a stack-based golfing language with around 400 commands (achieved through overloads) created by me, The Thonnu.
It seems like a good idea to share some tips for golfing in Thunno 2.
Please,...
5
votes
2
answers
367
views
Shortening this Code to process nested tuple even further without the use of max()
I have the code:
...
7
votes
1
answer
296
views
Is there any less code way to make a leaf (eye) shape in CSS?
I'm trying to solve a CSS challenge. It contains a rotated leaf shape (looks like an eye). Score for the challenge depends on amount of characters of the code. Here's my way to make a leaf shape:
<...
0
votes
0
answers
194
views
How to efficiently count all powers of 2 in a given set of numbers in vb.net?
Every integer can be expressed in powers of 2. You know this as the binary system
Assume you are given a set of k numbers ...
16
votes
13
answers
2k
views
Tips for golfing in SVG
SVG is an XML vector graphics markup language embeddable in web content.
Your tips should be at least somewhat specific to SVG.
Please post one tip per answer.
9
votes
5
answers
538
views
Shortest way to convert the result of a test to a string output (e.g. true or false) in bash
I'm trying to shorten a bash solution to a Code Golf challenge, which requires an output of true or false. I've managed to ...
5
votes
2
answers
741
views
Tips for shortening this type-safe addition in JavaScript
Consider:
c=(a,b)=>(+a||0)+(+b||0)
Yes, it is not good to solve it like that. But I want to shorten it even more. If a is a ...
0
votes
1
answer
142
views
Tips for golfing in Wren
Wren is a small, fast, class-based concurrent scripting language. Does anyone have any tips for this language?
Please make sure to post 1 tip per answer, and don't post answers like "remove ...
0
votes
0
answers
168
views
Tips for golfing in Zig
Not sure if I've seen this one before :/
Any tips for golfing in Zig? Please post 1 tip per answer and don't post obvious tips like "remove whitespace".
Github link
13
votes
4
answers
2k
views
Tips for improving your score in fastest code challenges
Fastest code is a scoring method on this site where the goal is to write code that is as fast as possible.
From the tag wiki:
The winner of a fastest-code challenge is determined by the runtime ...
8
votes
2
answers
590
views
Inverting string-based binary number in one line in Python
I want to read two strings on separate lines, each string the same length and containing only 0's and 1's, and determine if the first is the one's complement of the second. How succinctly can this be ...
3
votes
0
answers
101
views
Tips for golfing in Arn
Does anyone have tips on how to golf in this language? Please one tip per answer and avoid posting simple and general tips such as "remove whitespace".
Here is the github link and here is ...
2
votes
0
answers
270
views
Shorten this dns txt record request script as much as possible
I have made a short script that will pull dns txt records down from a server and combine them into a single string.
DNS txt records are:
1.website.com
...
6
votes
1
answer
206
views
Need some feedback with PHP+C polyglot code and class/struct properties [closed]
If you consider the following PHP+C polyglot snippet, there is a problem regarding class property access in the printf call:
...
4
votes
3
answers
1k
views
Python: can I shorten this code further for checking substrings
So the golf question was like this:
You are given a number T and then a total of T number of 17-character strings. For each of ...
5
votes
1
answer
730
views
Help me golf this C program checking for string patterns in a sorted hand of cards
I could not think of a better title.
This is a tips question. I'm asking for tips on golfing my code.
I recently took part in a code golf competition in C. The competition ended and I lost. The ...
11
votes
7
answers
800
views
Tips for golfing in Knight
Knight is the Language of the Month for August 2022, and I noticed that it didn't have a tips page, so here it is!
I'm looking for ideas which can be applied to code-golf problems and which are also ...
14
votes
2
answers
2k
views
Can `a?b<c:b>c` be shortened in Javascript?
So I have the situation where I have one boolean value a and, if that one is true and b<c ...
7
votes
4
answers
125
views
Tips for golfing in J-uby
J-uby is the Language of the Month for June 2022, so I'm looking for tips for golfing in it. As usual, please post one tip per answer, and avoid general tips such as "remove whitespace" or &...
11
votes
2
answers
844
views
Curry tips for Haskell programmers
Curry is the Language of the Month this month and some users are starting to get into it, so let's get some tips together.
Haskell and Curry are similar in a lot of ways and a lot of tips for Haskell ...
13
votes
5
answers
782
views
Tips for golfing in Piet
Seeing that the current language for Learn You a Lang for Great Good is Piet, and that we don't seem to have a tips page for Piet yet, I decided to make one.
Piet is a stack-based esoteric programming ...
2
votes
0
answers
87
views
Tips for golfing in Fennel
Fennel is a lispy language which compiles to Lua.
From its page:
Fennel is a programming language that brings together the speed, simplicity, and reach of Lua with the flexibility of a lisp syntax ...
4
votes
0
answers
205
views
Tips for golfing in Seriously
I am looking for tips to code in this golfing language Seriously, and was wondering what some of the ways for golfing this language is. "Remove comments" is not a tip. Actually is also ...
7
votes
2
answers
282
views
How to shorten Python code involving the sum of reciprocals?
I have a coding problem that goes like this:
Given a positive integer \$N\$, return a list of all possible pairs of positive integers \$(x,y)\$ such that $$\frac1x+\frac1y=\frac1N$$
I already solved ...
-8
votes
1
answer
337
views
The right way to return [[0, 0, 0], [0, 1, 0], [0, 0, 0]] [closed]
Here is the program to return [[0, 0, 0], [0, 1, 0], [0, 0, 0]]
[[0]*3,[0,1,0],[0]*3]
Try it online!
Can you shorten this code?...
12
votes
2
answers
331
views
Shortest way to coerce to array
Given a variable a (non array) or (any[]) convert to (any[])
function example(s: string | string[]) {
const e = Array.isArray(s) ? s: [s]
return e
}
Is ...
7
votes
6
answers
188
views
Tips for golfing in Lexurgy
What general tips do you have for golfing in Lexurgy? I'm looking for ideas which can be applied to code-golf problems and which are also at least somewhat specific to Lexurgy (e.g. "remove ...
10
votes
2
answers
865
views
Can I shorten this Python code for simulating a car driving around
I am trying to write a solution to the following problem using as few characters as possible (to meme my friend and introduce him to golfing). Can any improvements be done to my code?
So the problem ...
12
votes
4
answers
542
views
Tips for golfing in Add++
Add++ is the Language of the Month for January 2022, and so I'm asking for tips for golfing in it. Please stick to tips specific to Add++, and avoid general tips such as "remove whitespace" ...
2
votes
2
answers
143
views
Tips for golfing in VB.net [duplicate]
Any general tips for golfing in VB.net?
This, similar to Pascal, is a very rarely used language, thus having very few resources online
Visual Basic.NET (VB.NET) is a multi-paradigm, managed, type-safe,...
4
votes
0
answers
154
views
Tips for golfing in Objective C
Although on codingame.com, Objective C and C are two of the best golfing languages there, so I would like to know some of the best golfing methods (although I am a python person, I am currently trying ...
8
votes
10
answers
395
views
Tips for golfing in Pascal
What general tips do you have for golfing code in Pascal?
I know this is a tricky language very few people use this but I would like to know any tips from the professionals out there :)
I'm looking ...
7
votes
2
answers
193
views
In as few bytes as possible in t-sql, return 100 rows containing the phrase 'Have a great Christmas'
In as few bytes as possible in t-sql, return 100 rows containing the phrase 'Have a great Christmas'
92 (I think) to beat :D
...
4
votes
3
answers
679
views
How to shorten the Python code? Part II
Code Python 3, 245 bytes
...
12
votes
3
answers
381
views
Tips for golfing in BQN
What general tips do you have for golfing in BQN? I'm looking for ideas which can be applied to code-golf problems and which are also at least somewhat specific to BQN (e.g. "remove comments"...
9
votes
4
answers
3k
views
How to shorten the python code?
I'm writing a program that takes a number from input (call it x), loops from 0 to (x - 1) (let's call our iterator y) and prints \$y^x+x\$ for each y.
After the loop, it then prints "SUM: N" ...
20
votes
1
answer
615
views
How to solve the LCM in 50 bytes of Python
I've recently stumbled upon a Russian site called acmp.ru, in which one of the tasks, HOK, asks us to find the LCM of two positive integers. The full statement, translated to English is as follows:
...
10
votes
12
answers
2k
views
Tips for golfing in TypeScript's type system
What general tips do you have for golfing in TypeScript's type system? I'm looking for ideas which can be applied to code-golf problems and which are also at least somewhat specific to TypeScript's ...
2
votes
2
answers
210
views
Tips for parsing Standard Input in JavaScript
I've been doing quite a few code golf recently and I realised that a lot of times, I have to do something involving list.
Most of the times lists are space-separated or comma-separated values in the ...
9
votes
0
answers
269
views
Tips for golfing in Chef
What general tips do you have for golfing in Chef? I'm looking for ideas which can be applied to code-golf problems and which are also at least somewhat specific to Chef (e.g. "remove unnecessary ...
6
votes
2
answers
416
views
Pushing the limits to make a piece of code solving the K-Goodness String problem shorter
I am trying to push my limits of making a python code as short as possible.
I left the readability part way behind.
I was attempting the K-Goodness String problem from Round A of Google Kick Start ...
-1
votes
1
answer
308
views
Shortest way to convert a float to an int [closed]
I'm not really sure if this is the right place to ask this.
Now, I know I can convert a float to an int with int, but is there some shorter way?
12
votes
2
answers
559
views
Branchless (MIPS) assembly code for median of 3
I was trying to write a short MIPS32 code for computing the median of three registers.
The rules:
Assume that some values are pre-loaded into $t0, ...
9
votes
3
answers
431
views
Tips for golfing in Lean
Lean is a theorem prover and programming language. It's also as of writing the Language of the Month!
What tips do people have for golfing in Lean? As always, tips should be specific to to Lean (e.g....