All Questions
Tagged with c# mathematics
51
questions
5
votes
2
answers
263
views
C# console app that computes the Jaccard Index
So I wrote a basic C# console application that computes the Jaccard Index. This has its applications in cybersecurity and machine learning. Given two sets X and Y, the basic formula is:
$$ J(X, Y) = \...
1
vote
0
answers
147
views
Interleave Bits Generically
This commonly referenced "bit twiddling" site has an interesting algorithm for interleaving the bits of two 32-bit integers. Here is my attempt at completely generalizing the algorithm using ...
2
votes
2
answers
133
views
generate prime factors via wheel factorization
I want to factor random values of n that range from uint.MinValue to uint.MaxValue as ...
4
votes
2
answers
204
views
32-bit deterministic Miller-Rabin primality test
Are there any ways in which this code could be improved? I'm particularly interested in the ModularExponentiation function as it is the primary bottleneck during ...
5
votes
4
answers
4k
views
Dividing two numbers then handle the divide by zero exception with try/catch
I am new to coding, I hope you can help me to improve my code :)
First of all: The code works correctly.
...
3
votes
1
answer
336
views
Generic Integer Square Root
I have implemented an integer square root function that is branch-free and runs in constant time, using the first variant found in this answer as a base. All possible values for the types ...
2
votes
1
answer
267
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
1
answer
413
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 ...
6
votes
1
answer
747
views
C# random math questions project
I made a C# console math project where the user answers addition, subtraction, multiplication, division, power or square-root questions based on the difficulty they choose!
However, I am struggling ...
2
votes
2
answers
463
views
C# maths quiz with user choosen difficulty-level
I have built a maths project that asks the user an addition, subtraction, multiplication, division, power and square root questions based on the difficulty level they choose!
But I am trying to ...
6
votes
4
answers
263
views
All your Base - Exercism.io
This is an exercise on the website Exercism. I am self taught trying to learn C# and C++. This is the information from the readme.
Convert a number, represented as a sequence of digits in one base,...
4
votes
1
answer
524
views
Solving a linear system with two variables
Background:
Equation 1: 2x-y=6
Equation 2: 4x+3y=22
Because 1 is ax-by=c and 2 is dx-ey=f
y=(a * f - c * d) / (a * e - b * d) and x is simply (c - (b * y)) / a)
What I am trying to do:
...
3
votes
4
answers
8k
views
C# Code to Find all Divisors of an Integer
I made this so I can feed it integers and return an array with all the divisors of that integer. I put checks in in case the integer is less than 2. Order of integers in the array must be smallest ...
3
votes
2
answers
470
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 ...
3
votes
2
answers
126
views
Project price of publicly traded contract
I have to project the price for a publicly traded contract when the price should be approximately matching the targeted profit or loss. I have written the following code, runs under 0.02ms.. could be ...