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 [code-golf]

Code-golf is a competition to solve a particular problem in the fewest bytes of source code. If you want to score by characters instead of bytes, please state this explicitly in the challenge. If source code length is not the primary scoring criterion, consider using another tag instead.

7
votes
4answers
171 views

Dina's Paintings

Dina loves most numbers. In fact, she loves every number that is not a multiple of n (she really hates the number n). For her friends’ birthdays this year, Dina has decided to draw each of them a ...
20
votes
8answers
1k views

Draw this diamond pattern

The below pattern will form the basis of this challenge. ...
10
votes
9answers
1k views

Through Space and Time

Introduction: In general we usually speak of four dimensions: three space dimensions for x, y, and ...
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.
8
votes
7answers
287 views

Magic: The Gathering, Paying for Spells

For more MtG-goodness: Magic: The Gathering Combat with Abilities Premise: In Magic: the Gathering, you cast spells by paying their mana cost by tapping lands for the required amount. These lands ...
1
vote
19answers
797 views

Spelling Bee Acceptable

This is similar to this question. However, I have a different goal in mind: Reduce the wordlist to words that could appear. The easy part is to delete hyphens and similar. The hard part, however: ...
16
votes
9answers
2k views

Is this a Major Scale (or equivalent)?

Sandbox The major scale (or Ionian scale) is one of the most commonly used musical scales, especially in Western music. It is one of the diatonic scales. Like many musical scales, it is made up of ...
33
votes
53answers
5k views

The first, the last, and everything between

Given two integers, output the two integers, and then the range between them (excluding both). The order of the range must be the same as the input. Examples: ...
-7
votes
2answers
220 views

Colors weave into a spire of flames

https://www.youtube.com/watch?v=6vAhPeqlODg Ok—jig's up—this one's only related to smash in name, but it'll give you something to burn your time with while you wait 'til December 7th Given a color ...
14
votes
5answers
444 views

Professor at MIT needs an AP!

The 5-card magic trick involves a magician whose assistant gives them 4 shown cards and a hidden one, in this order, and the magician must guess the hidden one. WARNING: Solution below! Leave now or ...
22
votes
22answers
4k views

ASCII Art Octagons

Given an input integer n > 1, output an ASCII-art octagon with side lengths composed of n characters. See examples below: <...
22
votes
11answers
2k views

Smallest Integer Disk

This challenge is about finding the smallest disk that contains some given points. This is made somewhat trickier, however, by the fact that in this challenge, the disk's coordinates and radius must ...
7
votes
14answers
895 views

Parentheses sequences in lexicographical order

Challenge Taken from here and also here An n parentheses sequence consists of n (s and n )s. A valid parentheses sequence is ...
13
votes
6answers
2k views

Worded Calculator

A simplistic version of English numeral calculator Task Write a program that takes a string as input and outputs the result of the expression. Rules The input string will be worded and not numeral....
3
votes
1answer
181 views

All different functions

For functions \$f, g: \{0,1\}^n \rightarrow \{0,1\} \$, we say \$f \sim g\$ if there's a permutation of \$1,2,3,...,n\$ called \$i_1,i_2,i_3,...,i_n\$ so that \$f(x_1,x_2,x_3,...,x_n) = g(x_{i_1},x_{...
8
votes
3answers
242 views

Generate an RSA key pair

Given a positive integer \$N >= 4\$, output an RSA key pair (both the private and the public key) whose key length is \$N\$ bits. The RSA key generation algorithm is as follows: Choose an \$N\$-...
12
votes
6answers
637 views

Determine the Widest Valley

Imagine we get a slice of some mountainous region, this would result in a shape similar to this: ...
14
votes
28answers
2k views

The inverse Collatz Conjecture

I think the Collatz Conjecture is already well-known. But what if we invert the rules? Start with an integer n >= 1. Repeat the following steps: If n is even, multiply it by 3 and add 1. If n is ...
14
votes
36answers
2k views

Sum square difference

The sum of the squares of the first ten natural numbers is, \$1^2 + 2^2 + \dots + 10^2 = 385\$ The square of the sum of the first ten natural numbers is, \$(1 + 2 + ... + 10)^2 = 55^2 = 3025\$ ...
10
votes
15answers
1k views

Rosencrantz and Guildenstern are Code

In the absurdist play Rosencrantz and Guildenstern are Dead, the two main characters Rosencrantz and Guildenstern(or are they?) are always mixing up which of them is who—or sometimes which of their ...
14
votes
6answers
1k views

Ryley's Theorem

S. Ryley proved following theorem in 1825: Every rational number can be expressed as a sum of three rational cubes. Challenge Given some rational number \$r \in \mathbb Q \$ find three rational ...
3
votes
0answers
114 views

Number of circles packed into a rectangle [closed]

Calculate the maximum number of circles of radius r that can fit in a rectangle with width x and height ...
9
votes
4answers
233 views

Count the corners, edges and faces of a cut cube

Coming from this sandbox post This is inspired from an 8th graders math test Intro We have a cube with following corners ...
15
votes
11answers
855 views

Generate some rough numbers

Background A number n can be described as B-rough if all of the prime factors of n strictly ...
6
votes
18answers
630 views

Toasty, Burnt, Brûlée!

It turns out that my toaster is a tad broken. It lost WiFi (You know, it's one of those newfangled smart toasters), and its been going bonkers! Since it no longer works, I've been having to hack into ...
19
votes
32answers
3k views

How fast am I vrooooming?

Introduction My car speedometer was hacked! Instead of showing me how fast i'm driving, it just shows: "Vroooom!" Please help me know how fast i'm going. Challenge Take a string as input, and check ...
9
votes
5answers
192 views

Find the minimal initial values [duplicate]

Consider a sequence F of positive integers where F(n) = F(n-1) + F(n-2) for n >= 2. The ...
19
votes
3answers
354 views

Count cyclically self-describing lists

Cyclically self-describing lists A list \$L\$ of positive integers is cyclically self-describing, if the following conditions hold. \$L\$ is nonempty. The first and last elements of \$L\$ are ...
19
votes
10answers
2k views

Repeat this GCD operation

Problem A3 from the 2008 Putnam competition says: Start with a finite sequence \$a_1, a_2, \dots, a_n\$ of positive integers. If possible, choose two indices \$j < k\$ such that \$a_j\$ does not ...
21
votes
14answers
3k views

My array should equal this, but it doesn't!

Given an array of integers a which contains n integers, and a single integer x; remove the fewest amount of elements from ...
5
votes
29answers
1k views

Numbers Manipulation challenge

Use any programming language to generate two random digits between 1 and 9 (including both). Then your program should display: in the first line: the first random digit, in the second line: the ...
1
vote
5answers
548 views

0xDEADBEEF is not tasty, but still 0xFEEDBEEF

Inspired by "You had me at hello" Introduction For those who don't know, hexadecimal is a base system like decimal. Contrary to decimal however, it uses 16 (hence the name) digits instead of 10. ...
1
vote
0answers
98 views

x bottles of y on the z [duplicate]

I do not believe this question to be a duplicate of this one, since this one requires more string manipulation, if it is still a duplicate feel free to close this question Introduction Your ...
7
votes
12answers
817 views

Decimal Digit Truncating

Input: A decimal Output: The input truncated How to truncate them? The integer part of the input will remain the same. The decimal part of the input will be truncated based on the lowest digit in ...
0
votes
0answers
107 views

StalinSort Golf [duplicate]

Someone sent me this description of a joke sorting algorithm, and I thought it would make for a fun golf. Given a list of positive integers remove all elements that aren't larger than all elements ...
21
votes
11answers
6k views

Is this number secretly Fibonacci?

Background Most of you know what a Fibonacci number is. Some of you may know that all positive integers can be represented as a sum of one or more distinct Fibonacci numbers, according to Zeckendorf'...
6
votes
4answers
155 views

Seeking Substantial Subcollections

(thanks to @JonathanFrech for the title) Challenge Write a program or function that, given a collection of positive integers \$S\$ and a positive integer \$n\$, finds as many non-overlapping ...
11
votes
12answers
2k views

Split it. But not all!

Inspired by this StackOverflow question. Input: We'll take three inputs: A delimiter-character D to split on A character I ...
2
votes
0answers
193 views

Find the pattern

I feel tired to do "find the pattern" exercise such as 1 2 3 4 (5) 1 2 4 8 (16) 1 2 3 5 8 (13) Please write a program that finds the pattern for me. Here, we ...
9
votes
3answers
298 views

Is the Circuit Possible?

Write a program or function that takes input: all resistors available and a resistance value and outputs a truthy value of whether or not it is possible to get the resistance by using those resistors. ...
6
votes
1answer
498 views

Hack g-code.js parser

Here you can see g-code parser, written in JavaScript to use in microcontroller (like espruino). But you can run it in browser, because it don't use any specific features. ...
0
votes
7answers
276 views

convert decimal to duodecimal

The task is to convert a string representing a number in decimal (base 10) representation to duodecimal (base 12). The input is thus a string, the output should be printed. The input number can be ...
13
votes
16answers
2k views

Trim that distracting background off!

Isn't it annoying when you're taking a picture, but the background detracts from the actual substance of the image? I'd say it is. I need to know how much I should crop so that I get rid of this ...
-13
votes
15answers
244 views

Sequence and Series

Use any programming language to display numbers divisible by 1000000 that are greater than 1 and less than 10000000. Each number should be displayed in new line. Your program should display exactly: <...
5
votes
1answer
102 views

Minimum 1's to get 1-expression for n [duplicate]

Background Challenge is inspired by this question. The 1-expression is a formula that in which you add and multiply the number 1 any number of times. Parenthesis is allowed, but concatenating 1's (e....
17
votes
3answers
358 views

Optimize my wings order

This tweet lists the possible orders for Wings of a Chinese restaurant1: When ordering Pizza I usually calculate what size gives me the best Pizza-price ratio which is a simple calculation. However ...
8
votes
15answers
1k views

Find a recursive acronym

Introduction A recursive acronym is an acronym that contains or refers to itself, for example: Fish could be a recursive acronym for ...
14
votes
16answers
3k views

Chop up my ASCII art

Let's say I've got some ASCII art: ...
22
votes
16answers
3k views

Bake me a slice of cake

My birthday is in a month, and this is a slice of tasty cake. ...