rust – Calculating average value of points around given point in a wider field

I need to calculate the average value of points around a given point in a wider field.

For this I have a function:

fn local_average((x,y):(i32,i32),n:i32,(width,height):(i32,i32),space:&(i32)) -> i32 {
    let y_range = cmp::max(y-n,0)..cmp::min(y+n+1,height);
    let x_range = cmp::max(x-n,0)..cmp::min(x+n+1,width);
    println!("y: {:.?}, x: {:.?}",y_range,x_range);

    let size = (x_range.end-x_range.start) * (y_range.end-y_range.start);
    let mut total: i32 = 0;
    for yi in y_range {
        for xi in x_range.clone() {
            let i = yi * width + xi;
            total += space(i as usize); 
        }
    }

    println!("{} / {} = {}",total,size,total / size);
    total / size
}

The thing that bothers me here is x_range.clone(), I feel like this is not a good approach.

I could also implement this in a more function manor but I’m unsure if this is better as I find it to be less readable:

fn local_average_functional((x,y):(i32,i32),n:i32,(width,height):(i32,i32),space:&(i32)) -> i32 {
    let y_range = cmp::max(y-n,0)..cmp::min(y+n+1,height);
    let x_range = cmp::max(x-n,0)..cmp::min(x+n+1,width);
    println!("y: {:.?}, x: {:.?}",y_range,x_range);

    let size = (x_range.end-x_range.start) * (y_range.end-y_range.start);
    let total: i32 = y_range.map(|yl| {
        x_range.clone().map(|xl| {
            let il = yl * width as i32 + xl;
            space(il as usize) as i32
        }).sum::<i32>()
    }).sum();
    
    println!("{} / {} = {}",total,size,total / size);
    total / size
}

How could I improve this function?

Repl: https://repl.it/@JonathanWoollet/DraftyTautAdware

Average number hosted sites

Hi, hope you are well.

Quick question…
What would people say the average number of hosted sites is on a shared hosting plan?

TIA,
… | Read the rest of https://www.webhostingtalk.com/showthread.php?t=1839334&goto=newpost

How many unique visitors does an average gameserver running one of the newer multiplayer games typically get per month?

Lets say i have a 32 slot gameserver that is usually full for about 16 hours per day. Different people play on the server on different times a day. How many unique visitors/ip addresses does a typical gameserver like that get per month? I tried googling it but the results are mostly about webservers/websites and not gameservers. I’m asking this because i want to know whether gameserverhosting could be a viable option to advertise for my website. My intend is to advertise my website by including the url in the gameserver name.

database – What is the significance of dumping the tablespaces when it comes to the average Drupal sysadmin?

While recently running drush sql-dump on a server where there were never any error messages, I have started to get:

mysqldump: Error: ‘Access denied; you need (at least one of) the PROCESS privilege(s) for this operation’ when trying to dump tablespaces

It still produces a file I can import locally and I don’t seem to be having any problems. But I am still curious: What is the significance of dumping the tablespaces when it comes to the average Drupal sysadmin?

java – calculating average with different methods

This program is supposed to ask the user for a file where words are line by line and if that word is in a different file that has a score with it, it gets the averages of the score averages all the scores of all the words. I have the first part to work and I can print the words with their averages but how do I get the average of all the “line scores”?

public static void whileLoop(String word) throws FileNotFoundException{
    // declare variables 
    int reviewScore;
    String reviewText;
    double timesInFile = 0;
    double score = 0; 
    double lineScore = 0; 
    double fScore = 0; 
    
    //create movie review file instance and read 
    File reviewFile = new File("movieReviews.txt");
    Scanner reviewScanner = new Scanner(reviewFile); 
    
    while(reviewScanner.hasNext()) {
            reviewScore = reviewScanner.nextInt();
            reviewText = reviewScanner.nextLine();
            if(reviewText.contains(word))
            {
                timesInFile += 1; 
                score += reviewScore;
            }
             
        }
        
        lineScore = score / timesInFile;  
        System.out.println("line score = " + lineScore); 
        
}

public static void getFileWordScore() throws FileNotFoundException{
    // declare variables 
    String file; 
    String newFileText;
    double fScore = 0; 
    
    // ask for file and create file instance and read
    Scanner keyboard = new Scanner(System.in);
    System.out.print("Enter the name of the file with words you want to find the average score of: ");
    file = keyboard.nextLine(); 

File newFile = new File(file);

    // read word in the user created file, search it in movie review
    // & calculate its score 
    Scanner newFileScanner = new Scanner(newFile); 
    
    while(newFileScanner.hasNext()) {
        newFileText = newFileScanner.nextLine();
        System.out.println(newFileText);
        whileLoop(newFileText); 
        System.out.println(); 
    }
}

google sheets – How can I create an average value for every cell which contains a certain phrase?

I need to find the average value of cells containing a certain set of initials to create a scoreboard.

The value of the cell being the score and the brackets containing the initials of the score setter.

Here is the table I am referring to.

So the goal is to create an average score for each of the players (HG), (GT) & (JT).

I have tried different ways of combining REGEXMATCH and REGEXEXTRACT to no avail.

I don’t mind using multiple cells if need be.

Thanks!

google sheets – Find average number of ranges including current date over a period

I take notes in Google Sheets of the dates when I buy and sell stocks. I would like to know the average number of companies I own stock in on a day.

I have one column for the buy date, and another column for the sell date. Each row represents stock in a specific company. The period holding a stock may range from a few weeks up to many months. I always buy stock for the same amount, and I always buy all the stocks at the buy date and sell all the stocks at the sell date.

This is my actual data (except from the company names). Where there is no “Sell date”, I still own the stock.

Company Buy date Sell date
1 2020-07-06
2 2020-07-07 2020-09-23
3 2020-07-08 2020-08-21
4 2020-07-20 2020-10-08
5 2020-08-08
6 2020-08-19 2020-09-02
7 2020-09-03 2020-09-23
8 2020-09-23
9 2020-09-23
10 2020-09-23
11 2020-09-23
12 2020-10-07 2020-12-29
13 2020-10-15 2020-12-16
14 2020-10-15 2020-11-17
15 2020-11-17
16 2020-11-17
17 2020-11-17
18 2020-12-08 2020-12-29
19 2020-12-11
20 2020-12-11
21 2020-12-29
22 2021-01-11
23 2021-01-11

The algorithm would be: For each date between 2020-07-06 and today, check how many ranges include that date. Then calculate the average of all those values.

I realize I can currently do this manually, but this table will continue to grow over many years and I would like it automated.

I have searched this website and the search engines and have not been able to find a solution or any similar problem posted. If I have done a bad job searching, I am happily guided to any solutions you are able to find online. I have also read about the different formulas available in Google Sheets and have not really been able to come up with any strategy to solve my problem.

Thank you in advance!

Fredrik

volume – How can 6.10 ₿ be the average size of a Bitcoin transaction (lately)?

Number of Bitcoins sent in the last 24 hours: 1.84 million ₿.
Number of Bitcoin transactions in the last 24 hours: ~301,900.

This becomes on average 6.10 ₿ per transaction. That’s shocking to me. Since I just started with this little “formula”, I don’t know how normal/unusual this is.

It sounds extremely strange. I would’ve guessed that 0.01 or something would be the most common amount. Not multiple Bitcoins at once. Certainly not 6.10 ₿ on average.

Is this an extreme 24 hours in that sense? Or is this normal?! Or has there been some really MASSIVE single one which skews the average for today grossly?

Average Download Speed on Hetzner

On average, what is the download speed you guys get on Hetzner? I tried one server and it was roughly 500 KB/s on multiple locations (even s… | Read the rest of https://www.webhostingtalk.com/showthread.php?t=1837024&goto=newpost

complexity theory – How balanced is a binary tree in the average case?

For algorithms involving binary trees, time or space complexity is often O(logn) in the best case of a completely balanced tree, and O(n) in the worst case of a completely unbalanced tree. Sure, it’s a generalization, but it’s also a reasonable one.

But in real algorithms, we’re typically not interested in the rare worst case performance, much less the best case performance. Rather, we’re interested in how the algorithm performs in typical use. This begs an interesting (and useful) question: How balanced is a binary tree on average? Is there a reasonable way to approach that problem, or is it so dependent on use case that there’s no better answer than “take a look at the binary trees you’re using in your algorithm”?