Skip to main content

All Questions

Tagged with
7 votes
3 answers
3k views

Calculator of combinations without repetition

I am interested to find an absolute value (not an approximation) of "combination without repetition" for given \$n\$ and \$k\$, or \$\binom{n}{k}\$. The brute force solution would look like this <...
pgs's user avatar
  • 922
8 votes
1 answer
691 views

Lagrange Interpolation over quadrilateral points

I've been working on a program which calculates, given a point and 4 surrounding points, the Lagrange polynomial, in order to interpolate a value. Consider that I'm not a mathematician and I better ...
Dan's user avatar
  • 131
1 vote
2 answers
968 views

Find coprime numbers less than n

I get the coprime numbers less than n with the following algorithm: ...
A.M's user avatar
  • 119
7 votes
2 answers
2k views

Class Matrix implementation

Following the 18.06 Linear algebra course, I was curious to reinvent the matrix class and basic functionality, like \$PA=LU \$ decomposition, Gauss elimination, finding inverse matrix etc. Any ...
pgs's user avatar
  • 922
6 votes
4 answers
612 views

Pascal Triangle calculation with BigIntegers

On a well known programming challenges website(CW) there is a Kyu2 eggs height problem that can be solved utilizing a variation of Pascals Triangles properties. The problem asks to solve ...
Miguel_Ryu's user avatar
4 votes
1 answer
645 views

Method to return center items in a 2D array

I wish to have code that returns the center items of a 2d grid. Because I need an average value. The code I came up with does what I want (see the unit tests beneath it). But I think the code is ugly ...
Mike de Klerk's user avatar
4 votes
1 answer
211 views

Rare binary numbers

Rare numbers are the natural numbers in their binary forms in which there aren't two (or more) ones next to each other. Make a program that will give the N. rare number! For example: In case of N =...
Howard Fring's user avatar
3 votes
5 answers
2k views

Absolute Values and Fractions

$$ \frac{|x|-|y|}{1+|xy|} $$ How can I reduce the amount of code without losing quality? What are your tips? Your comments on the structure, logic, in general, everything. How to make the type of ...
Aleksey Nikolaev's user avatar
-2 votes
3 answers
180 views

Find target sum of 3 from and array

Input is a sorted array and a target sum. Find all sets of 3 unique elements that sum to a target. Looking for lowest order (big O). A, B, C are the indexes on the sorted array. A < B < C ...
paparazzo's user avatar
  • 6,016
7 votes
2 answers
861 views

Optimizing special cases of modulo

I have a use case where improvements to the speed of calculating modulo for 64 bit integer dividends makes a significant difference in overall processing time. The divisor isn't known statically - it ...
quentin-starin's user avatar
2 votes
2 answers
672 views

Convert a double to a string containing rational and surd

First off, code: ...
Happypig375's user avatar
8 votes
1 answer
3k views

Generating Uniformly Distributed Random Numbers

Edit: Dunno what PCG is and don't want to read the paper? Maybe this video of Melissa O'Neill (the author) explaining things will be palatable instead. Original: I attempted to answer this question ...
Kittoes0124's user avatar
  • 1,940
10 votes
2 answers
248 views

Resizing a discrete uniform CSRNG distribution

I have a requirement to generate a uniform distribution of cryptographically secure random numbers. To generate these numbers I only know of the ...
Peilonrayz's user avatar
  • 43.4k
4 votes
2 answers
4k views

Calculating distance and angle between two points, C# program

I like to think I'm an intermediate programmer, but I learned to code with the Unity engine so I'm still getting used to not using it, and I've never had someone review my code before. I don't know ...
Kyle Freeman's user avatar
7 votes
2 answers
182 views

Sum of the reciprocals of whole numbers adding to one

I have written some code which works out which sums of reciprocals of whole numbers sum to one, e.g: \$\frac 12 +\frac 13 +\frac 16 =1 \$ \$\frac 17 +\frac 18 +\frac 19 + \frac1{10} + \frac1{11}+ \...
user124568's user avatar

15 30 50 per page