How to find the sum of the length of all lines that can be drawn between coordinates
Find latitude and longitude of first 20 countries with a population greater than or equal to the population limit given below. Your task is to find the sum of the length of all lines (in kms) that can be drawn between coordinates of these countries.
 Assume radius of earth: 6371 km
 Round length of each line and final result to 2 decimal points
 If coordinates are missing for any country use 0.000 N 0.000 E
Population limit: 28000
I want a general equation to find it
do you know?
how many words do you know
See also questions close to this topic

How to evaluate Integer Operation Per Second
I've developed a cuda algorithm for counting sort:
/** * @brief This function implement the counting sort algorithm of the array 'array'. * @param array Pointer to the array used in counting sort. * @param dim_array Size of the array 'array'. * @param counts The array containing the */ __global__ void kernelCountingSort(int *array, int dim_array, int *counts) { // define index int i = blockIdx.x * blockDim.x + threadIdx.x; // check that the thread is not out of the vector boundary if (i >= dim_array) return; int count = 0; int el = array[i]; for (int j = 0; j < dim_array; ++j) { int le = array[j]; if (le < el) count++; else if (le == el && j < i) count++; } counts[count] = el; }
I'm trying to compute the number of integer operations per second of this algorithm. Therefore, to get the total number of integer operation, I supposed that I need to count only the additions operations on
count
variable. So I build this method:int countIO(int dim_array){ int s=0; for(int i=dim_array;i>0;i) s+=i; s+=dim_array; return s; }
This method compute how much
count
variable increment occur in the algorithm, but I've a question: Do I need to include the number of increments on thej
variable in the loop, as I made here:s+=dim_array;
?Generally, is it correct the way I computed the total number of integer operation?
PS. Finally, to obtain the number of integer operations per second I going to divide total integer operation with elasped time of the algorithm, expressed in seconds.

Algorithmus (Graphen)
We are looking for an algorithm that determines the number of connected components. In addition, it should be stored for each node to which connected component it belongs.
 Which known Algorithm can be used to deal with this it as efficiently as possible? and why

Different potential function for the same problem has the same amortized or not?
If I set the potential function as 2 multiple the size of the heap.
The operation for the insert and delete operation might be both
O(logn)
.I check that the definition of the potential function that my potential function is correct.
But the answer for the problem that the insertion took
O(logn)
and the extractmin tookO(1)
.So, it's there any problem that has different potential functions result in different amortized time complexity ?
I think that maybe I set the wrong potential function.
Because I think the amortized method result the same amortized time complexity, right ?

CRC doesn't return expected value
I have some technical documentation and try to replicate the given CRC algorithm in python. However I don't get the correct results. How do I have to tweak my algo to match the docs?
This is the documentation:
And this is my code:
data1 = b'\0x01\0x04\0x00\0x0b\0x00\0x01' data2 = b'\0x01\0x03\0x00\0x65\0x00\0x01' def crc16(data : bytearray): length = len(data) crc = 0xffff for i in range(0, length): crc ^= data[i] for j in range(0,8): if (crc & 0x01): crc =(crc >> 1) ^ 0xa001 else: crc = crc >> 1 return crc print(crc16(data1).to_bytes(2, 'big')) print(crc16(data2).to_bytes(2, 'big'))
Here are some examples for the documentation:
Here are my results:
b'\xc9Y' b'\xd4\xd1'

Python 3.9.9  How to calculate the log of division of two items (t and t+1) from one array
I've stumbled onto a simple problem that blocks me from any further progress. I'd like to calculate the log of the division of two items in a loop and then save each result to a new array.
So I have my dataset that is already scaled with Sklearn MinMaxScaler, and the precise calculations I'd like to perform are these:
logs = np.empty(12530) for i in data_prepared  1: logs[i] = np.log10(data_prepared[i + 1] / data_prepared[i])
But both
math.log10()
andnp.log10
return Index Error:IndexError: arrays used as indices must be of integer (or boolean) type
How can I perform the calculations I need?
EDIT: data_prepared dtype is float32

Can't perform a math.ceiling() over a pandas dataframe column
I have the following sentence:
b['trucks_est'] = math.ceil(b['volume'] / b['max_boxes_per_truck'])
Which raises this exception:
 TypeError Traceback (most recent call last) C:\Users\HUGO~1.VIL\AppData\Local\Temp/ipykernel_12504/708959517.py in <module> > 1 b['trucks_est'] = math.ceil( 2 b['volume'] / b['max_boxes_per_truck']) ~\Documents\code\Venv\lib\sitepackages\pandas\core\series.py in wrapper(self) 183 if len(self) == 1: 184 return converter(self.iloc[0]) > 185 raise TypeError(f"cannot convert the series to {converter}") 186 187 wrapper.__name__ = f"__{converter.__name__}__" TypeError: cannot convert the series to <class 'float'>
I know the problem is the
math.ceiling()
becauseb['trucks_est'] = b['volume'] / b['max_boxes_per_truck']
works perfectly.How can I perform this math operation over a pandas dataframe?

What would be an appropriate Java data structure to search in less than O(n)?
Let’s say I have to use Java datastructures to map coordinates to area’s general political party affiliations.
I would need to add new or remove an instance by location so: Add([0,0], “Democrat”) Remove ([1,0], “Republican”)
But I would also need to find if a political party exists in the database and list out all of the locations associated with a party.
Exists(“Light Party”) > true
FindAll(“Light Party”) > <[1,2],[4,6],[7,7]>
And be able to remove all locations associated with a party that may no longer exist.
RemoveAll(“Rent is too damn high”)> <[0,0],[3,6]>
I was originally planning on tackling the problem with a hashmap, but that would require an iterative solution for findAll and exists. I’m looking for a way to do this in less than O(n) time complexity. Hash maps are amazing when you’re using the keys, not when you need to find them.
What data structures would you recommend for this problem?

How to deal with extreme values on a Folium map
I have very little experience with folium maps. I need to make a map with the number of establishments in each department, the problem is that the capital has far more establishments than the interior, so when I create the color layer I get the capital as dark blue and all the rest with the same lighter color. This way the map is not so useful... How could I solve that? I thought of maybe dividing the value by the population but it would be better to use the original value. In the documentation, I did not find a way to parameterize the color.
df1 = pd.DataFrame({'code':['75','77','78','91','92','93','94','95'],'value':['13000','2000','2500','2300','2150','2600','1630','1300']}) dep_geo = geopandas.read_file('./dep.json', driver="JSON") #geodata taken from https://github.com/gregoiredavid/francegeojson/blob/master/departements.geojson departments = {'75', '77', '78', '91', '92', '93', '94', '95'} dep_geo = dep_geo[dep_geo['code'].isin(departments)] df_map = dep_geo.merge(df1, how="left", left_on=['code'], right_on=['code']) my_map = folium.Map(location=[48.856614, 2.3522219], zoom_start = 9, tiles='cartodbpositron') folium.Choropleth( geo_data=df_map, data=df_map, columns=['code',"value"], key_on="feature.properties.code", fill_color='YlGnBu', fill_opacity=0.5, line_opacity=0.2, legend_name="value ", smooth_factor=0, Highlight= True, line_color = "black", name = "value", show=False, overlay=True, nan_fill_color = "White" ).add_to(my_map)
Thank you for your help!

Extract latitude and longitude from Google Maps URL using C# winform Application
How to extract latitude and longitude from Google Maps URL using C# winform Application programmatically?

Errors converting lat and long values to sf coordinates
I have a series of coordinates that I am trying to plot on simple maps. I have two columns containing latitude and longitude for each point, respectively. I am attempting to use the
st_as_sf
function to convert this data into sf points but I keep getting numerous errors, most recently"Error in UseMethod("st_as_sf") : no applicable method for 'st_as_sf' applied to an object of class "c('double', 'numeric')"
I have tried changing the class of the data to numeric, double, integer, etc. and I continue to get this error.
Below is an example of my data
point lat long 1 38.254 76.712 2 38.123 76.710 3 38.438 76.699 4 38.254 76.712 5 38.232 76.733 st_as_sf(coords=c(lat, long), crs=4326)

How separate latitude and longitude into two columns from dataframe using regex
After using google maps api I get a list of all business it find,
on the column geometry I get this data for each business:
{'location': {'lat': 39.7904306, 'lng': 86.1631634}, 'viewport': {'northeast': {'lat': 39.79635710000001, 'lng': 86.15916770000001}, 'southwest': {'lat': 39.78564629999999, 'lng': 86.16786649999999}}}
I need to separate latitude and longitude into two separate columns one for each coordinate, after trying regex:
import re Health_centers['Venue Latitude'] = Health_centers['geometry'].str.extract(r"[^}]*")
I only get to extract
{'location': {'lat': 39.7904306, 'lng': 86.1631634
there is a way to combine strip and regex to do it with one code line?

Get nearest places with the comparison of longitude and latitude in MySQL
I am trying to get nearest places nearby me using following query.
select user_address_id, round( ( 6371* acos( least(1.0, cos( radians(19.024808088594966) ) * cos( radians(latitude) ) * cos( radians(longitude)  radians(72.84048742388586) ) + sin( radians(19.024808088594966) ) * sin( radians(latitude) ) ) ) ), 1) as distance from user_address
This query works but giving difference of almost 1.5 km instead of actual. I mean if I am at point A and I want distance up to point B. Then if actual distance between point A and B is 2.0 Km but then by using above query it returns me only 0.5 Km.
Please help me in this query to get actual distance between other places and me.
Thanks in advance.