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.

Filter by
Sorted by
Tagged with
3
votes
2answers
405 views

Remove duplicates from list and order it by count? (python 3)

How do I remove all duplicates from list and order it based on count? ...
41
votes
17answers
5k views

Tips for restricted source in Python

Just like code-golf, restricted-source pushes one to exploit quirks and hidden features of the Python language. We already have a place to collect all these tips for code-golf, those for restricted-...
3
votes
1answer
391 views

Redirect HTTP links to HTTPS with Javascript

What is the shortest way to secure a site with Javascript? I am new to Code Golfing, and this is what I've come up with so far. I bet that this could be improved though: Challenge: Make a script ...
4
votes
1answer
164 views

Which languages are optimal for problems that require "reading" input while also writing to it like a stack

When encountering a problem whose input is meant to be read sequentially, but you may also want to push back onto the input like a stack, which languages have the optimal boilerplates for doing so, ...
1
vote
2answers
691 views

Shortest Python 3 for sum of arithmetic progression

Input: from STDIN number of vertices in Graph \$2 \leq N \leq 100\$. Rules: [Code size] = max ([code length without spaces, tabs and newlines], [total code length divided by 4]) Math formulation: In ...
4
votes
2answers
1k views

Shortest python3 code for: Find the difference between a number and a power of two not exceeding a given number

So, this is a task from one very popular educational site in Russia: https://acmp.ru/index.asp?main=task&id_task=786&ins=1 Mathematically, you need to find the power of two not exceeding the ...
0
votes
6answers
610 views

LeetCode 552: Student Attendance Record II

I'm posting my code for a LeetCode problem copied here. If you have time and would like to golf for a short solution, please do so. Requirement It has to only pass the LeetCode's Online Judge, if the ...
2
votes
2answers
274 views

Is there a language that supports Turing machines? [closed]

Is there a programming language that supports single tape Turing machines specified in some format? I am aware multiple formats for expressing them exist, but is there a standard one using which an ...
7
votes
1answer
2k views

Resource for generating shortest regex given a list of strings

I'm looking for a program such that, given a finite list of strings, can find short regexes to match exactly all of them and nothing else. Since there are multiple languages that express regexes ...
0
votes
1answer
231 views

List of programming languages that can run code at runtime [closed]

What all languages have a construct similar to python's eval, so you can write code during runtime and run it? A list would be helpful for certain programming ...
9
votes
1answer
294 views

Multiplication algorithm on a 4004

So I was playing around with this emulator of the Intel 4004 and decided I wanted to set a challenge for myself. The first use for the 4004 was in a calculator, so I decided that I would try to code ...
2
votes
1answer
122 views

Code golfing my guess the number game with feedback in NS-HUBASIC - Can it be code golfed any further?

The player has to keep guessing a number from 1 to 10 until they guess the correct number to win the game. If they make an incorrect guess, they're told if their guess was too low or too high. Each ...
2
votes
1answer
176 views

Tips for Golfing in Symja

Symja is a "computer algebra language & Java symbolic math library for Android NCalc calculator". It's a fun little language, so I'm wondering if y'all have any tips for golfing in Symja. As per ...
4
votes
2answers
123 views

Tips for golfing in Pure Data

Pure data is a graphical programming language designed for audio processing. This makes it unsuitable for most general programming but especially unsuitable for code-golf. It would then be nice to ...
4
votes
1answer
261 views

Best free online resources to learn competitive programming [closed]

I am quite proficient in C++ and Java and want to learn competitive programming to participate in contests like Google codejam and other online contests held on sites like CodeChef and Codeforces. I ...
3
votes
1answer
192 views

Summing intertwined terms of an array

I'm recieving 2-dimensional positions of two objects as a string with this format: x1,y1,x2,y2. The string is recieved from a ...
12
votes
3answers
2k views

Intersection of circles – How can I reduce this golf code to 127 bytes?

I started a CodeWars kata in Python, just two days ago, related to code golf. Task: Given two congruent circles a and b of radius r, return the area of their intersection rounded down to the nearest ...
42
votes
8answers
3k views

Tips for Creating/Maintaining a Golfing Language

Creating a golfing language can be hard. Let's help budding golfing language creators out and provide some helpful tips on how to create one. I'm looking for tips on: The design process ...
4
votes
2answers
3k views

Shortest Solution in Python 3 for Caught Speeding - CodingBat

I am trying to find the shortest code in python 3, to solve this problem: You are driving a little too fast, and a police officer stops you. Write code to take two integer inputs, first one ...
4
votes
1answer
462 views

From text to ascii art from CodinGame practice puzzle

On CodingGame, there is a Puzzle that ask to write words with ascii art. I solve the puzzle then tried to golf it. What improvement can I do on it? ...
7
votes
2answers
256 views

Is there a shorter way to express this haskell idiom?

Every so often I have a function of type a -> b and a function of type b -> b -> c and I would like a function of type <...
11
votes
3answers
531 views

Decode ascii and reversed words sentence

In a challenge of CodingGame, there is a challenge that ask you to decode a string composed by reversed words ('Hello world' > 'olleH dlrow') then each characters converted into ascii value separeted ...
4
votes
2answers
1k views
3
votes
0answers
102 views

Parallel resistance in electric circuits in C [duplicate]

What are some tips on how to shorten this code even further? The code is meant to compute the parallel resistance of an electric circuit. Using scanf ...
8
votes
3answers
727 views

What is a short code for generating this matrix in R?

I can see that it is 101 'moving to the right' but I cannot think of a short way to generate it in R language. \$\begin{bmatrix} 0 & 1 & 0 & 0 & 0 & 0 \\ 1 & 0 & 1 & 0 ...
4
votes
1answer
512 views

Simplify the following C ascii graphing function

This wasn't originally intended for code-golf, just as a little debugging routine to roughly visualize something "goofy" going on in a model of some (irrelevant here) physical process. But ...
5
votes
1answer
390 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: <...
6
votes
2answers
299 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 ...
3
votes
5answers
293 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 ...
4
votes
3answers
314 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 ...
11
votes
2answers
335 views

Tips for golfing in MarioLANG

I recently saw this language in a challenge and it's awesome. Does anyone have some tips for code-golfing in it? Your tips should be at least somewhat specific to MarioLANG. Please post one tip per ...
8
votes
1answer
341 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 ...
9
votes
3answers
246 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
361 views

Golf my iteration function

Here is my ungolfed Ruby code for a function I want to try and golf: ...
9
votes
1answer
602 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 ...
12
votes
3answers
3k 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 ...
4
votes
0answers
104 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 problem ...
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
268 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 ...
7
votes
5answers
847 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 ...
9
votes
3answers
362 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.
9
votes
2answers
5k 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. ...
4
votes
0answers
273 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 ...
5
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
376 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
339 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 ...
10
votes
2answers
433 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
217 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 ...

1
2
3 4 5
7