This challenge is intended to be solved by using, manipulating, or creating shapes or other geometric structures.

learn more… | top users | synonyms

6
votes
1answer
113 views

Test if a point is in an Icosahedron

Take as input 3 floating point numbers, which represent the x, y, z coordinates of a point. Return a truthy or falsey value indicating whether the point is inside the regular icosahedron centred at ...
13
votes
4answers
187 views

Compute the winding number

The winding number is the integer number of net counterclockwise revolutions an observer must have made to follow a given closed path. Note that any clockwise revolutions count negative towards the ...
19
votes
15answers
1k views

Hypercube elements

Write a function or program that outputs the number of each type of element (vertex, edge, face, etc.) of an N-dimensional hypercube. As an example, the 3 dimensional cube has 1 cell (i.e. 1 ...
18
votes
23answers
2k views

Distance between two points in n-dimensional space

Here is another simple one: The Challenge Given two points in an n-dimensional space, output the distance between them, also called the Euclidean distance. The coordinates will be rational ...
3
votes
4answers
166 views

Find our neighbors

You live in a rectangular neighborhood which is completely partitioned into N rectangular plots, i.e. there are no gaps or overlaps. Plots do not necessarily have the same width/height as other plots. ...
21
votes
15answers
3k views

Geometry is So Fun

Everybody loves geometry. So why don't we try and code golf it? This challenge involves taking in letters and numbers and making shapes depending on it. The Input The input will be in the form of ...
7
votes
5answers
689 views

Hypercube sides

Your goal is to output all the "sides" (corners, edges, faces, etc.) of an N-dimensional unit hypercube, where N is non-negative. A "side" is defined as any (N-M)-dimension surface embedded in ...
1
vote
2answers
158 views

Find the line guaranteed by Sylvester-Gallai

The Sylvester-Gallai theorem says: Suppose you have a finite list of points in the plane. Suppose further that not all of those points are collinear (lie in a single line). Then there is some line ...
32
votes
12answers
4k views

Toilet Paper Mysteries

Today you need to solve a very practical problem: How many loops do you need to have a certain number of sheets on your toilet paper roll? Let's look at some facts: The diameter of a bare toilet ...
20
votes
3answers
422 views

Putting square pegs into square holes

I was intrigued by the design of this graphic from the New York Times, in which each US state is represented by a square in a grid. I wondered whether they placed the squares by hand or actually found ...
16
votes
1answer
141 views

Finding Exclusive Area in Circle Intersections

Here's a deceptively challenging geometry puzzle for you! Given a circle A, and n other circles B[n], find the total area contained within A that is not within any circle of B. Your code should be ...
10
votes
0answers
140 views

Lego Gear Train

Inspired by the Lego gear ratios challenge by Keith Randall. I, too, plan on building a giant lego robot that will eventually be able to destroy the other robots in the never-before-mentioned ...
9
votes
3answers
381 views

Draw a Christmas Star / Stellated Dodecahedron

Paper stars are a big thing in my family at christmas, so I thought a virtual one would be cool. Below is an image of a regular dodecahedron (from https://en.wikipedia.org/wiki/Dodecahedron, ...
28
votes
16answers
2k views

How much present did you get for Christmas?

Yes, how much, not how many... As we all know, a large present is far better than a small one. Therefore, the value of the presents should always be measured in total volume, not number of presents, ...
16
votes
2answers
284 views

Playing Billiards

In this code golf, you will have to determine the direction of the shortest shot that hits exactly n cushions before falling into a pocket. The billiard table is a 6 pocket pool table with the ...
3
votes
3answers
108 views

Most logical rectangle formula from numbers [duplicate]

Introduction The task is simple. When given a number, output the most logical rectangle. To explain what a logical rectangle is, I provided some examples: Input: 24. All possible rectangles have ...
16
votes
3answers
432 views

Rolling the Dice

Rolling the Dice So, I was rolling dice a while ago and thought of a challenge. Given the cube with a net taken from input and a list of moves, find the square on the bottom at the end. I will ...
10
votes
4answers
319 views

Point in convex hull (2D)

Background The convex hull of a finite number of points is the smallest convex polygon that contains all of the points, either as vertices or on the interior. For more information, see this question ...
17
votes
1answer
332 views

Random Golf of the Day #6: Roll a d20

About the Series First off, you may treat this like any other code golf challenge, and answer it without worrying about the series at all. However, there is a leaderboard across all challenges. You ...
3
votes
0answers
76 views

Is it a Regular Polygon? [closed]

A regular polygon is a polygon that is equiangular (all angles are equal in measure) and equilateral (all sides have the same length). Your job is to find out if a given polygon is regular or not. ...
51
votes
1answer
606 views

Sprocket Science: Animating a Chain Drive System

The goal of this challenge is to produce an animation of a chain drive system, comprised of a set of sprocket gears connected together by a chain. General Requirements Your program will be given a ...
90
votes
70answers
14k views

Draw the national flag of France

There have been many other flag challenges posted but not one for the national flag of France. This week seems like an appropriate time. Produce this flag in the fewest bytes possible: The image ...
13
votes
2answers
279 views

Spherical excess of a triangle

Spherical excess of a triangle As we all know, the sum of angles of any planar triangle is equal to 180 degrees. However, for a spherical triangle, the sum of angles is always greater than 180 ...
12
votes
13answers
689 views

Square side pinpointing

Welcome to my first code-golf challenge! :) Let's hop right into it. Challenge: Given two floating point vectors, O (origin) and T (target), you have to create a program to print the values L and R ...
16
votes
7answers
755 views

Print a Pentomino Rectangle

Write a program or function that takes no input but prints or returns a constant textual depiction of a rectangle made of the 12 distinct pentominoes: The rectangle may have any dimensions and be ...
1
vote
3answers
217 views

Area of Polygon [duplicate]

Given the number of vertices N of a convex polygon and each of their (x, y) calculate the polygon's area. vertexes are in clockwise order You must handle all N <= 45 ,-600 <= x,y <= 600, ...
20
votes
8answers
797 views

Circular ​Blues

Write a program or function that takes in a positive integer N and recreates this pattern of circles scaled to fit an N×N pixel image: This image is a valid output example for N = 946. In ...
9
votes
7answers
210 views

Print a cube's vertices and it's covering triangles

Output coordinates of the vertices of a cube. Then, output a list of 12 triangles that will cover the cube, each triangle being a list of three vertex-indexes, consistently oriented. Output must be an ...
15
votes
17answers
2k views

Area of the triangle

Another easy challenge for you. Your task Write a program or function that takes the input, which contains 3 pairs of x- and y-coordinates and calculates the area of the triangle formed inside them. ...
37
votes
8answers
2k views

Can I Slide Apart The Puzzle?

Write a program or function that takes in a rectangular grid of text where every cell is either an A or a B. All the A cells will form a simply-connected shape, i.e. they will all be orthogonally ...
15
votes
3answers
376 views

Regular Polygrams

Given the number of vertices n ≥ 3 and the "step size" 1 ≤ m < n/2 (indicating the distance between two connected vertices), output a graphical representation of the corresponding regular ...
13
votes
5answers
283 views

Is it L-convex?

Background A polyomino is called L-convex, if it's possible to travel from any tile to any other tile by an L-shaped path, that is, a path that goes in the cardinal directions and changes direction ...
2
votes
1answer
197 views

Measuring Rectangles

Challenge Your goal is to write a program which will output the 8 measurements of a rectangle, with only some measurements in the input. Your program should throw an error if it cant be done. Here ...
27
votes
7answers
2k views

Beatles Songs and Hexagons

Write two triangle (i.e. pyramid) shaped programs. The first one should be an upwards pointing text triangle with a minimum base width of three characters. So it would have a structure like X XXX ...
13
votes
5answers
1k views

Pyramid Schemes

Mayan pyramids were (and are) an important part of ancient architecture, that were generally used for religious purposes. They were usually step pyramids, but the steps on each were too steep to ...
16
votes
1answer
319 views

Cut a pizza into identical slices

This is what I thought this question was going to be, before I fully read it. A group of code golfers walk into The Nineteenth Bite Pizzeria and order a pizza. It comes in an irregular shape, made ...
30
votes
12answers
4k views

Visually Explain the Pythagorean Theorem

A common visual explanation of the Pythagorean theorem is as such: The squares are meant to represent the side length's squared, and the areas of a + b = c, just like the Pythagorean theorem says. ...
39
votes
7answers
1k views

Dennis, Doorknob, Martin Büttner, Chris Jester-Young - Pizzeria!

Programming Puzzles & Code Golf is about to get a new moderator, Dennis! This challenge is a tribute to him and our other active (or recently active) moderators: Doorknob, Martin Büttner, and ...
13
votes
1answer
344 views

Can I make that shape with blocks, slabs, and stairs?

Consider a rectangular two-dimensional grid where each cell can either be empty (.) or full (0). e.g. ..00.... 0000.... .00000.. 000...00 ..000000 000.00.. The grid is considered infinite, all ...
7
votes
1answer
248 views

Computing the geometric median

Given a list of integer points in an n-dimensional space, output the geometric median. Note that the output is not necessarily integer. Your answer must be precise to at least two digits after the ...
28
votes
1answer
673 views

Find the area of the largest convex polygon

Given a list of integer coordinates, find the area of the biggest convex polygon you can construct from the list such that - every vertex is in the list no element of the list is contained within ...
13
votes
11answers
2k views

Empty a Swimming Pool . . . With Only a Red Solo Cup

You have a swimming pool that is filled to the brim with water. You need to empty it, but you can't think of an efficient method. So you decide to use your red solo cup. You will repeatedly fill the ...
15
votes
5answers
1k views

Find the nearest clock hands

Challenge Given a number of seconds past midnight, output the smallest angle between any two hands on a clock face, using as few bytes as possible. You may assume that the number of seconds is ...
16
votes
13answers
553 views

Find the reference angle

This is a fairly simple question. According to this random website I found, a reference angle is the acute angle formed by the terminal side of the given angle and the x-axis. You have to write a ...
7
votes
3answers
346 views

Integral triangles and integral medians

Consider a triangle ABC where each side has integer length (an integral triangle). Define a median of ABC to be a line segment from a vertex to the midpoint of the opposing side. In the figure below, ...
7
votes
1answer
426 views

Go south, east and north, come to the same place

There is that famous riddle: A bear walks 1 km south, 1 km east and 1 km north, and comes to the place it started from. What color is the bear? This one is very old, so I'll generalize it: A ...
9
votes
4answers
390 views

Calculate the Orthocenter of a Triangle [duplicate]

Try to write the shortest program or function you can that prints or returns the calculated orthocenter of a triangle. The orthocenter of a triangle is the intersection point of the three altitudes ...
4
votes
2answers
211 views

Cut a silicon wafer into dies

When manufacturing chips, circular silicon wafers are cut into dies of needed size: The goal of this challenge is maximizing the number of whole dies that can be cut from a wafer of a given ...
20
votes
3answers
749 views

Stacking Pythagorean Triangles

Background A Pythagorean triangle is a right triangle where each side length is an integer (that is, the side lengths form a Pythagorean triple): Using the sides of this triangle, we can attach ...
15
votes
2answers
450 views

Worst Case Manhattan Exclusion

Imagine a W by H grid of squares that wraps toroidally. Items are placed onto the grid as follows. The first item can be placed on any square, but subsequent items must not be within a Manhattan ...