Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

musical /prog/ challange

Name: Anonymous 2010-09-22 14:03

Create an ordered list of fractions which product of the numerator and denominator equals a specific integer n.

ex: n=60
1/60, 2/30, 3/20, 4/15, 5/12, etc....

then do it with a list of integers.

If you are fancy you can also create a scale from the fractions you've got which best matches western tempered tuning (or any you prefer).

Name: Anonymous 2010-09-22 23:35

Java is faster than C++

derp:prog $ cat ProgChallengeFactor.java
>>16

derp:prog $ cat ProgChallengeFactor.cpp
#include <iostream>
#include <stdio.h>

using namespace std;

int main(int argc, const char *argv[]) {
  int n = atoi(argv[1]);
  for (int i=0; i <= n; i++) {
    for (int j=0; j <= n; j++) {
      if (i * j == n) {
        cout << i << "/" << j << " ";
      }
    }
  }
  return 0;
}

derp:prog $ javac ProgChallengeFactor.java; time java ProgChallengeFactor 99999
1/99999 3/33333 9/11111 41/2439 123/813 271/369 369/271 813/123 2439/41 11111/9 33333/3 99999/1
real    0m13.617s
user    0m13.588s
sys     0m0.057s

derp:prog $ g++ -fomit-frame-pointer progChallengeFactor.cpp -o prog; time ./prog 99999
1/99999 3/33333 9/11111 41/2439 123/813 271/369 369/271 813/123 2439/41 11111/9 33333/3 99999/1
real    0m31.389s
user    0m31.073s
sys     0m0.064s

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List