# Questions tagged [mathematics]

For code that aims to solve problems in all branches of mathematics. (Please do NOT use this tag for incidental trivial use of arithmetic. A simple test to apply is: would an amateur or professional mathematician take an interest in the question?)

445 questions
Filter by
Sorted by
Tagged with
37 views

### How to multiple variables rust? | error: expected one of ), ,, @, or |, found * [closed]

Log: ...
62 views

I was recently tasked to write an implementation of the Berlekamp–Massey algorithm (for GF2) from a given inductional proof and decided to fresh up on my Haskell, since converting a proof by induction ...
98 views

### Calculating every possible answer given a set of formulas

Problem Given a set of formulas (AKA "Rules"), get a list containing every possible answer that does not break any formula. Formula variables can have a maximum equal to the number of characters. ...
42 views

### Handling singularities in squircle parametric equations

In order to plot a squircle using its parametric equations: The equations can be found in page 9 of this this article: Fong, Chamberlain. "Squircular Calculations." arXiv preprint arXiv:1604....
56 views

### Get resulting rectangle from two overlapping rectangles

I have a function that creates a rectangle from two rectangles that overlap, I was wondering if there is a smarter way to do it purely mathematically rather than lots of ...
1k views

### Calculate the movement required to get from one angle to another angle on a compass

The goal of the function is to find out how to get from one angle to another angle. Two things are involved: the amount to move by and the direction (+ means turn right, - means turn left). The most ...
91 views

### 3 sum algorithm - Trying

Recently I started looking and refreshing about algorithms and decided to try to do the 3 sum algorithm. I did the code below: ...
69 views

53 views

### Modular multiplicative inverse in Ruby

I implemented an algorithm to find the modular multiplicative inverse of an integer. The code works, but it is too slow and I don't know why. I compared it with an algorithm I found in Rosetta Code, ...
83 views

### Sum of number's quotients when divided by exact powers of 2

Problem I have written code to solve this challenge: Given a formula: GCD(x,y) means the GCD (Greatest Common Divisor) of x and y. For example: if N=2, then: f(2) = 1/GCD(1,...
287 views

### Reverse int within the 32-bit signed integer range: $[−2^{31}, 2^{31} − 1]$ Optimized

LeetCode Problem Reverse digits of a 32-bit signed integer. When the reversed integer overflows return 0. Feedback Optimized from beta code in the original question here. Based on this LeetCode ...
92 views

### Shutting down all lamps with minimum number of switch presses

I found an optimization problem written in Finnish but I will translate it into English. The following is an example case. I have $n=120$ lamps in a circle, and enumerated by $L_1,…,L_{120}$. ...
62 views

### Optimising multiplication of matrix rows with matrix slice/page

I've recently vectorized most of the code for an optimization problem but this one still eludes me. As the procedure and not the actual values are important here, I have replaced the original matrices ...
246 views

### Python RSA/DSA File Cryptography, Key Generation, Key Protection

I have forked a previous version of my script, critiqued here: Generate public/private keys, encrypt, decrypt, sign, verify This program allows you to encrypt and decrypt raw files using RSA keys ...
90 views

### Project Euler, Problem 273: finding perfect-square partitions

Problem: Consider equations of the form: $a^2 + b^2 = N; 0 \leq a \leq b; a, b, N \in \mathbb{N}$. For $N=65$ there are two solutions: $a=1, b=8$ and $a=4, b=7$. We call \\$S(...
114 views

### PHP find cheapest permutation

I have multiple products that all have sizes and I need to find the cheapest configuration that meets the minimum required size. For example, John needs a minimum of 10 litres of storage - it can be ...
103 views

### Faster algorithm to tailor given mathematical expression

Is there a more optimized solution to solve the stated problem? Given an array 'arr' of 'N' elements and a number 'M', find the least index 'z' at which the equation gets satisfied. [ ] is ...
157 views

### Get n-th perfect number

The task: A number is considered perfect if its digits sum up to exactly 10. Given a positive integer n, return the n-th perfect number. For example, given 1, you should return 19. Given ...
92 views

### Finding the number of integers between 1 and K, who's sum of the digits is a multiple of D

Good day. So, I need to find the number of integers between 1 and K (inclusive) satisfying the following condition, modulo (10^9)+7: The sum of the digits in base ten is a multiple of D Here is my ...
148 views

### Automatic Differentiation with C++ Header-Only Library

Code review/feedback is requested and appreciated for the following open-source automatic differentiation C++ header-only library released under the Boost License. I am the author. https://github.com/...
717 views

### Balanced centrifuge configurations

Given an input N as the size of a centrifuge, I need to find out the number of balanced configurations. The full description is here. Centrifuge is a piece of ...