Coding since 11yo, that makes it over 30 years now ~~~
Have a PhD in Comp Sci ~~~
Love to go on bike tours ~~~
I try to stay as generalist as I can in this crazy wide place coding is at now.
functionscore(dice){// Business rules of the game:// v: the dice value// c: the number of dice required to trigger the rule// p: the points added each time the rule is triggeredconstscoringRules=[{v:1,c:3,p:1000},{v:6,c:3,p:600},{v:5,c:3,p:500},{v:4,c:3,p:400},{v:3,c:3,p:300},{v:2,c:3,p:200},{v:1,c:1,p:100},{v:5,c:1,p:50}]// returns the score given a histogram mapping a dice value to the number of dice with that valueconstscoreForHistogram=counts=>{letscore=0for(const{v,c,p}ofscoringRules){construleCount=Math.floor((counts[v]||0)/c);counts[v]-=ruleCount*c;score+=ruleCount*p;}returnscore;};// Generate the histogram required by scoreForHistogramconstcounts=[...Array(7)].map(v=>0);// note that the rest of the logic uses 1-indexed arrays, so we need 7 entries to get a valid counts[6] entryfor(constvofdice)counts[v]++;returnscoreForHistogram(counts)}
I am a software engineer currently working @ShopPad, previously @HPE. I like to build websites and web application in PHP, JavaScript, and Golang. I have an unhealthy obsession with Mexican food (🌯)
JS implementation keeping the rules as data
Keep the rules as data is the way to go. 🔥🔥🔥