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-23 17:09

OP here, I intended to say "Find every rational number written in it's simplest fraction form which product of the numerator and denominator equals a specific integer n."

Since everybody likes cryptic code this is the slow algorithm everybody uses.
In [spolier]FORTH[/spoiler]


: ?SIMPLYFY 2DUP MAX >R MIN DUP 2/ 1+ 2 DO DUP I MOD J I MOD OR IF ELSE DROP I UNLOOP RDROP EXIT THEN LOOP DROP RDROP FALSE ;
: PRINTFRACTION s>d 0 d.r ." /" . ;  
: FINDFRACTIONS DUP 2 DO DUP 2 DO DUP I J * = IF I J MIN 3 > IF I J ?SIMPLYFY ELSE FALSE THEN IF ELSE I J PRINTFRACTION THEN THEN LOOP LOOP DROP ;
: FRACTIONS DUP DUP 1 PRINTFRACTION FINDFRACTIONS 1 SWAP PRINTFRACTION ;


Slow as fuck, but its works as intended if a fraction can be simplified it is removed.

time gforth-fast musical.fs -e " 27000 fractions bye"
1/27000 2/13500 3/9000 5/5400 8/3375 27/1000 125/216 216/125 1000/27 3375/8 5400/5 9000/3 13500/2 27000/1
real    0m27.278s
user    0m17.737s
sys     0m0.049s

And nobody done a version which merges several fraction sequences or eulers thing either (on which this idea is based on btw)
I might do a full implementation in C since nobody else seems willing to do it.

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