Biorhythms: Difference between revisions

Content added Content deleted
Line 94: Line 94:
Mental day 25: valley
Mental day 25: valley
</pre>
</pre>

=={{header|C}}==
{{trans|Locomotive Basic}}
<lang c>#include <stdio.h>
#include <stdlib.h>
#include <math.h>

long day(int y, int m, int d) {
return 367 * y - 7 * (y + (m + 9) / 12) / 4 + 275 * m / 9 + d - 730530;
}

void cycle(long diff, int l, char *t) {
float p = 100 * sin(2 * M_PI * diff / l);
printf("%12s cycle: %3.0f%%", t, round(p));
if (abs(p) < 15)
printf(" (critical day)");
printf("\n");
}

int main(int argc, char *argv[]) {
long diff;

if (argc < 7) {
printf("Usage:\n");
printf("cbio y1 m1 d1 y2 m2 d2\n");
exit(1);
}
diff = abs(day(atoi(argv[1]), atoi(argv[2]), atoi(argv[3]))
- day(atoi(argv[4]), atoi(argv[5]), atoi(argv[6])));
printf("Age: %u days\n", diff);
cycle(diff, 23, "Physical");
cycle(diff, 28, "Emotional");
cycle(diff, 33, "Intellectual");
}</lang>
Test:
<lang bash>gcc -o cbio cbio.c -lm
./cbio 1972 7 11 1943 3 9
Age: 10717 days
Physical cycle: -27%
Emotional cycle: -100%
Intellectual cycle: -100%</lang>


=={{header|Common Lisp}}==
=={{header|Common Lisp}}==