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?)

Filter by
Sorted by
Tagged with
3
votes
1answer
88 views

How can I speed up my calculations with loops? Python

I wrote this code. But it works very slowly. I'm figuring out how many times I have to run the case generator to find numbers less than or equal to inv, in this case six. I count the number of ...
2
votes
1answer
38 views

A prime number checker (Multi numbers).py

so obviously this SIMPLE code checks if the number is prime or not. I need to make it more advanced, easier to use, fewer lines or any improvement. ...
5
votes
4answers
4k views

Project Euler #5 (LCM of 1-20)

Challenge: 2520 is the smallest number divisible by 1 to 10 without any remainder. What is the smallest positive number that is evenly divisible by 1-20? Solution: ...
8
votes
2answers
324 views

Probability that Three Pieces Form a Triangle

I wrote some code to estimate the solution to the following problem: If you break a line segment at two random points, what is the probability that the new line segments can form a triangle? The ...
2
votes
1answer
45 views

Binomial Expansion Calculator

So i wrote a program with the documentation for my fx cg50 calculator's micropython to calculate various items, each of which are: Pascal Triangle Entry Pascal Triangle Level/Entire Row Binomial ...
5
votes
0answers
38 views

Sequence and Series Calculator

The Sequences & Series involved are Arithmetic and Geometric. stores and allows you to calculate using these given formulas and import fractions into micropython Support for micropython! ...
2
votes
3answers
65 views

Efficiently calculate the value of an arithmetic sequence

I need to calculate the value for the following function: $$f(n) = -1 + 2 - 3 + ... + -1^n$$ The time limit to calculate a given value of \$n\$ is less than 1 second. My approach does not meet that ...
5
votes
1answer
141 views

Scan-line algorithm to fill in a triangle

I wrote the following script to fill a Triangle. ...
2
votes
1answer
51 views

Converting an equirectangular image to a cubemap

I've written a program that does three things: Take an equirectangular image and ... ... cut horizontally-overlapping image areas. ... fill the image from the bottom with black so it has a ratio of 2:...
2
votes
2answers
65 views

Exponentiation by squaring in x64 Linux Assembly

I am learning some assembly for a compiler project I am working on and I have come across the Exponentiation by Squaring algorithm when it came to calculating x ^ n. To get a grasp on how the ...
1
vote
0answers
34 views

Code is timeout - Hamming Number

I have a problem with my code, because his is required a long time to be done(only when I put big numbers like 2000)... I am trying to do the Hamming Numbers kata on codewars.com: A Hamming number is ...
2
votes
1answer
62 views

Determine if points are within a rotated rectangle

Using only Python 2.7 and the standard library (no imports): Determine if a point is inside the rotated rectangle. ...
1
vote
1answer
59 views

Integer pairs of a product in Python

This bit of code is looking for the pair of integers that make up a product. You can input any integer and it returns the pairs of numbers that, when multiplied together, make it up. I have done a ...
6
votes
2answers
336 views

Quadratic Expression Factorer and Solver

I have decided to create a program that can factor and solve quadratic expressions in micropython, where the standard library is limited, and i have no idea how to implement external modules onto it, ...
4
votes
1answer
46 views

A Level Statistics Calculator/Helper For A Casio Fx-CG50 Calculator's MicroPython

I have made a program for my calculator's micropython, that can solve various a level statistics questions for me. However due to the limitations of the ...
7
votes
1answer
617 views

Convert Decimal to Fraction

This code below converts number from decimal to fraction. I don't know if there's a better way or better methods to do this job so any advice would be appreciated. ...
2
votes
1answer
207 views

Quadratic equation solver in Ruby

I wrote a simple quadratic equation solver with Ruby to help me solve quadratic equations. Please tell me what I did right or wrong, and what I can do to improve it. ...
2
votes
1answer
64 views

Euler Transform on Leibniz Series of Pi

So i read about simple series for Pi named Leibniz Series for Pi. Here is its Link:- Series . I made a program for it and soon realised that it converges very slows . So i did Euler accelerate for ...
1
vote
1answer
41 views

Recursive Function to Produce Constrained List of Integer Partitions

I have modified a recursive function designed to print all the integer partitions of a positive integer to create a function that returns all partitions of the "number" parameter if they ...
5
votes
2answers
172 views

Find the best matching combination of numbers

I need to manipulate chunks quantity until total will be as close as possible to the ...
2
votes
1answer
43 views

Finding the lowest perfect square that can be added to a number to make another perfect square

The code below returns the smallest perfect square that can be added to a number n to result in a perfect square. It works perfectly fine but I need it to run ...
4
votes
1answer
45 views

A library of 2D Shapes with functions for their intersections

The goal was as much code reuse as I could get. Shooting for a pure-function-y style. Would love any feedback on general architecture, adherence to standard practice and usability - as well as ideas ...
12
votes
3answers
320 views

MMMRjs a product of BYTES Genesis

We have published a product today called MMMR.js this product is licensed under the MIT license and is built by Syed Mohammad Sannan. The uniqueness of this product is that it is built with and for ...
3
votes
1answer
45 views

Python's OOP for Calculating Growth of Money

I am making an OOP to calculate growth of money according to theory of interest. I have made 3 classes: Contribution which contain data of a deposit and its growth, ...
3
votes
0answers
39 views

How to simplify the following distance function for the taxicab ring metric space?

Consider the taxicab ring metric space shown below. This is a discrete metric space in which we have both a grid and concentric diamond rings. This metric space stretches infinitely in all four ...
1
vote
0answers
29 views

Solving the game of 24 recursively in APL

The "game of 24" as I called it in the title is a maths game in which you are given four numbers and have to combine them in an expression using only the four basic arithmetic operations <...
4
votes
2answers
103 views

Factoring and solving a quadratic polynomial

So i code stuff for my fx-cg50 calculator's micropython as I'm an a level student and a python beginner, and i need help pointing out the bugs and some programming tips to further improve my code, and ...
4
votes
2answers
1k views

Project Euler Problem 21 in Python: Summing amicable numbers

Let d(n) be defined as the sum of proper divisors of n (numbers less than n which divide evenly into n). If d(a) = b and d(b) = a, where a ≠ b, then a and b are an amicable pair and each of a and b ...
1
vote
1answer
67 views

C - Division from scratch

I wrote this code where division can be done without using C's builtin operator: ...
7
votes
1answer
69 views

Python - A Numeric Matrix Calculator/Processor

it's the second object oriented program i've worked on, more details on https://hyperskill.org/projects/96?goal=391. I've added as much documentation as needed, as a first time, to explain each ...
4
votes
1answer
39 views

Convolution function

I implemented the following function using the matrix object from breeze library. Basically it is just a glorified while loop. The convolution there is extremely ...
15
votes
4answers
2k views

Calculator in C++

I made a calculator in C++. I wanted to ask is this code well written, understandable, and alright. ...
1
vote
1answer
48 views

Solving roots of negative numbers

As part of an assignment for college summer classes, I was tasked with writing a program that solves roots of negative numbers. I've ran it through the test cases I was provided and it computes ...
1
vote
1answer
41 views

Multiplying by certain elementary symmetric polynomials

Let me preface this with saying that it's probably not necessary to understand all the math behind this to review my code. Unless you have a lot of spare time or a very strong interest I also wouldn't ...
1
vote
1answer
74 views

A Credit Payment Calculator

So I've attempted this project from hyperskills where you're asked to make a calculator script that can calculate annuity and differentiated payments given that 3 of 4 values are known. I think i went ...
1
vote
0answers
26 views

Vectorization of Mersenne Twister? [closed]

Ahoy friends. Right now i'm selling a huge amount of HDDs and usually i used DBAN or nwipe to perform this actions. Unfortunately the PRNG Mersenne Twister is quite slow, so i get a throughput of ...
0
votes
1answer
61 views

Simple math library in Rust

So, I've tried to make a simple math library in Rust. What do you think about it? ...
3
votes
2answers
3k views

Google Foobar bomb_baby

This is the question I am facing at level 3 of Google Foobar: There are two types: Mach bombs (M) and Facula bombs (F). The bombs, once released into the LAMBCHOP's inner workings, will ...
2
votes
0answers
37 views

Division safe from overflow for fixedpoint

So I was investigating overflow safe division for a class that uses an int64 member with a given RESOLUTION ( 10000 ) for the fractional part. To preserve precision in the fractional part during an ...
11
votes
2answers
1k views

Calculating pi using bash

I've written a little program to calculate pi using the Nilakantha series: For this formula, take three and start alternating between adding and subtracting fractions with numerators of 4 and ...
2
votes
1answer
47 views

Graphing various mathematical functions in Python

1) This code's task is to create graphs of various algebraic, logarithmic and trigonometric functions and relations using Python's matplotlib.plyplot module. ...
6
votes
2answers
9k views

Finding greatest value in array smaller than x

Code review requested to make this code simpler, cleaner, and better. Input array is sorted. This program finds the greatest number smaller than x. So, in an ...
4
votes
1answer
75 views

Simulated annealing for magic square-of-squares puzzle

I'm working on a function that takes in a NumPy array containing only mutually distinct positive square numbers. I want the function to pick an element at random, find if there is a lower positive ...
4
votes
2answers
56 views

Python: Function to Find 2 Closest Points Among [x,y] Coordinates

I'm writing some code in Python that takes a set of [x,y] coordinates (in a list of tuples) and also an x-value. I need to find the two closest x coordinates to my x-value. To find the closest x, I ...
3
votes
1answer
26 views

Statistics Calculator for Listed and Grouped Data

I made a statistics calculator based on raw data for my Edexcel IAL Statistics 1 course which I'm going to use in my calculator's MicroPython. I would like some suggestions for ways to further improve ...
0
votes
1answer
50 views

Python extended Euclidean algortihm + inverse modulo

I programmed the extended Euclidean algorithm together with the inverse modulo because I am making an RSA system from scratch. Any feedback regarding efficiency etc. is welcome :) ...
2
votes
1answer
61 views

Compute the derivative of a function

1.11 Arranging the derivative of a function The derivative of any function f (x) at x0 can be estimated according to the following formula: Write a program that prints three columns of ...
3
votes
1answer
75 views

Rock Paper Scissors without arrays and if-statements, how to reduce

As working on a little private programming challenge, I tried "Rock Paper Scissors" without arrays or if-statements. It works as intended, though, I am sure this can be done a little bit more ...
3
votes
2answers
481 views

Extended Euclidean algorithm

I have programmed the extended euclidean algorithm. Is this a good approach? ...
1
vote
2answers
53 views

Binary exponentation with modulo

I have implemented binary exponentiation. Is this good? ...

1
2 3 4 5
11