Jump to content

Self-describing numbers: Difference between revisions

m
m (→‎Alternative With "Optimisations": update @truncate() call)
Line 3,593:
3211000
42101000</pre>
===Alternative With "OptimisationsOptimizations"===
Here is an alternative implementation of <em>isSelfDescribing()</em> that
illustrates additional computationally cheap ways of partially eliminating
Line 3,637:
// should equal the number of digits in the number
var sum: u32 = 0;
for (digits, 0..) |n, index| sum += n * @truncateas(u32, @truncate(index));
if (sum != digits.len) return false;
}
59

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.