Category: Programming Puzzles

Generate Fair Results from a Biased Coin

In this post, we will discuss how to generate fair results from a biased coin which prefer one side of the coin over another, and returns TAILS with p probability and HEADS with (1-p) probability

Single line expressions to swap two integers in Java

Given two integers, swap them in single line in Java.     There are many expressions to swap two variables in single line in Java. Notice that all below methods can also be used with C/C++.   1. Using Bitwise XOR(^) Operator  

Download   Run Code   2. Using Addition and Subtraction Operator …