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
20 votes
11 answers
2k views

Write a function that returns an iterable object of all valid points 4-directionally adjacent to (x, y)

A very common need in algorithms classes and computer science in general is to iterate 4-directionally over a grid or matrix (such as in BFS or DFS). This seems to often result in a lot of clunky and ...
NightDriveDrones'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
11 votes
2 answers
463 views

​Plane​ ​Blow​up​

The Blow-up is a powerful tool in algebraic geometry. It allows the removal of singularities from algebraic sets while preserving the rest of their structure. If you're not familiar with any of that ...
flawr's user avatar
  • 43.8k
27 votes
29 answers
5k views

Count the number of triangles

Given a list of positive integers, find the number of triangles we can form such that their side lengths are represented by three distinct entries of the input list. (Inspiration comes from CR.) ...
flawr's user avatar
  • 43.8k
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
7 votes
6 answers
602 views

The Knight's estate

And then the King said: You fought bravely, Knight, and your deed will not be forgotten for centuries. For your valor I grant you this castle and the lands around it. Things rush me, and I can not ...
Ver Nick's user avatar
  • 607
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
14 votes
2 answers
910 views

Counting generalized polyominoes

This challenge will have you count pseudo-polyforms on the snub square tiling. I think that this sequence does not yet exist on the OEIS, so this challenge exists to compute as many terms as possible ...
Peter Kagey's user avatar
  • 8,659
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
10 votes
2 answers
360 views

Partition and Restructure

Given two contiguous shapes of the same area, determine the optimal way to divide the first shape into a minimum number of contiguous segments such that they can be rearranged to form the second shape....
hyper-neutrino's user avatar
  • 41.4k
27 votes
7 answers
1k views

Expand a hexagon

Given an ASCII art hexagon as input, output one whose sides are all one unit longer. ...
xnor's user avatar
  • 144k
14 votes
15 answers
1k views

Dihedral group D4 composition with custom labels

The dihedral group \$D_4\$ is the symmetry group of the square, that is the moves that transform a square to itself via rotations and reflections. It consists of 8 elements: rotations by 0, 90, 180, ...
xnor's user avatar
  • 144k
11 votes
6 answers
5k views

Area of a 2D convex hull

You are given an array/list/vector of pairs of integers representing cartesian coordinates \$(x, y)\$ of points on a 2D Euclidean plane; all coordinates are between \$−10^4\$ and \$10^4\$, duplicates ...
Vladimir Reshetnikov's user avatar
8 votes
2 answers
374 views

Can this container hold this much liquid?

Can this container hold this much liquid? Challenge Synopsis As you most likely know, liquids have an indefinite shape and a definite volume. As such, they always take the shape of their container. ...
GMills's user avatar
  • 946
25 votes
4 answers
687 views

How lit is this room? 🔥 pt. 1

Related to this question. A room is defined to be a (not necessarily convex) non-intersecting polygon, expressed as an ordered list of 2-dimensional coordinates. A sufficiently bright lightbulb is ...
rigged's user avatar
  • 1,543
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
10 votes
1 answer
341 views

Count the Closed Polygons

Input: An NxM grid or multi-line string (or other reasonable input-format), containing only printable ASCII (unicode range ...
Kevin Cruijssen's user avatar
7 votes
1 answer
634 views

Hilbertize an image

For a computer vision app I want to do a mapping of an image, in such a way that every pixel fit hilbert curve, instead of conventional layout. So task could be as follows: Task description Given ...
xakepp35's user avatar
  • 313
20 votes
9 answers
2k views

Partitioning the grid into triangles

Goal The goal of this challenge is to produce a function of n which computes the number of ways to partition the n X 1 grid into ...
Peter Kagey's user avatar
  • 8,659
16 votes
9 answers
3k views

Drawing the Peano curve

Introduction In geometry, the Peano curve is the first example of a space-filling curve to be discovered, by Giuseppe Peano in 1890. Peano's curve is a surjective, continuous function from the unit ...
Peiffap's user avatar
  • 287
19 votes
8 answers
1k views

Is this quadrilateral cyclic?

In mathematics, a cyclic quadrilateral is one whose vertices all lie on the same circle. In other words, every vertex is on the circumcircle of the other three. For more information, see the MathWorld ...
lirtosiast's user avatar
  • 21.4k
23 votes
11 answers
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 ...
Pavel's user avatar
  • 9,367
3 votes
0 answers
211 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 ...
Mohamed Hadari's user avatar
8 votes
0 answers
172 views

Find a way to determine to which fibonacci squares a given coordinate belongs [closed]

Given a random coordinate (x,y), determine in which square (squares are referenced by their sidelength) it is (or the borders of which squares). The squares are drawn in a counter clockwise direction,...
Citronmelisa's user avatar
7 votes
2 answers
276 views

Drawing convex polyiamonds

Description OEIS sequence A096004 gives the Number of convex triangular polyominoes [polyiamonds] containing n cells. It begins: ...
Peter Kagey's user avatar
  • 8,659
10 votes
2 answers
405 views

Intersection Point of Two Line Segments

Given two line segments, determine if the line segments intersect and if so, where. In the case that the two given line segments are co-linear and overlap, determine the midpoint of the overlapping ...
Beefster's user avatar
  • 9,901
9 votes
14 answers
3k views

Draw a times table (also called modular multiplication circle) of a number \$n\$ with \$k\$ vertices

Not to be confused with this question. You need to draw a times table (also known as Cremona's method for cardioid generation) as shown in this video. The number \$n\$ and \$k\$ will be the inputs. ...
Agile_Eagle's user avatar
25 votes
6 answers
2k views

Two dozen kissing number approximations

Given a number from 1 to 24, output the kissing number to the best of current knowledge (some numbers will have more than one acceptable output). Knowledge of geometry is not essential as the outputs ...
trichoplax is on Codidact now's user avatar
1 vote
3 answers
353 views

Rounded Rectangles

Challenge Given an integer greater or equal to 4, n, print a rounded rectangle of as close as possible (with a gap of 1) sides and a perimeter of n characters. Rules n is always 4 or greater, ...
GammaGames's user avatar
  • 1,105
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
-2 votes
1 answer
231 views

Find the longest uninterrupted arc in N dimensions

See similar question for 2D case: Find the longest uninterrupted arc The challenge here is to find the longest uninterruped great circle arc around a unit hypersphere in N dimensions, with a random ...
F Chopin's user avatar
  • 269
11 votes
5 answers
516 views

Find the longest uninterrupted arc

The challenge here is to find the longest uninterruped arc around a unit circle with a random amount of points distributed in random positions around it. Here is a diagram to assist my explanation: ...
F Chopin's user avatar
  • 269
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
14 votes
10 answers
2k views

Area enclosed by perimeter loop

Find the area of a region of unit cells given its perimeter loop as a sequence of 90-degree turns. For example, take the three-cell region XX X whose perimeter ...
xnor's user avatar
  • 144k
14 votes
6 answers
987 views

Will you be my Weaver?

I've been recently playing through 'The Weaver' and I think it presents an interesting challenge for code-golf. Premise: The Weaver is a game wherein you are given a number of ribbons coming from 2 ...
Asone Tuhid's user avatar
  • 2,353
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
15 votes
13 answers
3k views

Circle intersection area

Description : Given x and y positions of two circles along with their radii, output the area ...
Muhammad Salman's user avatar
13 votes
21 answers
3k views

Distance between two points on the Moon

Given latitude/longitude of two points on the Moon (lat1, lon1) and (lat2, lon2), compute the distance between the two points in ...
mdahmoune's user avatar
  • 2,862
26 votes
9 answers
3k views

Largest rectangle in 2d array

Input The board: A 2D container (matrix, list of lists, etc.) of letters like: ...
danihp's user avatar
  • 361
15 votes
9 answers
1k views

Join up the rooms

So, here's a map of, let's say, a dungeon... ########## # ##### # ##### ########## ########## ########## ########## #### ## #### ## ########## Let's ...
AJFaraday's user avatar
  • 11.8k
15 votes
16 answers
900 views

Euler-Poincaré-Characteristic of Polyhedra

Given a triangulation of the surface of a polyhedron p, calculate its Euler-Poincaré-Characteristic χ(p) = V-E+F, where ...
flawr's user avatar
  • 43.8k
12 votes
5 answers
709 views

Sparse Protractor

Given some positive integer n, design a protractor with the fewest number of marks that lets you measure all angles that are an integral multiple of ...
flawr's user avatar
  • 43.8k
6 votes
1 answer
486 views

Stereographic projection of polyhedra

You will create a program that generates the stereographic projection of polyhedra. In particular, to keep things simple, we'll only focus on n-chamfered dodecahedron. Given a natural number ...
Christopher King's user avatar
14 votes
3 answers
597 views

Code Golf Simulated Golf

Given a list of hole yardages, green sizes, a slice angle and a max distance, compute a golf score. Assumptions Earth is flat All greens are circular Slice angle will be between -45 and 45 degrees ...
Kelly Lowder's user avatar
  • 3,475
11 votes
2 answers
2k views

Solve a Rubik's Cube

Your challenge is to write a program to solve a 3x3x3 Rubik's Cube. This challenge is based on this one from 2013, rewritten to adhere to current community standards, and reposted with the original ...
MD XF's user avatar
  • 13.8k
13 votes
5 answers
401 views

Integer triangles with perimeter less than n

Definition An "integer triangle" is one with integer coordinates. For example the following triangle is an integer triangle: ...
Peter Kagey's user avatar
  • 8,659
22 votes
3 answers
872 views

​L​o​o​p​ ​I​t​

Note: The title of this question should be "Loop It", but because title needs to be at least 15 characters, there are some invisible spaces. This note is such that the challenge can be ...
flawr's user avatar
  • 43.8k
3 votes
1 answer
445 views

Maximum Area of a Polygon with Vertices of a Polygon [closed]

Rules Given a list of integer coordinates, l, with a length of at least 4, and an integer n such that n is smaller than the length of l (but at least 3), return the largest area of an n-sided polygon ...
0WJYxW9FMN's user avatar
  • 2,773
9 votes
1 answer
348 views

Find the smallest triangle encompassing the specified polygon

Input: An integer N which represents the polygon's vertices and a list of their x and y coordinates. Expected output: The smallest difference possible between the area of the(not necessarily convex) ...
McLinux's user avatar
  • 335
15 votes
2 answers
303 views

Program an Uncircularness Score

Your task is to program a mathematical function \$s\$, that takes a nonempty finite set \$A\$ of points in the 2D plane, and outputs an uncircularity score \$s(A)\$ that satisfies following properties:...
flawr's user avatar
  • 43.8k

1 2
3
4 5
8