78 lines
1.1 KiB
C
78 lines
1.1 KiB
C
|
#include <stdio.h>
|
||
|
#include <float.h>
|
||
|
#include <unistd.h>
|
||
|
#include <stdlib.h>
|
||
|
#include <string.h>
|
||
|
#include <math.h>
|
||
|
|
||
|
double min = 90000;
|
||
|
double max = 3000000;
|
||
|
|
||
|
int parse_double(const char *str, double *res) {
|
||
|
char *ptr;
|
||
|
|
||
|
*res = strtod(str, &ptr);
|
||
|
if (*ptr)
|
||
|
return 0;
|
||
|
|
||
|
return 1;
|
||
|
}
|
||
|
|
||
|
void print(double diff, double val) {
|
||
|
int lvl = (int)round((val - min + 1) / diff * 7);
|
||
|
if (lvl < 0)
|
||
|
lvl = 0;
|
||
|
|
||
|
else if (lvl > 7)
|
||
|
lvl = 7;
|
||
|
|
||
|
putchar('\xe2');
|
||
|
putchar('\x96');
|
||
|
putchar('\x81' + lvl);
|
||
|
}
|
||
|
|
||
|
int main(int argc, char **argv) {
|
||
|
argv++;
|
||
|
argc--;
|
||
|
|
||
|
if (argc == 0) {
|
||
|
fprintf(stderr, "spark: missing operands\n");
|
||
|
return 1;
|
||
|
}
|
||
|
|
||
|
size_t as = argc / 2;
|
||
|
double *a = malloc((as + 1) * sizeof(double));
|
||
|
if (a == NULL)
|
||
|
return 1;
|
||
|
|
||
|
size_t j = 0;
|
||
|
for (size_t i = 0; i < as; i++) {
|
||
|
double val = 0;
|
||
|
if (!parse_double(argv[j], &val)) {
|
||
|
j++;
|
||
|
continue;
|
||
|
}
|
||
|
|
||
|
double val2 = 0;
|
||
|
if (!parse_double(argv[j + 1], &val)) {
|
||
|
j++;
|
||
|
continue;
|
||
|
}
|
||
|
|
||
|
a[i] = (val + val2) / 2;
|
||
|
j++;
|
||
|
}
|
||
|
|
||
|
double diff = max - min + 1;
|
||
|
if (diff < 1)
|
||
|
diff = 1;
|
||
|
|
||
|
for (size_t i = 0; i < as; i++)
|
||
|
print(diff, a[i]);
|
||
|
|
||
|
putchar('\r');
|
||
|
|
||
|
free(a);
|
||
|
return 0;
|
||
|
}
|