Content
Jeroen Frijters JeroenFrijters 1d The Dutch government was forced to release the source code of their DigiD digital authentication iOS app. It is written in C. github.comMinBZKwoo-bes… private static string GetPercentageRounds (double percentage) if (percentage 0) return "0000000000"; if (percentage 0.0 percentage 0.1) return "0000000000"; 11 percentage 0.1 percentage 0.2) return if (percentage noTunn 00000000"; 0.2 percentage 0.3) 0000000" if percentage ercentage 0.4) 11 percentage 0.5) 11 percentage 0.6) return if percentage 6 percentage 0.7) return 000" 1 percentage 0.7 percentage 0.8) 11 percentage return a percentage 0.9) 0000": return 11 1.3M Q308 171,196 6,678 08 tyrannoSaurav TyrannoSaurav Replying to JeroenFrijters Ahh I see the problem is that there are too many if statements. Here’s a solution implementing binary search in O(log n) private static string GetPercentageRounds (double percentage) if (percentage 0 So percentage 0.5) if (percentage 0.2) if (percentage 0.1; 11 percentage return return return "O 00"; if (percentage 0.4) if (percentage 0.3) return "0000000000"; return "000000000"; return " 0000"; if (percentage 0.5 percentage 0.9) if (percentage 0.7) if (percentage return gOO" return if (percentage return return return