Questions tagged [math]

The challenge involves mathematics in some central way. Also consider using more specific tags, listed in the tag wiki info.

Filter by
Sorted by
Tagged with
9 votes
3 answers
1k views

Output a 1-2-3-5-7... sequence

Follow-up of my previous challenge, inspired by @emanresu A's question, and proven possible by @att (Mathematica solution linked) For the purposes of this challenge, a 1-2-3-5-7... sequence is an ...
Tbw's user avatar
  • 1,735
14 votes
13 answers
1k views
+200

Output a 1-2-3 sequence

For the purposes of this challenge, a 1-2-3 sequence is an infinite sequence of increasing positive integers such that for any positive integer \$n\$, exactly one of \$n, 2n,\$ and \$3n\$ appears in ...
Tbw's user avatar
  • 1,735
17 votes
4 answers
2k views

Draw a Fibonacci Swoosh

Title courtesy of Greg Martin For this challenge, I'll define an arc of size \$k\$ as a single piece of a sine wave with a length of \$k\$ units and an height of \$\frac{k}{4}\$ units: And I'll ...
emanresu A's user avatar
  • 37.8k
6 votes
12 answers
905 views

Argument of a complex number (Robbers)

V1.1: Added criterion to help with tiebreakers, a bit overkill but still.V1.2: It's April 15th! Task: Crack the scrambled code for calculating the argument of a complex number \$z=x+iy\$ given two ...
CrSb0001's user avatar
  • 361
10 votes
23 answers
2k views

Argument of a complex number (Cops)

This is the cop's thread, where one should post the scrambled code. Here is the robbers' thread where the cracked source should be posted and linked to the cop's answer. NB: I am currently writing up ...
CrSb0001's user avatar
  • 361
14 votes
7 answers
2k views

How quickly can you type this unary string?

If I want to type the string aaa, the least keystrokes I can type it in is 3: a a a. But if I want to type the string ...
emanresu A's user avatar
  • 37.8k
7 votes
2 answers
245 views

Convert maximum values to bit widths

Background The newest version of the C standard, C23, adds preprocessor macros like INT_WIDTH, ULONG_WIDTH, and ...
Tavian Barnes's user avatar
12 votes
14 answers
1k views

Lattice points visible from the origin

Challenge Create a program that outputs a square grid showing visible and non-visible points \$(x, y)\$ from the origin based on their greatest common divisor (GCD). A point \$(x, y)\$ is considered ...
vengy's user avatar
  • 2,163
18 votes
26 answers
2k views

Is it a tetrate of two?

The tetration operation consists of repeated exponentiation, and it is written ↑↑. For instance, 3↑↑3 =3 ^(3^3) = 3^27 = 7,625,597,484,987 A tetrate of two is an ...
isaacg's user avatar
  • 42k
12 votes
6 answers
1k views

Contract a tensor

Introduction Tensor contraction is an operation that can be performed on a tensor. It is a generalization of the idea of the trace of a matrix. For example, if we have a rank-2 tensor (a matrix) and ...
Tbw's user avatar
  • 1,735
11 votes
10 answers
1k views

Egyptian fraction representations of 1 without prime denominators

Background As noted in this question, for all positive integers \$n>2\$ there exists at least one Egyptian fraction representation (EFR) of \$n\$ distinct positive integers \$a_{1} < a_{2} < \...
Max Muller's user avatar
15 votes
12 answers
810 views

Sum up snail number neighbours

Input: You are given two numbers n and m. Create the snail: Given an n >= 3, fill an <...
Philippos's user avatar
  • 2,501
14 votes
13 answers
1k views

Counting rankings

There is a competition with \$n\$ participants in total. Alice is one of the participants. The outcome of the competition is given as a ranking per participant with a possibility of ties; e.g. there ...
Bubbler's user avatar
  • 76k
3 votes
4 answers
639 views

Fastest count of certain hypercubes with labeled vertices

CHALLENGE This is a fastest-code challenge. Count how many n-dimensional hypercubes with n=1,2,3,4 exist, with vertices labeled with either 1 or 0, such that there does not exist any rectangle formed ...
Fabius Wiesner's user avatar
4 votes
5 answers
390 views

Generate a sequence of \$n\$ consecutive composite numbers

Definitions The common methods to generate consecutive composites are $$\overbrace{(n+1)! + 2, \ (n+1)! + 3, \ \ldots, \ (n+1)! + (n+1)}^{\text{n composites}}$$ $$\overbrace{n!+2,n!+3,...,n!+n}^{\text{...
vengy's user avatar
  • 2,163
1 vote
8 answers
288 views

Alternating Random Series Sum To \$N\$ [closed]

Challenge Given a positive integer \$N \ge 3\$, generate an alternating series of \$N\$ random numbers within the range \$[1, N]\$, such that their sum equals \$N\$. Expressed mathematically as $$N = ...
vengy's user avatar
  • 2,163
-2 votes
8 answers
1k views

Number of cigarettes that can be made from a given number of butts

Assumption A cigarette can be made by combining four cigarette butts. Cigarette butts last infinitely until smoked. Explanation Say you have 31 butts. That means, you can make 7 cigarettes from 28 ...
Siddharth Singh's user avatar
12 votes
20 answers
1k views

Modular Equivalence

Given two numbers \$x,y > 2, x≠y \$ output all integers \$m\$ such that $$ x + y \equiv x \cdot y \pmod m $$ $$ x \cdot y > m > 2 $$ Input Two integers Output A list of integers Test cases <...
pacman256's user avatar
  • 3,760
13 votes
19 answers
1k views

The TAK function (easy mode)

The TAK function is defined as follows for integers \$x\$, \$y\$, \$z\$: $$ t(x, y, z) = \begin{cases} y, & \text{if $x \le y$} \\ t(t(x-1,y,z), t(y-1,z,x), t(z-1,x,y)), & \text{otherwise} \...
Bubbler's user avatar
  • 76k
18 votes
7 answers
1k views

The TAK function

The TAK function is defined as follows for integers \$x\$, \$y\$, \$z\$: $$ t(x, y, z) = \begin{cases} y, & \text{if $x \le y$} \\ t(t(x-1,y,z), t(y-1,z,x), t(z-1,x,y)), & \text{otherwise} \...
Bubbler's user avatar
  • 76k
13 votes
20 answers
2k views

Complete a Mystery Sequence

Given a sequence of three integers, determine if the sequence is arithmetic (of the form [a, a+d, a+2*d]) or geometric (of the form ...
nyxbird's user avatar
  • 313
7 votes
10 answers
960 views

Make 1's and 2's composite

Input An integer k composed of 1 and 2, with at least 3 digits and at most 200 digits. ...
Sunny Lu's user avatar
  • 419
4 votes
25 answers
2k views

Consecutive Composite Numbers

Challenge Generate \$n-1\$ consecutive composite numbers using this prime gap formula $$n!+2,n!+3,...,n!+n$$ Input An integer \$n\$ such that \$3 \leq n \leq 50 \$. Output Sequence of \$n-1\$ ...
vengy's user avatar
  • 2,163
17 votes
19 answers
1k views

Ellipse Lattice Point Counter

Challenge Determine how many integer lattice points there are in an ellipse $$\frac{x^2}{a^2} + \frac{y^2}{b^2} \leq 1$$ centered at the origin with width \$2a\$ and height \$2b\$ where integers \$a, ...
vengy's user avatar
  • 2,163
-6 votes
1 answer
173 views

Where to stand to throw circles over sticks

Consider a horizontal line with vertical lines centered on the x-axis and placed at gaps of \$\sqrt{2}/2\$. For a positive integer \$n \geq 3\$, the first half of the lines have lengths \$0, \sqrt{2},...
Simd's user avatar
  • 2,896
15 votes
21 answers
2k views

Divmod continuously until the remainder is 1 or 0, then get the remainder

The task is simple, divide, get the quotient and the remainder, and if the remainder isn't 1 or 0, do the same thing (quotient divmod remainder) until the remainder is 1 or 0, then get the remainder. ...
Fmbalbuena's user avatar
  • 3,847
10 votes
12 answers
1k views

Counting Collinear Points

Given two points \$(x_1, y_1)\$ and \$(x_2, y_2)\$ with integer coordinates, calculate the number of integer points (excluding the given points) that lie on the straight line segment joining these two ...
vengy's user avatar
  • 2,163
1 vote
1 answer
509 views

Find the optimum circle in an infinite grid

Consider an \$n \times n\$ grid of integers which is part of an infinite grid. The top left coordinate of the \$n \times n\$ grid of integers is \$(0, 0)\$. The task is to find a circle which when ...
Simd's user avatar
  • 2,896
11 votes
20 answers
5k views

Calculate 500 digits of e

Write a program to calculate the first 500 digits of the mathematical constant e, meeting the rules below: It cannot include "e", "math.e" or similar e constants, nor may it call ...
Simd's user avatar
  • 2,896
9 votes
3 answers
474 views

Coin sequence probability

Given two strings containing only 0 and 1, decide the probability that first appears earlier as a consecutive substring in an ...
l4m2's user avatar
  • 23.8k
16 votes
2 answers
583 views

Construct this point

Given a constructible point \$(x, y) \in \mathbb R^2\$, output the steps required to construct \$(x, y)\$ Constructing a point Consider the following "construction" of a point \$(\alpha, \...
caird coinheringaahin g's user avatar
19 votes
9 answers
977 views

Output an infinitely proportional sequence

In this challenge, an infinitely proportional sequence is defined as a infinite sequence of positive integers such that: All positive integers are contained infinitely many times within the sequence. ...
emanresu A's user avatar
  • 37.8k
7 votes
3 answers
194 views

Inscribe a maximal regular polygon into a square image

You want to draw a regular polygon but you have limited space! In this challenge, you should draw a polygon with n sides which is as big as possible for a given square container image. I found ...
anatolyg's user avatar
  • 13.6k
18 votes
24 answers
2k views

Test whether a sequence is bitonic

You know what a monotonic sequence is: each element is bigger than its predecessor (monotonically rising) or as its successor (monotonically falling). Bitonic means you have two arms of the sequence, ...
Philippos's user avatar
  • 2,501
13 votes
7 answers
2k views

Auto-golf an esolang

The lack of a social life drove a poor nerd into inventing another superfluous esolang called !+~%. For no good reason it initializes the accumulator with ...
Philippos's user avatar
  • 2,501
-2 votes
11 answers
591 views

Print 100 digits of Champernowne's Constant

Inspired by this and this question Challenge Your challenge is to print any 100 consecutive digits of Champernowne's Constant. You must give the index at which that subsequence appears. The 0 at the ...
CrSb0001's user avatar
  • 361
14 votes
17 answers
3k views

What's the character limit of this text field? [duplicate]

Someone I know has no coding experience, but has proposed an algorithm* to determine the character limit of text fields they find online. They copy a string containing the numbers from 1 to 1,000 ...
Luke Sawczak's user avatar
10 votes
7 answers
1k views

Night hike partitioning

We want to go on a night hike with the youth group, but of course not everyone has their torch, even though we told them we planned to split up. What options are there for group formation if n teens ...
Philippos's user avatar
  • 2,501
16 votes
16 answers
4k views

Which skill to train?

Story (skip, if you prefer the naked task): You need five skills for an imaginary sport: Speed, strength, endurance, accuracy and tactics. If you achieve a score in each of these disciplines, you can ...
Philippos's user avatar
  • 2,501
4 votes
1 answer
217 views

Convert real numbers between factoradic and positive integer bases

This prompt asked you to convert back and forth to factoradic, but is very limited in scope (only decimal integers from 0 to 10!-1). Your task in this challenge is to reach just a bit further and ...
guest4308's user avatar
  • 467
1 vote
0 answers
140 views

Produce a secure block cipher round function (1 bit round key; 7 bit message)

We need to produce a block cipher round function with a 1 bit round key size and a 7 bit message size with the highest level of cryptographic security according to our measure of security. ...
Joseph Van Name's user avatar
9 votes
8 answers
671 views

Produce the shortest suffix for an (almost) arbitrary string

I encountered some silly code from a game and I figured this would actually turn into a fun golfing problem, so: Given any ASCII string in the limited char range specified below. Append as few ...
Olipro's user avatar
  • 199
12 votes
6 answers
2k views

Sine using square root [closed]

Given input \$x \in \left\{0,3,6,...,90\right\}\$, output \$\sin\left(x°\right)\$ using integer and \$+ - \times \div ( ) \sqrt{\cdot}\$(square root), e.g. \$\sin(45°)=\sqrt{1\div 2}\$. Flexible ...
l4m2's user avatar
  • 23.8k
17 votes
14 answers
2k views

Finding the power sandwich version 2

Introduction This question is inspired by this great question. Challenge Given a number \$N>0\$, output the largest integer \$a^b\$ that is smaller or equal to \$N\$, and the smallest integer \$c^d\...
Dmitry Kamenetsky's user avatar
15 votes
16 answers
2k views

Finding the power sandwich

Introduction Finding the closest power to a number is a common enough problem. But what if you need both the next-highest and next-lowest power? In this challenge you must find the closest powers to a ...
calvenable's user avatar
10 votes
6 answers
422 views

Hermite interpolation

We already have a challenge for polynomial interpolation: given a list of points, output the coefficients of the polynomial that passes through them. Hermite interpolation is a generalization of ...
alephalpha's user avatar
14 votes
10 answers
1k views

Expected number of rounds for this labeling scheme

Task Here is an interesting math problem: Let's say that there are \$n\$ indistinguishable unlabeled objects in a bin. For every "round", pull \$k\$ objects randomly out of the bin with ...
Aiden Chow's user avatar
  • 13.3k
9 votes
5 answers
524 views

Write a variadic fixed point combinator

A fixed-point combinator is a higher order function \$\mathrm{fix}\$ that returns the fixed point of its argument function. If the function \$f\$ has one or more fixed points, then $$\mathrm{fix} f=f(\...
Legendary Wizard's user avatar
3 votes
2 answers
342 views

Visualise the Euclidean GCD [duplicate]

The Euclidean GCD Algorithm is an algorithm that efficiently computes the GCD of two positive integers, by repeatedly subtracting the smaller number from the larger number until they become equal. It ...
emanresu A's user avatar
  • 37.8k
16 votes
18 answers
2k views

Divisor chain counts (1 3 3 7 ...)

The divisors of a natural number form a poset under the relation of "a divides b?", \$a | b\$. This challenge is to produce the number, \$C\$, of non-empty chains of such posets for natural ...
Jonathan Allan's user avatar

1
2 3 4 5
37