Content
Jeroen Friters JeroenFriters 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) "0000000000"; if (percentage 0.1 percentage 0.2) return 100000000"; iF percentage 0.2 8 percentage 0.3) hOrunn 00000000"; if (percentage 0.3 percentage 0.4) norunr 0000000"; if (percentage 0.4 percentage 0.5) 00000": if (percentage 0.5 8 percentage 0.6) returr 00000000"; if (percentage 0.6 percentage 0.7) returr if (percentage 97 percentage 0.8) if (percentage 0.8 8 percentage 0.9) noturn "I return "0000000000"; da 1.3M O308 171,196 9 6,678 tyrannoSaurav TyrannoSaurav Replying to JeroenFriters 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 6 percentage 0.5) if (percentage 0.2) if (percentage 0.1) S if (percentage 0) return "0000000000"; return "0000000000"; return 000000000"; if (percentage 0.41 if (percentage 0.3) return 00000000"; return 00000000"; return "0000000000": if (percentage 0.5 66 percentage 0.9) if (percentage 0.7) if (percentage 0.6 return return 000": 300". if (percentage 0.8) return return return