[ prog / sol / mona ]

prog


Monads,Async/Await : Algebraic Effects in C99

41 2021-01-15 06:06

//command line version
#include "Util/void.h"
char* rollarg(int argc,char**argv) {double r=rdouble();
char* res="Nothing";
for(size_t i=1; i<argc;i++){r-=atof(argv[i]);
if(r<0.0){res=tmax(strrchr(argv[i],',')+1,argv[i])/*protect from invalid arg format*/;break;}};
return res;}

int main(int argc,char**argv){
puts(rollarg(argc,argv));
// ./roll 0.5,"50% chance" 0.2,"20% chance" 1.0,"30% chance"

;}

69


VIP:

do not edit these