What exactly does Math.floor do?

No, in fact this line of code outputs 0: Math.floor(0.9); Math.floor always rounds to the nearest whole number that is smaller than your input. You might confuse it with Math.round, that rounds to nearest whole number. This is why this code always outputs 1 or 0, since input never gets to 2 or bigger: Math.floor(Math.random()*2) … Read more

C++ quadratic equation using factorization

Building on what @Aditi Rawat said, I’ve wrote a little program that does what you need using the quadratic roots formula. Not sure if you need to do it that way or not but this solves the problem: #include <iostream> #include <cmath> using namespace std; int main() { double a, b, c; cout<<“Enter a: “; … Read more

How to generate Random point(x,y) in Java [closed]

Take a look at article https://www.tutorialspoint.com/java/util/java_util_random.htm. All you need to do is to generate pairs of floats in range (-1,1). You should use method nextFloat() from class Random. It will give you numbers in range (0,1). Then multiply it by 2 and subtract 1 and you will have numbers in desired interval.

Python. Finding thresholds for rows of data

Look into the python package pandas. Here’s a tutorial: https://pandas.pydata.org/pandas-docs/stable/tutorials.html import pandas as pd list1 = [-50, -40, -30, -20, -10, 0, 1, 2] list2 = [-300, -200, -100, 0, 100, 200, 300, 400] df = pd.DataFrame({‘List 1’: list1, ‘List 2’: list2}) newdf = df.copy() newdf[df > df.median()] = 1 newdf[df < df.median()] = -1 … Read more

How to find out the date of the first day of week from the week number in C++

Using Howard Hinnant’s free, open-source, header-only date library, it can look like this: #include “date.h” #include “iso_week.h” #include <iostream> int main() { using namespace iso_week::literals; std::cout << date::year_month_day{2017_y/8_w/mon} << ‘\n’; std::cout << date::year_month_day{2017_y/10_w/mon} << ‘\n’; } which outputs: 2017-02-20 2017-03-06 There are also getters for year, month and day on the year_month_day types, and plenty … Read more