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
319 votes
24 answers
46k views

Write Moby Dick, approximately

Here is a 1.2Mb ASCII text file containing the text of Herman Melville's Moby-Dick; or, The Whale. Your task is to write a program or function (or class, etc. -- see below) which will be given this ...
N. Virgo's user avatar
  • 7,254
192 votes
179 answers
20k views

What is the smallest positive base 10 integer that can be printed by a program shorter (in characters) than itself?

I think the question as above is clear, but just in case: Write a full program (not just a function) which prints a positive base 10 integer, optionally followed by a single newline. Qualifying ...
Arandur's user avatar
  • 1,939
56 votes
9 answers
10k views

Is this even a word?

Your should write a program or function that takes a 4-character string as input and outputs a value indicating if the string is an English word or not. You are allowed to make mistakes in 15% of the ...
randomra's user avatar
  • 20.8k
48 votes
5 answers
1k views

TryItOnquine Challenge

(based on this post and the ensuing discussion on chat -- also, much thanks to Dennis for TIO!) The Challenge Choose a language that's currently available on the TryItOnline site, for example ...
AdmBorkBork's user avatar
  • 43.3k
45 votes
1 answer
2k views

Minimal keystrokes needed to type a given text

We all know that programmers tend to be lazy. In order to maximize your free time, you decide to write a program that outputs a minimal number of keystrokes for text fed into it. Input: Text that has ...
TimWolla's user avatar
  • 1,950
43 votes
6 answers
2k views

Island Golf #1: Circumnavigation

This is the first in a series of Island Golf challenges. Next challenge Given an island in ASCII-art, output an optimal path to circumnavigate it. Input Your input will be a rectangular grid ...
DLosc's user avatar
  • 38.5k
42 votes
16 answers
4k views

How small can it get?

Starting with a positive integer N, find the smallest integer N' which can be computed by repeatedly dividing N by one of its digits (in base-10). Each selected digit must be a divisor of N greater ...
Arnauld's user avatar
  • 191k
36 votes
1 answer
2k views

Domino Circuits

Scoreboard Here are the raw scores (i.e. domino counts) for VisualMelon's submission. I'll turn these into the normalised scores described below, when more answers come in. The existing solution can ...
Martin Ender's user avatar
31 votes
10 answers
5k views

Who Is Kevin Bacon?

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
  • 23.5k
31 votes
2 answers
1k views

Can a neural network recognize primes?

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,579
31 votes
3 answers
954 views

Choose the last card in a poker hand

Poker hands are ranked from best to worst as follows: Straight flush - five cards of sequential rank, all of the same suit Four of a kind - four cards of the same rank and one card of another rank ...
Stewie Griffin's user avatar
30 votes
4 answers
807 views

Plurality Voting with Cellular Automata

There's a really important problem in cellular automata called the Majority problem: The majority problem, or density classification task is the problem of finding one-dimensional cellular automaton ...
PhiNotPi's user avatar
  • 29k
30 votes
3 answers
777 views

Heavy Box Stacking

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
  • 9,901
29 votes
9 answers
2k views

Uniquely separated pixels

For an N by N image, find a set of pixels such that no separation distance is present more than once. That is, if two pixels are separated by a distance d, then they are the only two pixels that are ...
trichoplax is on Codidact now's user avatar
29 votes
1 answer
866 views

Given a list of circles, output the area of the smallest containing rectangle

You will be given a list of radii, you must output the area of the smallest rectangle which they will all fit in. For example, given the list [5,3,1.5] you would ...
Tim's user avatar
  • 2,879
27 votes
13 answers
3k views

Make me a minimum magic sum

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,203
26 votes
27 answers
2k views

Hunt for discount

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
  • 711
26 votes
2 answers
1k views

Optimize Compiler for simple Reverse Polish Notation Programming Language

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
25 votes
10 answers
2k views

Efficient Robot Movement

Disclaimer: The story told within this question is entirely fictional, and invented solely for the purpose of providing an intro. My boss has gotten a new toy robot, and he wants me to help program ...
Gryphon's user avatar
  • 7,215
25 votes
4 answers
918 views

Minimum rectangle cover

Rectangle covers Suppose you have a matrix of bits, for example the following. 1 1 0 0 0 1 1 0 1 1 1 1 0 1 1 1 0 1 1 1 0 1 1 1 1 1 0 1 1 1 1 0 1 1 0 1 1 1 0 1 ...
Zgarb's user avatar
  • 42.6k
24 votes
2 answers
2k views

Compute the maximum number of runs possible for as large a string as possible

[This question is a follow up to Compute the runs of a string ] A period p of a string w is any positive integer ...
user avatar
23 votes
39 answers
1k views

Find the maximum deviation

This problem is "inspired" from a question that was originally asked on Quora (not for code golfing). I just want to make it a challenge for you guys (and my first problem submission here). Given an ...
todeale's user avatar
  • 383
23 votes
2 answers
1k views

Create a uniquely solvable crossword ... without clues

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,579
23 votes
5 answers
594 views

Trigger the chutes and protect the jackpot

You are going to participate in a gameshow. One of the challenges works as follows: The first room contains a large number of identical balls. The second room contains a series of chutes, each of ...
Peter Taylor's user avatar
  • 43.1k
23 votes
2 answers
964 views

Optimize sorting, using "Sub-vector reversals"

This is a fewest-operations challenge where the objective is to sort a vector into ascending order using the fewest reversals. Your algorithm can only sort the vector using "sub-vector reversals"1, ...
Stewie Griffin's user avatar
22 votes
14 answers
3k views

Find a maximal rectangle of 1s

Background I want to buy an plot of land and build my house on it. My house should be rectangular, and as large as possible; however, the available plots have lots of rocky areas that I cannot build ...
Zgarb's user avatar
  • 42.6k
22 votes
1 answer
652 views

Golfing Python string literals

Background Python 3 has many types of string literals. For example, the string this 'is' an exa\\m/ple can be represented as: ...
PurkkaKoodari's user avatar
22 votes
2 answers
1k views

Integer Linear Programming

Introduction Write a solver for integer linear programming. Challenge Your task is write a solver for integer linear programming (ILP). In ILP, linear inequalities of a set of unknowns (all of which ...
Weijun Zhou's user avatar
  • 3,627
21 votes
11 answers
2k views

Fruit bagging factory

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
  • 4,957
21 votes
3 answers
2k views

Piet (Mondrian)'s Puzzle

For more information, watch this video, and go to A276523 for a related sequence. The Mondrian Puzzle (for an integer n) is the following: Fit non-congruent ...
clismique's user avatar
  • 6,982
20 votes
7 answers
1k views

Optimize the Scralphabet

Scralphabet A normal bag of Scrabble tiles contains the following letters (? is a blank tile, which can stand for any other letter): ...
sirpercival's user avatar
  • 1,824
20 votes
4 answers
654 views

Egyptian fractions summing to n

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
  • 97.8k
20 votes
4 answers
595 views

"Finish work" as early as possible

Background Imagine for a moment that you have a mind-numbingly boring job. Every morning, you are given a collection of tasks that you should work on that day. Each task has a certain duration, and ...
Zgarb's user avatar
  • 42.6k
19 votes
8 answers
949 views

Optimal path through a matrix

Given a matrix consisting of positive integers, output the path with the lowest sum when traversing from the upper left element to the bottom right. You may move vertically, horizontally and ...
Stewie Griffin's user avatar
19 votes
8 answers
2k views

Optimally break a string into words

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 Programs's user avatar
19 votes
1 answer
2k views

Shortest 2-Player Game of Halma

In Chess, it's possible for the game to end after 4 moves (2 each) with a Fool's Mate. Your goal is to find the Fool's Mate of Halma: the 2-player game of Halma that minimises the number of turns ...
cardboard_box's user avatar
19 votes
2 answers
2k views

Compact a Befunge program

Befunge is a 2-dimensional esoteric programming language. The basic idea is that (one-character) commands are placed on a 2-dimensional grid. Control flow walks across the grid, executing commands it ...
Mechanical snail's user avatar
19 votes
4 answers
324 views

Remove letters while keeping strings unique

Inspired by this wonderful (based on the number of views and votes) challenge, which, in my humble opinion, has way too few answers. Given (by any means) a list of strings, return (by any means) a ...
Adám's user avatar
  • 30k
19 votes
1 answer
935 views

Gerrymander North Carolina

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
19 votes
2 answers
336 views

Island Golf #2: The Eccentric Hermits

This is the second in a series of Island Golf challenges. Previous challenge Two hermits have arrived on a desert island. Since they came seeking solitude, they wish to live as far away from each ...
DLosc's user avatar
  • 38.5k
19 votes
2 answers
3k views

Mastermind strategy

I could only find code-golf challenges for Mastermind, so here's a code-challenge version that I would have liked to take on myself. An optimal strategy for the normal Mastermind game, MM(4,6), was ...
MrBackend's user avatar
  • 406
19 votes
1 answer
720 views

Advent Challenge 1: Help Santa unlock his present vault!

Next >> Descriptive Keywords (for searching): Make Two Matrices Equivalent, Overlap, Array, Find Challenge Santa has had a history of elves stealing presents from his vault in the past, so this ...
hyper-neutrino's user avatar
  • 41.4k
18 votes
19 answers
5k views

The Dating Game / Secretary Problem

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
  • 12.4k
18 votes
14 answers
1k views

Permutations in Disguise

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
  • 43.8k
18 votes
7 answers
1k views

Square root multiples

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,659
18 votes
8 answers
681 views

Sort by shuffling blocks

Block shuffle sort The block shuffle sort is a (rather artificial) method of sorting a list. It works as follows, illustrated by an example. ...
Zgarb's user avatar
  • 42.6k
18 votes
1 answer
1k views

Sort with a neural network

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
18 votes
8 answers
1k views

1D Hopping Array Maze

Inspired by We do tower hopping and related to 2D Maze Minus 1D Introduction Your task is to find the shortest path to get out of an array maze following specified rules. Challenge A 1D array a with n ...
Weijun Zhou's user avatar
  • 3,627
18 votes
2 answers
486 views

Minifying math statements

The Challenge You are the owner of an amazing service called Coyote Beta, which magically answers math questions its users send to it over the internet. But it turns out, bandwidth is expensive. ...
TND's user avatar
  • 553