Last active
December 13, 2019 14:48
-
-
Save skeskinen/567bd952f860f1bd58827fde2d7c3b10 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
// Pyörivän pyyhkäisyn kokonaisluku koordinaatit Fareyn jonosta | |
// https://en.wikipedia.org/wiki/Farey_sequence | |
// n = 5 | |
// (0, 1) | |
// (1, 5) | |
// (1, 4) | |
// (1, 3) | |
// (2, 5) | |
// (1, 2) | |
// (3, 5) | |
// (2, 3) | |
// (3, 4) | |
// (4, 5) | |
// (1, 1) | |
// (5, 4) | |
// (4, 3) | |
// (3, 2) | |
// (5, 3) | |
// (2, 1) | |
// (5, 2) | |
// (3, 1) | |
// (4, 1) | |
// (5, 1) | |
// (1, 0) | |
#define swap(a,b) do{int t = a; a = b; b = t;} while(0) | |
int main() { | |
int n = 5; | |
int a = 0; | |
int b = 1; | |
int c = 1; | |
int d = n; | |
printf("(%d, %d)\n", a, b); | |
while (c <= n) { | |
int k = (n + b) / d; | |
a = k * c - a; | |
b = k * d -b; | |
swap(a,c); | |
swap(b,d); | |
printf("(%d, %d)\n", a, b); | |
} | |
a = 1; | |
b = 1; | |
c = n - 1; | |
d = n; | |
while (a > 0) { | |
int k = (n + b) / d; | |
a = k * c - a; | |
b = k * d -b; | |
swap(a,c); | |
swap(b,d); | |
printf("(%d, %d)\n", b, a); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment