Skip to main content

Questions tagged [optimization]

For challenges focusing on the optimization of an aspect not covered by other tags. (not a winning criterion)

Filter by
Sorted by
Tagged with
18 votes
3 answers
998 views

Here is a game: Start with the set {1,2,3,...,n} of natural numbers. At any turn of the game, you may pick two numbers from this set, a and b, then replace them with their product a*b. Since it is a ...
Fabius Wiesner's user avatar
16 votes
11 answers
2k views

When code golfing, it can be useful to write numbers succinctly. This challenge involves using a source language to generate code for a target language. For the submission to be valid, it must ...
Charles's user avatar
  • 3,071
17 votes
6 answers
2k views

inspired by this post. Consider 2 coworkers who work Monday - Friday, every week of every year, with no breaks or national holidays. On day n (day, month and year), worker 1 asks worker 2 their ...
Themoonisacheese's user avatar
12 votes
3 answers
582 views

Imagine an infinite symmetrical triangle of pegs, where the rows have size 1, 2, 3, ... (similar to Pascal's Triangle). All the pegs are red apart from k (your ...
user1502040's user avatar
  • 4,190
22 votes
2 answers
2k views

The task is to find parameters that make a fast leap year check correct for the widest range of years. We assume the Proleptic Gregorian calendar, which extends the Gregorian calendar backward from ...
Falk Hüffner's user avatar
14 votes
5 answers
750 views

Output a grid of characters visualizing the decomposition of a number into a sum of four perfect squares. Challenge Given a nonnegative integer \$0 \le n \le 2^{30}\$, output a \$2^k \times 2^k\$ ...
bb94's user avatar
  • 3,898
0 votes
2 answers
292 views

Challenge This challenge is based on the domino effect: Initially, each domino is located on one straight line and is in a vertical state. It can be dropped either to the left along the same straight ...
Michael's user avatar
  • 11
4 votes
1 answer
687 views

Consider an \$n \times n\$ grid of integers. The task is to draw a straight line across the grid so that the part that includes the top left corner sums to the largest number possible. Here is a ...
Simd's user avatar
  • 3,167
4 votes
5 answers
1k views

Here is a challenge: What is the shortest possible compiled program? Writing one line programs are fun, but they often lean on language libraries that get pulled into the final bits. How lean can you ...
Roger Hill's user avatar
1 vote
0 answers
229 views

There is a question to basically find the largest sum in an array, such that no two elements are chosen adjacent to each other. The concept is to recursively calculate the sum, while considering and ...
BlazeRod11's user avatar
17 votes
19 answers
6k views

The bots are looking for love. Can you help them? The rules The goal of this game is find the bot you have the highest compatibility with. However, robots, who are inexperienced at dating are unable ...
mousetail's user avatar
  • 14.4k
3 votes
0 answers
221 views

I'm working from home and the heat of my laptop on my lap is the only thing keeping me warm. I have a Dell G3 Laptop with an NVidia GEForce GTX CPU. I have tried writing a rust program with 5 threads ...
Blue7's user avatar
  • 139
6 votes
2 answers
1k views

In this game, you can look inside one box at a time chosen by you. When you do that, you can see how many coins there are in that box. The wizard has one last twist for you. At any point, you can ...
user avatar
4 votes
0 answers
312 views

You want to write your English essay. However, all characters on your keyboard broke other than the arrow keys and the enter key. You want to find out how to place the characters so you can write your ...
Command Master's user avatar
6 votes
1 answer
2k views

This challenge requires integration with C, so you can stop reading if you're not interested. Matrix multiplication is a simple operation, but the performance depends a lot on how efficiently the code ...
xiver77's user avatar
  • 2,395
11 votes
7 answers
759 views

Given two sets of strings, \$ D \$ and \$ R \$, find the shortest string which contains every string in \$ D \$, but contains none of the strings in \$ R \$. There are almost always multiple possible ...
pxeger's user avatar
  • 25.3k
19 votes
8 answers
2k views

Given a string, like potatocarrot, break it into the smallest number of substrings possible. These substrings can consist either be a single character, or one of a ...
rydwolf's user avatar
  • 19.3k
13 votes
2 answers
517 views

It's laundry day, and you have lots of clothes that need to be washed. Wanting to have as much time left over for code golf as possible, you hope to optimize how quickly you wash and dry them all. You ...
rydwolf's user avatar
  • 19.3k
15 votes
12 answers
2k views

There are times when a large number of people need to choose something. They all want to get the stuff they choose, obviously, but it's impossible to please everyone that way, so a usual compromise is ...
ophact's user avatar
  • 3,184
3 votes
2 answers
319 views

Modern hardware can perform multiplication very fast in a constant latency of 3~4 cycles. But some tiny chips for embedded environments sometimes lack hardware multiplication, which has to be emulated ...
xiver77's user avatar
  • 2,395
22 votes
4 answers
813 views

An "Egyptian fraction" is a list of distinct fractions with a numerator of \$1\$. For example: \$ \frac 1 1+ \frac 1 2 + \frac 1 3 + \frac 1 6 \$ The "size" of an Egyptian ...
Wheat Wizard's user avatar
  • 103k
12 votes
6 answers
1k views

This challenge is inspired by the High throughput Fizz Buzz challenge. The goal Generate a list of prime numbers up to 10,000,000,000,000,000. The output of primes should be in decimal digits followed ...
xiver77's user avatar
  • 2,395
32 votes
10 answers
5k views

You may know the game The Six Degrees of Kevin Bacon, based on the conjecture that every actor in Hollywood can be connected to Kevin Bacon by no more than 6 "co-star" relations, so Kevin ...
pxeger's user avatar
  • 25.3k
14 votes
21 answers
2k views

I'm designing a new space station for generic super-villain purposes (something something megalaser), but I'm having trouble designing the solar panels. My genius team of scientists can calculate ...
Mayube's user avatar
  • 11.8k
26 votes
27 answers
3k views

Story My local pizza delivery introduced new discount. You get 50% discount from every second item on your order. But being greedy capitalists, they forgot to mention that they will rearrange items ...
talex's user avatar
  • 927
7 votes
2 answers
398 views

Background Consider an \$n\times n\$ grid, where each cell is either empty (denoted by .) or a wall (denoted by #). We say that ...
Delfad0r's user avatar
  • 6,276
18 votes
7 answers
1k views

This code-challenge is based on OEIS sequence A261865. \$A261865(n)\$ is the least integer \$k\$ such that some multiple of \$\sqrt{k}\$ is in the interval \$(n,n+1)\$. The goal of this challenge is ...
Peter Kagey's user avatar
  • 8,165
4 votes
2 answers
443 views

Your program should take two lists, where each entry (a positive integer) represents the number of members of some group, as input. These lists will have the same sum but may have different lengths. ...
user1502040's user avatar
  • 4,190
2 votes
0 answers
79 views

Here's an interview question I've seen on a few sites. People claim that an O(n) solution is possible, but I've been racking my brain these last 2 days and I couldn'...
Ram Rachum's user avatar
8 votes
3 answers
631 views

You are given an array \$A\$, which may contain duplicate elements. In each swap, you may swap the value of any two indices \$i, j\$ (i.e. switch the values of \$A_i\$ and \$A_j\$). What is the least ...
user avatar
19 votes
1 answer
1k views

The challenge How well can you gerrymander North Carolina into 13 voting districts? In this challenge, you use the following files to draw different maps for Republicans and Democrats. File 1: ...
Dustin G. Mixon's user avatar
11 votes
2 answers
1k views

The challenge Find the smallest feedforward neural network such that, given any 3-dimensional input vector \$(a,b,c)\$ with integer entries in \$[-10,10]\$, the network outputs the largest (i.e., "...
Dustin G. Mixon's user avatar
18 votes
1 answer
1k views

The previous neural net golfing challenges (this and that) inspired me to pose a new challenge: The challenge Find the smallest feedforward neural network such that, given any 4-dimensional input ...
Dustin G. Mixon's user avatar
23 votes
2 answers
1k views

Can you imagine solving the New York Times crossword puzzle without any clues? Maybe not with all of the creativity and new words and phrases appearing in modern crosswords, but with a fixed word ...
A. Rex's user avatar
  • 2,617
18 votes
14 answers
2k views

Given a \$n\$-dimensional vector \$v\$ with real entries, find a closest permutation \$p\$ of \$(1,2,...,n)\$ with respect to the \$l_1\$-distance. Details If it is more convenient, you can use ...
flawr's user avatar
  • 44.1k
32 votes
6 answers
985 views

You have a bunch of heavy boxes and you want to stack them in the fewest number of stacks possible. The issue is that you can't stack more boxes on a box than it can support, so heavier boxes must go ...
Beefster's user avatar
  • 10k
6 votes
1 answer
714 views

Given two numbers in tape location #0 and tape location #1 in Brainfuck, compute their product into another tape location (specify with answer). Optimize for the least amount of time-units used, where ...
w33z8kqrqk8zzzx33's user avatar
27 votes
13 answers
3k views

Keeping this challenge short. You are given 4 numbers: p1, p2, p3 and p4. The magic sum of the numbers are defined as follows: ...
Koishore Roy's user avatar
  • 1,223
31 votes
2 answers
1k views

Background Recognizing primality seems like a poor fit for (artificial) neural networks. However, the universal approximation theorem states that neural networks can approximate any continuous ...
A. Rex's user avatar
  • 2,617
11 votes
4 answers
616 views

A flow network is a directed graph G = (V, E) with a source vertex s ϵ V and a sink vertex ...
user avatar
17 votes
3 answers
1k views

Background The traveling salesman problem (TSP) asks for the shortest circuit that visits a given collection of cities. For the purposes of this question, the cities will be points in the plane and ...
A. Rex's user avatar
  • 2,617
16 votes
1 answer
473 views

This is a code-challenge with a custom scoring system, where the lowest score wins. Introduction Many smartphones allow to enter text by swiping your finger across the 2D virtual keyboard. This ...
Arnauld's user avatar
  • 206k
16 votes
3 answers
587 views

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 ...
ბიმო's user avatar
6 votes
3 answers
328 views

You are given a list, L, with the length N. L contains N random positive integer values. You are only able to select from the outer edges of the list (left/right), and after each selection every value ...
feddy's user avatar
  • 61
26 votes
2 answers
1k views

Description Imaginary programming language (IPL) uses Polish Reverse Notation. It has the following commands: i -- input number and push it to the stack o -- non-destructive output top of the stack (...
Андрей Ломакин's user avatar
15 votes
6 answers
2k views

Challenge Given an integer n ≥ 4, output a permutation of the integers [0, n-1] with the property that no two consecutive integers are next to each other. The value of a permutation ...
user avatar
21 votes
11 answers
2k views

Your mission is to build an algorithm (program or function) that can optimize packing fruit from a conveyor belt into bags to be sent off to retailers, optimizing for a largest number of bags. Each ...
Angs's user avatar
  • 5,017
10 votes
1 answer
386 views

Given a set of items, each with a weight and a value, determine the number of each item to include in a collection so that the total weight is less than or equal to a given limit and the total value ...
user avatar
11 votes
2 answers
598 views

Inspired by The Great API Easter Egg Hunt! Summary Your task is to search for a predetermined integer in the "Collatz space" (to be explained later) using the fewest step possible. ...
Weijun Zhou's user avatar
  • 3,657
7 votes
4 answers
536 views

Introduction For a given rational number r, find a pair of integers p,q so that p/q=r and ...
Weijun Zhou's user avatar
  • 3,657