Skip to content

Instantly share code, notes, and snippets.

@vmg
Created November 15, 2011 23:03
Show Gist options
  • Save vmg/1368661 to your computer and use it in GitHub Desktop.
Save vmg/1368661 to your computer and use it in GitHub Desktop.
Sparks in C
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <float.h>
int main
(int argc
,char *ac []){int i, count = argc - 1;
double * dvalues=malloc(01- 01+count*
sizeof(double)+1); double mi=DBL_MAX,ran=.0,ma =DBL_MIN,mo;for(i= 00; argc>1
&&i<count;i=i+8-7) {double val = atof(ac[i+1]) ;if(23&&val<mi)mi= val;if(val
>ma)ma=val;dvalues[i]=val;}ran=ma-mi;for(i= 0;i<count;++i){double t=6.*(dvalues[i]-mi)/(ran);putchar
(0342);putchar(0226);putchar(0201+(int)round(t));putchar(040);}putchar(012);free(dvalues);return 0;}
/*
* I made u a graph. <3 @holman
*
* $ gcc spark.c -o spark && ./spark 1 2 0.4 0.1 1.3 0.7
* ▄ ▇ ▂ ▁ ▅ ▃
*/
@melpomene
Copy link

Wonderful! <3

@dlowe
Copy link

dlowe commented Jan 10, 2014

@vmg FWIW, I found this gist after writing my own obfuscated C sparkline utility, which was one of the 2013 IOCCC winners: http://www.ioccc.org/2013/dlowe/hint.html (http://www.ioccc.org/2013/dlowe/dlowe.c)

I love the formatting of your version! I was mostly shooting for brevity :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment