If n is the numerator and d the denominator of a fraction, that fraction is defined a (reduced) proper fraction if and only if GCD(n,d)==1.
For ex...
For further actions, you may consider blocking this person and/or reporting abuse
Rust:
Two beers for the
numcrate (forgcd) :)A Javascript solution:
Test cases:
This is a pretty straight-forward solution using a counter. You can run this in vscode terminal as
node [file-name].jsThe number of proper fractions is the number of numbers in 1 .. N-1 that are coprime with N, i.e. whose greatest common divisor with N is 1.
My first time writing in Golang, managed to figure out the basic syntax.
For testing
Clojure:
A Swift solution:
Output:
Had to implement a GCD function, as I didn't find one in the standard Swift library(if anyone knows different, let me know!)
Otherwise pretty straight forward, choose to go with brute force for-loop and a counter, as I found after some testing the array functions like .filter() / .map() / .reduce() are SCARY slow...
Scala
Not much going on. Generate a sequence with all the numbers between
1andn - 1which greatest common denominator withnis one and get the length of that sequence.Tests
Elixir:
Tests: