Linked Questions

297
votes
157answers
108k views

Tips for golfing in Python

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

Tips for golfing in JavaScript

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

It was just a bug

Inspired by the bugged output in @Carcigenicate's Clojure answer for the Print this diamond challenge. Print this exact text: ...
59
votes
119answers
16k views

Duck, duck, goose!

Remember the kids game, 'Duck, Duck, Goose'? No? Me neither. The challenge Print the word 'duck' on individual lines an indeterminate amount of times. Print the word 'goose'. Your program ends. The ...
76
votes
90answers
17k views

Build me a brick wall!

Challenge I need help building a brick wall! Throw together some code for me using no input and produce the following output wall shown below: ...
69
votes
83answers
10k views

Make the Mexican Wave

In as few bytes as possible, write a program or function that outputs the following: ...
97
votes
39answers
24k views

Tips for golfing in Java

Are there any useful shortcuts that can be used in Java? As shown below, import already adds at least 17 characters to a program. ...
69
votes
55answers
17k views

Tips for code-golfing in C#

What general tips do you have for golfing in C#? I'm looking for ideas that can be applied to code golf problems in general that are at least somewhat specific to C# (e.g. "remove comments" is not an ...
52
votes
95answers
9k views

Alphabet triangle

You are to print this exact text: ...
71
votes
52answers
25k views

Tips for golfing in Ruby

What general tips can you give for golfing in Ruby? I'm looking for ideas that can be applied to code golf problems in general that are specific to Ruby. (For example, "Remove comments" would not be ...
52
votes
75answers
8k views

Output Buffalo buffalo Buffalo buffalo buffalo buffalo Buffalo buffalo

Challenge The goal is to output Buffalo buffalo Buffalo buffalo buffalo buffalo Buffalo buffalo. Context. (Maybe another interesting challenge could be printing all ...
54
votes
75answers
8k views

Test a number for narcissism

A Narcissistic Number is a number which is the sum of its own digits, each raised to the power of the number of digits. For example, take \$153\$ (3 digits): \$1^3 + 5^3 + 3^3 = 153\$ \$1634\$: \$1^...
73
votes
41answers
20k views

Shortest Game of Life

Conway's Game of Life is the classic example of cellular automation. The cells form a square grid and each has two states: alive or dead. On each turn, each cell simultaneously updates according to ...
75
votes
36answers
4k views

Uncollapse digits

Task Given a string of English names of digits “collapsed” together, like this: zeronineoneoneeighttwoseventhreesixfourtwofive Split the string back into digits:...
31
votes
70answers
8k views

Randomizing until 0

Challenge Sandbox post Given a positive integer (K) Output a uniformly-random integer (Y) between ...
32
votes
62answers
5k views

Insist on an answer

At runtime, keep prompting for a line of input until the user inputs something (other than an empty newline), i.e. does not just press Enter or OK. Output or result is neither required nor prohibited. ...
54
votes
40answers
6k views

Make some Alphabet Rain

Alphabet Rain The Task: The basic premise is to print out the input string and then repeat each character vertically, based on it's (0-indexed) position in the (case-insensitive) alphabet ...
39
votes
45answers
7k views

Kolmogorov shifter

Output or display the following three lines of text, exactly as they are shown below. A trailing newline is accepted. ...
41
votes
45answers
8k views

I done did made a spaceship maw!

Introduction: Inspired by this comment of @MagicOctopusUrn on @Emigna's 05AB1E answer for my "It was just a bug" challenge: 8F9ÝÀNð×ý}».∊ I done did made ...
45
votes
43answers
4k views

Split string on first occurrence of each character

Related. Given a printable ASCII string, split it into a list of non-empty strings with a new sub-string beginning every time a character, which has not previously been seen in the same case, occurs. ...
25
votes
61answers
6k views

Reinvent the For loop [closed]

For loops are used extensively in many languages, but what would you do if no languages supported them? Create a way to execute a basic ...
19
votes
68answers
5k views

Round towards zero

This is a simple task. Given a positive or negative real number, round it to the next whole integer closer to zero. The challenge Take input through any reasonable form (stdin, function, etc.) of ...
34
votes
44answers
5k views

Half, Half Half, and, Half

Consider the following number sequence: \$ 0, \frac{1}{2}, \frac{1}{4}, \frac{3}{4}, \frac{1}{8}, \frac{3}{8}, \frac{5}{8}, \frac{7}{8}, \frac{1}{16}, \frac{3}{16}, \frac{5}{16}, \frac{7}{16}, \...
32
votes
47answers
5k views

Print all lexicographically increasing numbers under 10000

A lexicographically increasing number is an integer whose digits are in strictly increasing order. Print all lexicographically increasing numbers under 10000. Here are lines of the expected output: ...
38
votes
38answers
9k views

Tips for golfing in PHP

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

Divisor skyline

For any positive integer \$k\$, let \$d(k)\$ denote the number of divisors of \$k\$. For example, \$d(6)\$ is \$4\$, because \$6\$ has \$4\$ divisors (namely \$1, 2, 3, 6\$). Given a positive integer \...
34
votes
42answers
3k views

Up and down, up and down

Challenge: Given a positive integer input n, create a vector that follows this pattern: 0 1 0 -1 -2 -1 0 1 2 3 2 1 0 -1 -2 -3 -4 -3 -2 -1 ... ±(n-1) ±n ...
41
votes
30answers
7k views

There, I fixed it (with tape)

Challenge: Given a string only containing upper- and/or lowercase letters (whichever you prefer), put tape horizontally to fix it. We do this by checking the ...
40
votes
26answers
3k views

Difference should make no difference

Your company lately hired a new bunch of extremely dedicated sysadmins. They feel that just watching computer screens is quite limiting (I mean, 60Hz refresh rate is just NOT enough), so they hooked ...
31
votes
31answers
3k views

How tall are the monoliths?

Here is an example of an input of monoliths. There are 4 in this example. _ | | _ | | _ | | | | | | | | _ _| |_| |___| |____| |_ The first ...
11
votes
59answers
2k views

Print multiplication tables by input

In this challenge you've to print multiplication tables by input, Here are some examples: ...
21
votes
40answers
3k views

X Steps Forward, 1 Step Back

Here the first 100 numbers of an easy sequence: ...
33
votes
30answers
5k views

root of root of root of root

This idea came to me when I saw my little brother playing with my calculator :D The task Taking a integer as an input, print that many graphical square roots under each other, like this: ...
24
votes
35answers
4k views

It's time for a clock challenge!

I'd like you to build me a clock that displays time in this format: 18 ---------- 19 -------------------------------------------------- This displays '18:10'. The ...
23
votes
40answers
3k views

Draw a hollow square of # with given width

I got this challenge from Codingame and am curious about better solutions than mine: Given a width via standard input draw a hollow square of '#' in given width and length. Example: 5 results in <...
59
votes
18answers
4k views

There are two new sheriffs in town – Identifying DJMcMego pairs!

We have some new sheriffs moderators in town, Mego and DJMcMayhem. We need a challenge to properly honour them for their new positions, so there we go. Here's something that has caught my attention ...
31
votes
28answers
3k views

Implement the Zundoko Kiyoshi function

Background The Zundoko Kiyoshi function originates from this tweet by kumiromilk. Translated from Japanese, it reads roughly as follows: The test for my Java lecture had a problem that said "...
33
votes
25answers
5k views

The (Easy) Road to Code

Input: An integer \$n\$, which is guaranteed to be \$\ge3\$. An integer \$d\$, which is one of \$[-1,0,1]\$. Output: A road of size \$n\$, which will be in a north-west direction if \$d=-1\$; a ...
61
votes
15answers
12k views

I HATE spaces in file names

It is simple. I cannot stand when people use spaces when naming files. It sometimes wrecks console commands and makes the output of ls ugly. The challenge is to write a program (only ascii characters)...
25
votes
30answers
4k views

Zero-sum counting

Write a program or function that given n ≥ 1 returns the number of solutions to ±1 ± 2 ± 3 ± ... ± n = 0. For n = 6 there are no solutions, so the answer is 0. For n = 4 there are ...
26
votes
30answers
2k views

Nth Differences

In math, one way to figure out what the type of a given relation (linear, quadratic, etc) is to calculate the differences. To do so you take a list of y values for which the gap between the ...
16
votes
47answers
4k views

ASCII Meme Arrow Generator

Specifications Given a number n, output an ASCII "meme arrow" (greater-than symbol, >) of size ...
39
votes
22answers
3k views

Print the nth prime that contains n

This question will be a twist on finding the nth prime number. Challenge You must write a program that will take one input n, ...
28
votes
26answers
4k views

Generate a password

It is very hard to remember my password, so I came up with a way to generate a password. The way I generate my password is from a word or a sentence, following these steps: Start from left to right ...
25
votes
29answers
2k views

Replace me by the sum of my cyclic successors!

I have a simple challenge for you this time. Given an array of positive integers A (or the equivalent in your language), replace each entry Ai with the sum of the next Ai elements of A, cycling back ...
27
votes
27answers
2k views

Display a number in Toki Pona

Toki Pona is a constructed language with 137ish words, designed to constrain the speaker to expressing ideas in a simple and straightforward manner, reducing ideas to more essential forms. Often, ...
23
votes
25answers
4k views

The Möbius Function

The Möbius Function The Möbius function is an important number theoretic function. Your submission should accept a positive integer n and return the value of the ...
19
votes
25answers
5k views

The Work Day Countdown

I just had a genius idea for making the work-life easier - a countdown to a specific date which only counts workdays. The basic task is to create a countdown to a specific date which only includes ...
21
votes
34answers
2k views

Give me Triangles [duplicate]

Given an integer n>0, write a program that will output an "isosceles" Triangle out of #'s of height n. Examples: ...
23
votes
29answers
5k views

Find the closest palindromic number

Given a number N, output/return X so that N+X is a palindrome, where |X| has to be as small as possible. Palindrome: A number is a palindrome, if its sequence of digits is the same when reading them ...

15 30 50 per page