Find out how many laptops Molly can buy based on available money, array of quantities and array of costs

Problem description:
Molly wants to purchase laptops for her school. Find out how many laptops she can purchase by comparing the vendors available.
Each vendor sells the laptops in batches, with a quantity identifying how many laptops on each batch, and a cost for the whole batch.
Sample input: 50 [20,19] [24,20] That means Molly has 50 dollars to spend. The first vendor has 20 laptops per batch and each batch costs 24 dollars. The second vendor has 19 laptops per batch and each batch costs 20 dollars.
The possible answers are 40 and 38. If she buys from the first vendor, she will spend 48 dollars (24 * 2) and since she’s buying 2 batches the total quantity is 40 (20 * 2).
If however she would buy from the second vendor, the maximum quantity would be 38, since each batch has 19 laptops and she’d run out of money after the second batch.
The final answer is then 40, since 40 is higher than 38.
This seems similar to the Knapsack problem.

My solution is listed below. The permute method is there to generate the possible permutations between the indices. For instance if we have 3 items in the input array the permutations are:
012 021 102 120 201 210

import static org.junit.Assert.assertEquals; import java.util.List; import java.util.stream.IntStream;  public class ShoppingBudget {    public static void main(String[] args) {     ShoppingBudget sb = new ShoppingBudget();     assertEquals(40, sb.budgetShopping(50, List.of(20, 19), List.of(24, 20)));     assertEquals(20, sb.budgetShopping(4, List.of(10), List.of(2)));     assertEquals(0, sb.budgetShopping(1, List.of(10), List.of(2)));     assertEquals(41, sb.budgetShopping(50, List.of(20, 1), List.of(24, 2)));   }    private void permute(int start, int moneyAvailable, int[] inputIndices,       List<Integer> budgetQuantities, List<Integer> budgetCosts, MaxQuantity maxQuantity) {     if (start == inputIndices.length) { // base case        int possibleMax = findSolution(inputIndices, moneyAvailable, budgetQuantities, budgetCosts);        maxQuantity.value = Math.max(maxQuantity.value, possibleMax);        return;     }     for (int i = start; i < inputIndices.length; i++) {       // swapping       int temp = inputIndices[i];       inputIndices[i] = inputIndices[start];       inputIndices[start] = temp;       // swap(input[i], input[start]);        permute(start + 1, moneyAvailable, inputIndices, budgetQuantities, budgetCosts, maxQuantity);       // swap(input[i],input[start]);        int temp2 = inputIndices[i];       inputIndices[i] = inputIndices[start];       inputIndices[start] = temp2;     }   }    private int findSolution(int[] inputIndices, int moneyAvailable,        List<Integer> budgetQuantities, List<Integer> budgetCosts) {     int remaining = moneyAvailable;     int counter = 0;      for (int index : inputIndices) {       if (remaining == 0) {         break;       }        int quantity = budgetQuantities.get(index);       int cost = budgetCosts.get(index);        if (cost <= remaining) {         int howManyToBuy = remaining / cost;         counter += howManyToBuy * quantity;         remaining -= (howManyToBuy * cost);       }     }      return counter;   }    private int budgetShopping(int n, List<Integer> budgetQuantities,       List<Integer> budgetCosts) {     int[] inputIndices = IntStream.rangeClosed(0, budgetQuantities.size() - 1).toArray();     MaxQuantity maxQuantity = new MaxQuantity();     maxQuantity.value = Integer.MIN_VALUE;     permute(0, n, inputIndices, budgetQuantities, budgetCosts, maxQuantity);      return maxQuantity.value;   } }  class MaxQuantity {   int value; } 

xrandr: cannot find output “eDP-1”

I am trying to add some missing displays in ubuntu 16.04 system, I followed the following site for configuration:

http://ubuntuhandbook.org/index.php/2017/04/custom-screen-resolution-ubuntu-desktop/

dev@mysite-dev:~$   xrandr Screen 0: minimum 320 x 200, current 1024 x 768, maximum 8192 x 8192 VGA-1 connected primary 1024x768+0+0 (normal left inverted right x axis y axis) 0mm x 0mm    1024x768      60.00*     800x600       60.32    56.25      848x480       60.00      640x480       59.94   HDMI-1 disconnected (normal left inverted right x axis y axis) HDMI-2 disconnected (normal left inverted right x axis y axis) dev@mysite-dev:~$   cvt 1920 1080 # 1920x1080 59.96 Hz (CVT 2.07M9) hsync: 67.16 kHz; pclk: 173.00 MHz Modeline "1920x1080_60.00"  173.00  1920 2048 2248 2576  1080 1083 1088 1120 -hsync +vsync dev@mysite-dev:~$   sudo xrandr --newmode "1920x1080_60.00"  173.00  1920 2048 2248 2576  1080 1083 1088 1120 -hsync +vsync [sudo] password for dev:  dev@mysite-dev:~$   sudo xrandr --addmode eDP-1 "1920x1080_60.00" xrandr: cannot find output "eDP-1" dev@mysite-dev:~$    

As you can see I am getting the following error:

xrandr: cannot find output "eDP-1" 

How do I find the surface area of this function $y = e^{-x^2}$ when it’s rotated around the x-axis?

So I have this question:

Set up an integral for the area of the surface obtained by rotating the curve about the i) y axis and ii) x axis.

Let’s start with the xaxis problem:

$ y = e^{-x^2}$ from $ -1 \leq x \leq 1$

So for i), I’m going to use the formula:

$ $ \int_{-1}^1 2 \pi e^{-x^2} \sqrt{1 + \frac{dy}{dx}^2} dx$ $

$ \frac{dy}{dx} = e^{-x^2} * -2x$ and so $ \frac{dy^2}{dx} = 4x^2e^{-2x^2}$

Is that right? Did I do the squaring right?

So surface area = $ $ \int_{-1}^1 2 \pi e^{-x^2} \sqrt{1 + 4x^2e^{-2x^2}}dx$ $

Now I am stuck…

$ $ 2 \pi \int_{-1}^1 e^{-x^2} \sqrt{1 + 4x^2e^{-2x^2}}dx$ $

Can I u-sub $ u = e^{-x^2}$

`find /nfs/server/mount/data[12] -name data_*.gz > /dev/null` 4x slower the second time it’s executed – why?

An NFS server (it’s some sort of NAS appliance, I do not know what brand, nor anything about how it is configured) has a single filesystem exported and mounted on a Linux client. Server and client are both on the same local network. The remote filesystem is laid out like this:

/nfs/server/mount/data1/                         client_uuid_1/                                       data_20170101.gz                                       data_20170102.gz                                       ...                         client_uuid_2/                                       data_20170101.gz                                       data_20170102.gz                                       ...                         ...                   data2/                         client_uuid_3/                                       data_20170101.gz                                       data_20170102.gz                                       ...                         ... 

In total, there are order of 40,000 client_uuid_N directories and order of 300,000 data files. I noticed that a script that has to scan all of the directories for new data files was very slow just to do a glob operation, so I investigated further and I found this bizarre phenomenon:

The first time I run find /nfs/server/mount/data[12] -name data_*.gz > /dev/null after remounting the file system, it completes in roughly five minutes. That’s already painfully slow and suggests some sort of problem, but it gets weirder.

The second time I run that command, it takes four times longer — nearly twenty minutes. This is exactly backward from what I would expect.

Why might this be happening?

Trying to find real website merchants that accept Apple Pay or Google Pay (W3C Pay) as payment methods

I’ve been conducting technical research of the online payments sector, comparing many payment solutions. I’ve explored both the Apple Pay and Google Pay APIs and I see that they both support Web Integrations with Javascript APIs that would work directly through the Safari browser on a MAC with touch ID – in the case of Apple, and through Chrome and other browsers in the case of Google Pay).

I’m looking for real world implementation of the WEB APIs of Apple Pay and Google Pay. (Not Native apps. Not In-store NFC). I’m looking for website merchants that allow you to pay using Apple Pay or Google Pay (on the desktop – using your browser). So far not able to find any.

The only place I was able to find where you can pay with Apple pay through Safari is the Apple App Store itself – where you can buy hardware with Apple Pay, right in Safari on your iPhone (without installing any native apps).

I was not able to find any Google Pay web merchant implementations.

Google searches lead me on wild goose chases into many unrelated topics.

Can anyone suggest small niche merchants or websites they know for sure accept Apple Pay or Google Pay on their merchant websites?

I need to analyze their implementations and assess user experience and other factors…

Thanks.

How to easily find out which Google App Engine project is mapped to a custom domain?

I want to be able to generate a report of custom domains is a Google App Engine instance mapped to.

It is because I have a number of google app engine projects which are mapped to various different domains. There is no rule how these projects are mapped to domains. Instead of using the Google Cloud Platform and iterate through each playground, is there an easier to interrogate GCP and retrieve a mapping between instance and custom domains?

Where can I find more resource about how to handle huge input for a coding problem [on hold]

Take this question as example, https://leetcode.com/problems/game-of-life/

What about the input size is 1TB, 2TB that we can not accommodate the whole input data in memory. To this kind of question, what’s the proper term to search for this sort of questions? Is there any recommended book to read for this kind of question?

My idea for this question is to read three rows in memory at once. And shift a row at a time.