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
1
vote
0answers
54 views

Coin Flip Streaks script

I am attempting to complete the coin flip streaks problem from automate the boring stuff with python. My code works fine but my only concern is the phrasing of the task. Does the question want us to ...
0
votes
0answers
30 views

Going in a direction, relative to the keys pressed and horizontal camera angle? [closed]

If you're confused by some parts here, I am just treating booleans as integers, 0 being false and 1 being true, but I'm wondering if there is a way to get rid of ...
4
votes
2answers
117 views

Generate prime factorisations of factorial numbers

The code was written to generate the factorisation of numbers into primes in ascending order. E.g 3! ='2 * 3', 4!='2^3 * 3'. When I have huge numbers such as 100!, the run time becomes a problem. I ...
1
vote
1answer
32 views

“Backwards Read Primes” of Codewars powershell version

Link to problem: https://www.codewars.com/kata/5539fecef69c483c5a000015/train/powershell I have a working solution in Codewars but my solution is slow for some reason and I need to improve the ...
2
votes
0answers
28 views

Gradient descent algorithm for solving localization problem in 3-dimensional space

Task This code accomplishes the Time Difference of Arrival (TDoA) multilateration problem (see) using gradient descent (known otherwise as steepest descent). Goal I'm looking to: a) Improve speed: In ...
0
votes
0answers
56 views

Great-circle distance in Java

Today's assignment states that I need to write a complete java program which will calculate the relative orthodromic distance between two sets of geographic coordinates declared by the user. When the ...
8
votes
2answers
355 views

Square roots via Newton's method in Java

This time, one of my labs state that I need to write a complete java program which will calculate the square root of a number via Newton's method. The reason behind using Newton's method, as opposed ...
2
votes
0answers
23 views

Data Visualization (rendering env)

How can I improve this code? It renders a ML env with openAI gym and matplotlib. I am new to coding so not sure if my variables or format or any lines can be improved. ...
9
votes
5answers
2k views

Efficiently find all the Pythagorean triplets where all numbers less than 1000

How can I make this code run faster: ...
8
votes
4answers
466 views

“Kinda” addition chain calculator

I build an addition chain (more information about addition chains: Wikipedia) calculator that produces shorter chains than chains with the length equal to the number that's being tried to achieve. It ...
7
votes
2answers
58 views

Python - Input Filtering, Calculating with a Variable Amount of Inputs

I've been working on an Aerodynamics calculator using python (which I'm relatively new at), In this program, a value can be calculated based on multiple different inputs ie. a calculates b, b ...
2
votes
1answer
53 views

Improving performance of function to multiply vector with a matrix?

I wrote this function to multiply vector with a matrix and I was wondering if someone experienced can spot something can improved its performance. ...
4
votes
0answers
123 views

A Very Simple Support Vector Machine with SMO Algorithm Implementation

Context. I was looking for some simple implementation of SVM with the SMO algorithm that can be used as an in-class problem together with a simple mathematical explanation of how it works. The problem ...
3
votes
1answer
139 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
41 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
0answers
43 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
1answer
68 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 ...
2
votes
3answers
74 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 ...
2
votes
1answer
58 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
75 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 ...
5
votes
1answer
164 views

Scan-line algorithm to fill in a triangle

I wrote the following script to fill a Triangle. ...
1
vote
0answers
42 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
73 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. ...
6
votes
2answers
349 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, ...
1
vote
1answer
60 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 ...
7
votes
1answer
636 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
69 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 ...
4
votes
1answer
46 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 ...
5
votes
2answers
173 views

Find the best matching combination of numbers

I need to manipulate chunks quantity until total will be as close as possible to the ...
4
votes
1answer
70 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 ...
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
44 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
31 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 <...
1
vote
1answer
44 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 ...
1
vote
1answer
67 views

C - Division from scratch

I wrote this code where division can be done without using C's builtin operator: ...
3
votes
1answer
50 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 ...
7
votes
1answer
93 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
41 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
51 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 ...
12
votes
3answers
322 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 ...
8
votes
2answers
327 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 ...
1
vote
1answer
92 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
63 views

Simple math library in Rust

So, I've tried to make a simple math library in Rust. What do you think about it? ...
2
votes
0answers
39 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 ...
1
vote
1answer
43 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 ...
2
votes
1answer
50 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. ...
4
votes
1answer
82 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
61 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 ...

1
2 3 4 5
11