Loading…

Worlds

Create a lock class to prevent deadlock

  There are several common options to prevent deadlock. One of the most popular is to explicitly declare what lock is required. This way, we will be able to check whether the created lock is a deadlock and if so, we can stop working.   Let’s take a look and sort out the way we…

Create a method that counts a number

  As usual, initially, we try to solve the task bluntly.   /* Count the number ‘2’ between 0 and n */ int numberOf2sInRange(int n) { int count = 0; for (int i = 2; i <= n; i++) { // We can begin with 2 count += numberOf2s(i); } return count; } /* count…

The Probability of Meeting a Car on a Deserted Highway

  The probability of a car on a deserted highway for a 30 minute period is 0.95. What is the probability of its occurrence in 10 minutes?   This question is difficult to answer because the information that we have is not what we would like to have. However, in real life, it is a…

Finding the maximum of two numbers

  The most widespread option of max function implementation is to check the operator of the a-b expression. In this case, we cannot use comparisons operators, but we can use the multiplication operator.   Note The task’s essence is to make everything without switch instructions at the processor level instead of hiding the comparison or…

The task of calendar gaps merging

    Let’s suppose you are working in a company and it is developing an electronic calendar. The calendar has a function that shows when various programming teams will be busy at a meeting.   Those periods when the team is busy are marked on the calendar as time ranges, for example, from 10:00 to…