June 2018 Update

This commit is contained in:
Ingy döt Net 2018-06-22 20:57:24 +00:00
parent ba8067c3b7
commit 22f33d4004
5278 changed files with 84726 additions and 14379 deletions

View file

@ -0,0 +1,49 @@
/*Abhishek Ghosh, 5th October 2017*/
#include<string.h>
#include<stdlib.h>
#include<locale.h>
#include<stdio.h>
#include<wchar.h>
#include<math.h>
int main(int argC,char* argV[])
{
double* arr,min,max;
char* str;
int i,len;
if(argC == 1)
printf("Usage : %s <data points separated by spaces or commas>",argV[0]);
else{
arr = (double*)malloc((argC-1)*sizeof(double));
for(i=1;i<argC;i++){
len = strlen(argV[i]);
if(argV[i][len-1]==','){
str = (char*)malloc(len*sizeof(char));
strncpy(str,argV[i],len-1);
arr[i-1] = atof(str);
free(str);
}
else
arr[i-1] = atof(argV[i]);
if(i==1){
min = arr[i-1];
max = arr[i-1];
}
else{
min=(min<arr[i-1]?min:arr[i-1]);
max=(max>arr[i-1]?max:arr[i-1]);
}
}
printf("\n%Max : %lf,Min : %lf,Range : %lf\n",max,min,max-min);
setlocale(LC_ALL, "");
for(i=1;i<argC;i++){
printf("%lc", (wint_t)(9601 + (int)ceil((arr[i-1]-min)/(max-min)*7)));
}
}
return 0;
}

View file

@ -1,22 +1,12 @@
function sparklineit(a)
const sparkchars = '\u2581':'\u2588'
const dyn = length(sparkchars)
(lo, hi) = extrema(a)
b = max(iceil(dyn*(a-lo)/(hi-lo)), 1)
return join(sparkchars[b], "")
function sparklineit(arr::Vector{<:Integer})
sparkchars = '\u2581':'\u2588'
dyn = length(sparkchars)
lo, hi = extrema(arr)
b = @. max(ceil(Int, dyn * (arr - lo) / (hi - lo)), 1)
return join(sparkchars[b])
end
function getnumbers(s)
a = split(s, r"[,,\s]+")
a = try
map(parseint, a)
catch
map(parsefloat, a)
end
end
test = getnumbers("1 2 3 4 5 6 7 8 7 6 5 4 3 2 1")
println(test, " => ", sparklineit(test))
test = getnumbers("1.5, 0.5 3.5, 2.5 5.5, 4.5 7.5, 6.5")
println(test, " => ", sparklineit(test))
v = rand(0:10, 10)
println("$v → ", sparklineit(v))
v = 10rand(10)
println("$(round.(v, 2)) → ", sparklineit(v))