diff options
Diffstat (limited to 'spark.c')
-rw-r--r-- | spark.c | 37 |
1 files changed, 37 insertions, 0 deletions
@@ -0,0 +1,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; +} |