Tag: r

53 votes
23 answers
2K views
How to determine if a list of polygon points are in clockwise order?

Having a list of points, how do I find if they are in clockwise order? For example: point[0] = (5,0) point[1

avatar
Charis
0 1 0 9
asked 07 September, 2021
57 votes
11 answers
905 views
JavaScript % (modulo) gives a negative result for negative numbers

According to Google Calculator (-13) % 64 is 51. According to Javascript (see this JSBin) it is -13. How do

avatar
Percy
0 1 0 9
asked 07 September, 2021
62 votes
11 answers
1.3K views
Fast ceiling of an integer division in C / C++

Given integer values x and y, C and C++ both return as the quotient q = x/y the floor of the floating point eq

avatar
Patsy
0 1 0 9
asked 07 September, 2021
69 votes
7 answers
2.5K views
What is "entropy and information gain"?

I am reading this book (NLTK) and it is confusing. Entropy is defined as: Entropy is the sum of the proba

avatar
Leonardo
0 1 0 9
asked 07 September, 2021
55 votes
25 answers
2.4K views
How to evaluate a math expression given in string form?

I'm trying to write a Java routine to evaluate math expressions from String values like: "5+3" "10-40" "(

avatar
Stacia
0 1 0 9
asked 07 September, 2021
67 votes
30 answers
1.2K views
Fastest way to list all primes below N

This is the best algorithm I could come up. def get_primes(n): numbers = set(range(n, 1, -1)) primes

avatar
Alba
0 1 0 9
asked 07 September, 2021
58 votes
7 answers
1.9K views
Fastest way to determine if an integer is between two integers (inclusive) with known sets of values

Is there a faster way than x >= start && x <= end in C or C++ to test if an integer is between t

avatar
Stacia
0 1 0 9
asked 07 September, 2021
56 votes
30 answers
3K views
Calculate distance between 2 GPS coordinates

How do I calculate distance between two GPS coordinates (using latitude and longitude)?

avatar
Stacia
0 1 0 9
asked 07 September, 2021
62 votes
12 answers
2.4K views
JavaScript math, round to two decimal places

I have the following JavaScript syntax: var discount = Math.round(100 - (price / listprice) * 100)

avatar
Lashawna
0 1 0 9
asked 07 September, 2021
66 votes
16 answers
2.8K views
What is the difference between &apos;/&apos; and &apos;//&apos; when used for division?

Is there a benefit to using one over the other? In Python 2, they both seem to return the same results: >&

avatar
Thurman
0 1 0 9
asked 07 September, 2021
57 votes
16 answers
1.9K views
How to sum array of numbers in Ruby?

I have an array of integers. For example: array = [123,321,12389] Is there any nice way to get the sum of

avatar
Kristopher
0 1 0 9
asked 07 September, 2021
63 votes
26 answers
2.7K views
How to check if a number is a power of 2

Today I needed a simple algorithm for checking if a number is a power of 2. The algorithm needs to be: Simpl

avatar
Majorie
0 1 0 9
asked 07 September, 2021
57 votes
6 answers
2.2K views
How do I determine whether my calculation of pi is accurate?

I was trying various methods to implement a program that gives the digits of pi sequentially. I tried the Tayl

avatar
Hilario
0 1 0 9
asked 07 September, 2021
61 votes
28 answers
1.6K views
Understanding "randomness"

I can't get my head around this, which is more random? rand() OR: rand() * rand() I´m finding it a

avatar
Thurman
0 1 0 9
asked 07 September, 2021
62 votes
30 answers
1.2K views
Designing function f(f(n)) == -n

A question I got on my last interview: Design a function f, such that: f(f(n)) == -n Where n is a 3

avatar
Alphonso
0 1 0 9
asked 07 September, 2021
59 votes
30 answers
469 views
Calculate distance between two latitude-longitude points? (Haversine formula)

How do I calculate the distance between two points specified by latitude and longitude? For clarification, I&

avatar
Forrest
0 1 0 9
asked 07 September, 2021
67 votes
21 answers
1.8K views
What is JavaScript&apos;s highest integer value that a number can go to without losing precision?

Is this defined by the language? Is there a defined maximum? Is it different in different browsers?

avatar
Keith
0 1 0 9
asked 07 September, 2021
52 votes
18 answers
1.6K views
How to perform an integer division, and separately get the remainder, in JavaScript?

In JavaScript, how do I get: The whole number of times a given integer goes into another? The remainder?

avatar
Dusty
0 1 0 9
asked 07 September, 2021
62 votes
30 answers
1.1K views
Easy interview question got harder: given numbers 1..100, find the missing number(s) given exactly k are missing

I had an interesting job interview experience a while back. The question started really easy: Q1: We have a b

avatar
Kurtis
0 1 0 9
asked 07 September, 2021
55 votes
30 answers
1K views
Fastest way to determine if an integer&apos;s square root is an integer

I'm looking for the fastest way to determine if a long value is a perfect square (i.e. its square root is

avatar
Margo
0 1 0 9
asked 07 September, 2021