Is a list (potentially) divisible by another?

Build bipartite graph structure – connect a[i] with all its divisors from b[]. Then find maximum matching and check whether it is perfect matching (number of edges in matching is equal to the number of pairs (if graph is directed) or to doubled number). Arbitrary chosen Kuhn algorithm implementation here. Upd: @Eric Duminil made great … Read more

How to convert a String containing Scientific Notation to correct Javascript number format

Edit: This answer seems to be generating some confusion. The original question was asking how to convert scientific notation in the form of a string to a number (so that it could be used for calculation). However, a significant number of people finding this answer seem to think it’s about converting a number that is … Read more

Negative numbers to binary string in JavaScript

Short answer: The toString() function takes the decimal, converts it to binary and adds a “-” sign. A zero fill right shift converts it’s operands to signed 32-bit integers in two complements format. A more detailed answer: Question 1: //If you try (-3).toString(2); //show “-11” It’s in the function .toString(). When you output a number … Read more

Comparing the values of two generic Numbers

This should work for all classes that extend Number, and are Comparable to themselves. By adding the & Comparable you allow to remove all the type checks and provides runtime type checks and error throwing for free when compared to Sarmun answer. class NumberComparator<T extends Number & Comparable> implements Comparator<T> { public int compare( T … Read more