blob: ea782835d9f8fa9b1e4b941aecc64b3c181ed245 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
|
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <float.h>
int main(int argc, char *argv[])
{
if (argc < 2 || !strcmp(argv[1], "-h") || !strcmp(argv[1], "--help")) {
fprintf(stderr, "Spark\n by Jason A. Donenfeld <Jason@zx2c4.com>\n\n");
fprintf(stderr, "Usage: %s [number] [number] [number] ...\n", argv[0]);
return 1;
}
double *values = malloc(sizeof(double) * (argc - 1));
double max = DBL_MIN;
double min = DBL_MAX;
for (int i = 0; i < argc - 1; ++i) {
values[i] = atof(argv[i + 1]);
if (values[i] > max)
max = values[i];
if (values[i] < min)
min = values[i];
}
double difference = max - min + 1;
if (difference < 1)
difference = 1;
const int levels = 8;
for (int i = 0; i < argc - 1; ++i) {
putchar('\xe2');
putchar('\x96');
putchar('\x81' + (int)round((values[i] - min + 1) / difference * (levels - 1)));
}
putchar('\n');
free(values);
return 0;
}
|