Formatting decimal places with unknown number

A Float uses a binary (IEEE 754) representation and cannot represent all decimal fractions precisely. For example, let x : Float = 123.456 stores in x the bytes 42f6e979, which is approximately 123.45600128173828. So does x have 3 or 14 fractional digits? You can use NSNumberFormatter if you specify a maximum number of decimal digits … Read more

XSLT Bitwise Logic

XSLT is Turing-complete, see for example here or here, hence it can be done. But I have used XSLT only one or two times and can give no solution. UPDATE I just read a tutorial again and found a solution using the following fact. bitset(x, n) returns true, if the n-th bit of x is … Read more

How to use LINQ to find all combinations of n items from a set of numbers?

Usage: var results = new[] { 1, 2, 3, 4, 5, 6, 7, 8, 9 }.DifferentCombinations(3); Code: public static class Ex { public static IEnumerable<IEnumerable<T>> DifferentCombinations<T>(this IEnumerable<T> elements, int k) { return k == 0 ? new[] { new T[0] } : elements.SelectMany((e, i) => elements.Skip(i + 1).DifferentCombinations(k – 1).Select(c => (new[] {e}).Concat(c))); } }

AND/OR in Python? [duplicate]

As Matt Ball‘s answer explains, or is “and/or”. But or doesn’t work with in the way you use it above. You have to say if “a” in someList or “á” in someList or…. Or better yet, if any(c in someList for c in (“a”, “á”, “à”, “ã”, “â”)): … That’s the answer to your question … Read more

Fastest way of finding the middle value of a triple?

There’s an answer here using min/max and no branches (https://stackoverflow.com/a/14676309/2233603). Actually 4 min/max operations are enough to find the median, there’s no need for xor’s: median = max(min(a,b), min(max(a,b),c)); Though, it won’t give you the median value’s index… Breakdown of all cases: a b c 1 2 3 max(min(1,2), min(max(1,2),3)) = max(1, min(2,3)) = max(1, … Read more