Questions tagged [geometry]

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

Filter by
Sorted by
Tagged with
169 votes
8 answers
36k views

Draw an Image as a Voronoi Map

Credits to Calvin's Hobbies for nudging my challenge idea in the right direction. Consider a set of points in the plane, which we will call sites, and associate a colour with each site. Now you can ...
Martin Ender's user avatar
141 votes
27 answers
24k views

Appease Your Google Overlords: Draw the "G" Logo

Write a program or function that takes in a positive integer N, and outputs an N×N pixel image of Google's "G" logo according to this* construction: For example, if N is 400, a 400×...
Calvin's Hobbies's user avatar
121 votes
16 answers
17k views

Implement the Game of Life on Anything but a Regular Grid

Conway's Game of Life is (almost) always played on a regular square grid, but it doesn't need to be. Write a program that implements the standard cell neighboring rules from Conway's Game of Life on a ...
Calvin's Hobbies's user avatar
112 votes
87 answers
27k views

Draw the national flag of Iceland

This year's UEFA Euro 2016 is over and besides a couple of negative headlines there has been a very positive surprise as well – the Iceland national football team. Let's draw their national flag. ...
insertusernamehere's user avatar
106 votes
96 answers
23k 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 must ...
steve's user avatar
  • 2,394
105 votes
3 answers
4k 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 ...
Ell's user avatar
  • 7,687
65 votes
16 answers
11k views

Draw the € sign

The goal is to output or display an image with an € (euro) sign according to the following specs (ignoring the border of the sign). Source: http://en.wikipedia.org/wiki/File:Euro_Construction.svg ...
A.L's user avatar
  • 1,288
60 votes
11 answers
15k views

Draw the South Korean flag

When I stumbled upon this question I remembered that I had also once seen precise rules for the construction of the South Korean flag. And this is quite a different construction. Source: Wikipedia ...
Martin Ender's user avatar
58 votes
10 answers
10k views

Little Chandler is sad. Draw him a cloud to cheer him up

Little Chandler is sad. Draw him a cloud to cheer him up. Note: Drawing a cloud won't actually cheer him up. A circle can be defined as a 3-tuple (x,y,r) where <...
absinthe's user avatar
  • 8,629
51 votes
31 answers
9k views

Covering a Skyline with brush strokes

Given a non-negative integer skyline height list, answer how many uninterrupted 1-unit-high horizontal brush strokes are needed to cover it. [1,3,2,1,2,1,5,3,3,4,2]...
Adám's user avatar
  • 29.9k
50 votes
81 answers
10k views

Is my triangle right?

Given a, b, c the length of the three sides of a triangle, say if the triangle is right-angled (i.e. has one angle equal to 90 degrees) or not. Input Three positive ...
mdahmoune's user avatar
  • 2,862
47 votes
37 answers
8k views

Draw the Ionising Radiation Hazard Symbol

Draw the ionising-radiation-hazard-symbol in an arbitrary colour on a distinctly coloured background. The specific proportions were published in the June 27th 1974 issue of the Federal Register of the ...
flawr's user avatar
  • 43.8k
47 votes
3 answers
4k views

Construct a pentagon avoiding compass use

Rules You will start with only two elements: Points \$A\$ and \$B\$ such that \$A \neq B\$. These points occupy a plane that is infinite in all directions. At any step in the process you may do any ...
Wheat Wizard's user avatar
  • 97.6k
45 votes
9 answers
2k 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 ...
Calvin's Hobbies's user avatar
44 votes
26 answers
10k views

Random point on a sphere

The Challenge Write a program or function that takes no input and outputs a 3-dimensional vector of length \$1\$ in a theoretically uniform random direction. This is equivalent to a random point on ...
Jitse's user avatar
  • 6,896
44 votes
9 answers
5k views

Build a triangle without any triangles

As a little kid, I liked to play with these toys a lot: They probably intended for these to be used for art, but I always used them for math! Fractals, patterns, etc. One time, I was given this ...
DJMcMayhem's user avatar
43 votes
44 answers
5k views

The Crow vs The Taxicab

Imagine travelling to a point lying A miles away horizontally and B miles away vertically from your current position. Or in other words, travelling from (0, 0) to ...
DJMcMayhem's user avatar
43 votes
6 answers
3k views

​P​i​ =​= ​3​.​2​

Inspired by this video of Infinite Series. Introduction Pi is defined as the ratio of the circumference to the diameter of a circle. But how is a circle defined? Usually a circle is defined as the ...
flawr's user avatar
  • 43.8k
43 votes
5 answers
3k views

Block Building Bot Flocks!

The contest is over! Intro This is an interactive king-of-the-hill contest where the controller is fully contained in a Stack Snippet at the bottom of the question. The controller automatically ...
Calvin's Hobbies's user avatar
40 votes
22 answers
9k views

Check if point lies inside triangle

Your goal is to determine whether a given 2D point X lies within the area of the triangle with given vertices A,B,C. Write a function that takes in the coordinates of the test point X and the three ...
xnor's user avatar
  • 144k
40 votes
13 answers
3k views

Volumes of ASCII boxes

Introduction In this challenge, you are given as input the ASCII representation of the net (unfolded surface) of a rectangular cuboid (3D box). The format is this: ...
Zgarb's user avatar
  • 42.5k
39 votes
21 answers
7k views

Angle between the hands on a clock [duplicate]

Given the time in 24 hour format (2359 = 11:59pm) return the angle between the minute and hour hands on a standard clock (on the ...
Dan McGrath's user avatar
  • 1,007
39 votes
4 answers
3k views

Addition on Elliptic Curves

Disclaimer: This does not do any justice on the rich topic of elliptic curves. It is simplified a lot. As elliptic curves recently got a lot of media attention in the context of encryption, I wanted ...
flawr's user avatar
  • 43.8k
38 votes
21 answers
5k 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 ...
Maltysen's user avatar
  • 25.7k
38 votes
8 answers
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 ...
Calvin's Hobbies's user avatar
37 votes
19 answers
3k views

Chebyshev Rotation

Consider a regular grid, where each cell has integer coordinates. We can group the cells into (square-shaped) "rings" where the cells in each ring have the same Chebyshev distance (or ...
Martin Ender's user avatar
37 votes
14 answers
5k 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 ...
geokavel's user avatar
  • 6,656
36 votes
41 answers
5k views

Evaluate the aspect ratio of a triangle

Given three sidelengths of a triangle, evaluate its aspect ratio AR given the following formula: where The closer to equilaterality a triangle is, the closer to 1 ...
Fatalize's user avatar
  • 38.5k
36 votes
15 answers
3k views

Triangular Lattice Points close to the Origin

Background A triangular grid is a grid formed by tiling the plane regularly with equilateral triangles of side length 1. The picture below is an example of a triangular grid. A triangular lattice ...
Bubbler's user avatar
  • 74.9k
34 votes
9 answers
3k views

I really wanted a rhombus, but all I got was this stupid rectangle

Given only a straightedge and compass, inscribe a rhombus inside the given rectangle, sharing two opposite points. Input Input is the dimensions of the rectangle. In the example shown, that would be <...
Geobits's user avatar
  • 19.7k
34 votes
3 answers
2k views

Placing circles along a square spiral

In this code golf challenge, you'll be computing the placement of (open) circles of areas \$\pi, 2\pi, 3\pi, \dots\$ when greedily placed along integer points in a square spiral in such a way that no ...
Peter Kagey's user avatar
  • 8,659
34 votes
4 answers
4k views

The happy Ender problem

The happy ending problem (actually a theorem) states that Any set of five points in the plane in general position has a subset of four points that form the vertices of a convex quadrilateral. The ...
Luis Mendo's user avatar
  • 104k
34 votes
1 answer
1k views

Gasket Weaving - draw a Sierpiński knot

Given an integer N >= 2, produce an image showing a Sierpiński knot of degree N. For example, here are knots of degree 2, 3, 4 and 5: Click on the images to view full size (the higher the degree the ...
trichoplax is on Codidact now's user avatar
33 votes
27 answers
4k views

Circumference of an ellipse

Challenge Unlike the circumference of a circle (which is as simple as \$2\pi r\$), the circumference (arc length) of an ellipse is hard. Given the semi-major axis \$a\$ and semi-minor axis \$b\$ of an ...
Bubbler's user avatar
  • 74.9k
32 votes
3 answers
5k views

Area of a Self-Intersecting Polygon

Consider a potentially self-intersecting polygon, defined by a list of vertices in 2D space. E.g. ...
Martin Ender's user avatar
32 votes
21 answers
3k 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, ...
Stewie Griffin's user avatar
31 votes
26 answers
3k views

Draw HyperNeutrino's benzene hegaxon icon in ASCII

In celebration of HyperNeutrino getting back his account and rep, following Mr. Xcoder. Apologies for rotating the picture for drawability. Print or output this ASCII art exactly. You may have ...
xnor's user avatar
  • 144k
31 votes
8 answers
2k views

Area of an ASCII polygon

You should write a program or function which receives a string representing an ascii-art polygon as input and outputs ot returns the area of the polygon. The input is a string consisting of the ...
randomra's user avatar
  • 20.8k
31 votes
1 answer
665 views

Fishing for Cube Nets

Cubes can be made of six squares as sides. But you could also fold three 2x1 rectangles in half and glue them together to form a cube. Now in this challenge you get a set of pieces which are each made ...
flawr's user avatar
  • 43.8k
30 votes
19 answers
10k views

Shortest Code to randomly place points and connect them

The Task This is quite a simple coding task, all your program has to do is place a point on a canvas (or your alternative in another coding language) and connect it to all the dots already placed. ...
Alexander Craggs's user avatar
30 votes
8 answers
3k 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 ...
Calvin's Hobbies's user avatar
30 votes
7 answers
7k views

Golf the smallest circle!

The problem: Given a non-empty set of points in the Cartesian plane, find the smallest circle that encloses them all (Wikipedia link). This problem is trivial if the number of points is three or ...
Barranka's user avatar
  • 432
30 votes
4 answers
796 views

A Dog on a Chain

I'm looking out of my attic window into my neighbor's yard. They have a dog chained to a post in the center of the yard. The dog runs around the yard but is always on the end of its chain, so it ...
Wheat Wizard's user avatar
  • 97.6k
30 votes
3 answers
2k views

Golf the smallest sphere!

Inspired by this challenge, as well as a problem I've been working on Problem: Given a non-empty set of points in 3D space, find the diameter of the smallest sphere ...
10GeV's user avatar
  • 371
29 votes
50 answers
5k views

Diamond creator +

Challenge : Given an integer n as input. Create a diamond that is 2x the given number n. Input : Input is integer ...
Muhammad Salman's user avatar
29 votes
38 answers
4k views

Normalize a Vector

To normalize a vector is to scale it to a length of 1 (a unit vector), whilst keeping the direction consistent. For example, if we wanted to normalize a vector with 3 components, u, we would first ...
FlipTack's user avatar
  • 14.6k
29 votes
6 answers
9k views

Let's draw the flag of Nepal

Nepal’s flag (Wikipedia, Numberphile) looks very different from any other. It also has specific drawing instructions (included in the Wikipedia article). I want you guys to make a program which will ...
ST3's user avatar
  • 1,369
29 votes
8 answers
5k views

Billiard balls collision

Given the 2-dimensional positions and velocities of a pair of billiard balls right before impact, calculate their velocities after a perfectly elastic collision. The balls are assumed to be ideal ...
ngn's user avatar
  • 15.2k
29 votes
4 answers
1k views

Smallest region of the plane that contains all free n-ominoes

On Math Stack Exchange, I asked a question about the smallest region that can contain all free n-ominos. I'd like to add this sequence to the On-Line Encyclopedia of Integer Sequences once I have ...
Peter Kagey's user avatar
  • 8,659
29 votes
3 answers
836 views

Squarefinder – Locating regular tetragons

Imagine a bunch of rectangles drawn in the plane, each rectangle with its vertices at integer coordinates and its sides parallel to the axes: The rectangles partition the plane into a number of ...
Sp3000's user avatar
  • 61.8k

1
2 3 4 5
8