c# - Getting remainder of sequence but with exception on element with remainer zero -
c# - Getting remainder of sequence but with exception on element with remainer zero -
let have number 1 24, want remainder of these 12 mod 12 sequence 1 11 , additionally 0 (of 12 , 24) . need 0 12. how accomplish such thing in 1 liner(without additional variables or ifs). right code this:
for (int = 1; <= 24; i++) { console.writeline(i % 12); }
oneline solution (with slight overhead though: i % 12
computed twice):
for (int = 1; <= 24; i++) { console.writeline(i % 12 == 0 ? 12 : % 12); }
pure arithmetic solution is
for (int = 1; <= 24; i++) { console.writeline(12 - (12 - % 12) % 12); }
c# modulus sequences
Comments
Post a Comment