array – Finding number of possible arrangements of books on a shelf with a Monte-Carlo approach

The Problem

I am trying to determine numerically how many possible ways a number of books can be arranged on a shelf. Specifically, there are x3 categories “physics“, “sci-fi“, and “travel“. Each contains `N_phys`, `N_scifi`, and `N_travel` numbers of books respectively. Within their category, the books can be placed in any order, but they must stay within their respective category (i.e all the physics books together). The categories can then be arranged in any order (i.e I could have all the sci-fi books first, followed by travel, followed by physics, for example).

My Attempt

I have decided to label both each book and its category by integers, with “physics” = 1, “sci-fi” = 2, and “travel” = 3. The shelf is then a 2D array. So for example, a whole shelf could look like the following:

``````(3   2   1   4   1   2   2   1   3;   % Book ID
1   1   1   1   3   3   2   2   2)  % Categrory label
``````

where the the first 4 books are physics (because the second row is 1), followed by 2 travel books, and finally 3 sci-fi books, like this:

This problem can be solved easily and exactly as a permutation, and the result is `N_phys ! x N_scifi ! x N_travel ! x 3 !`. For `N_phys = 4`, `N_scifi = 3`, and `N_travel = 2`, the result is 1728 possible arrangements.

I have written a “brute-force” numerical attempt, shown below in Matlab, which seems to give the correct result:

``````N_phys = 4;   % Number of physics books
N_scifi = 3;  % Number of sci-fi books
N_travel = 2; % Number of travel books

books_physics = (1:N_phys;...
ones(1,N_phys)); % Collection of physics books

books_scifi = (1:N_scifi;...
2*ones(1,N_scifi)); % Collection of sci-fi books

books_travel = (1:N_travel;...
3*ones(1,N_travel));  % Collection of travel books

num_samples = 10000; % Number of random shelves to generate
unique_shelves = zeros(num_samples*2,N_phys+N_scifi+N_travel); % Preallocate

unique_shelves(1:2,:) = (books_physics books_scifi books_travel);
num_unique_shelves = 1;

% Generate "num_samples" permutations of shelves randomly
for sample_num = 1:num_samples

books_physics_shuffled = books_physics( :, randperm(N_phys) ); % Shuffle physics books
books_scifi_shuffled = books_scifi( :, randperm(N_scifi) );    % Shuffle sci-fi books
books_travel_shuffled = books_travel( :, randperm(N_travel) ); % Shuffle travel books

category_order = randperm(3,3); % Choose order of categories, e.g. sci-fi/phsycis/travel  = (2 1 3)

shelf = ();

% Arrange the categories in a random order
for k = 1:3
if category_order(k) == 1
shelf = (shelf books_physics_shuffled);
elseif category_order(k) == 2
shelf = (shelf books_scifi_shuffled);
elseif category_order(k) == 3
shelf = (shelf books_travel_shuffled);
end
end

% Iterate over discovered shelves, and see if we have found a new unique one
shelf_exists = 0;
for k = 1:num_unique_shelves
if shelf == unique_shelves( (2*k-1):(2*k),:)
shelf_exists = 1; % Shelf was previously discovered
break
end
end

if ~shelf_exists % New shelf was found
unique_shelves( (2*num_unique_shelves+1):(2*num_unique_shelves+2),:) = shelf; % Add shelf to existing ones
num_unique_shelves = num_unique_shelves + 1;
end

end

disp(('Number of unique shelves found = ',num2str(num_unique_shelves)))
disp(('Expected = ', num2str(factorial(N_phys)*factorial(N_scifi)*factorial(N_travel)*factorial(3) )))
``````

As can be seen, I am basically randomly generating a shelf, and then checking if it has been previously found. If it has, I add it to the list.

I am looking for feedback on the way this is implemented, and how it can be improved to make it more concise and efficient. Is there a better data structure for storing such “unique_shelves”, instead of the 2D array of integers as above? My code also doesn’t scale easily for more categories, since they are hardcoded.

Tips or alternative examples would be great! Thanks.

How to approach a web and app designer developer?

I have an idea for an app and a website that is needed to run the app. I need to make a cost report to find investors and to find the feasibility of implementing it. I would like to call web developers and app developers but I do not have any knowledge (I know about it roughly, but not the important stuff) about it. I also do not know the latest technical terms. I would like to get quotes regarding the cost, but I do not want to leak my ideas. Please give me some advice on what to ask, what to study to not be conned, how much to give away, how am I protected from theft, and other important stuff. Thank you.

I have made a static HTML website, but that is the max knowledge that I have. I know you can make a website using Wix, but that too is mostly static. I want to make a dynamic website where I am expecting at least 400-500 users working on it and the app to have a lot more users viewing it.

P.S. this question was asked 9 years ago on this website, but the links are now obsolete.

application design – Help with GUI development approach

Hey all Take it easy on me Newby and first time poster!

I’m looking for help planning out the best approach to a simple UI app that will be used to create and store various sizes of data (mostly just strings, integers and various length paragraphs)

Just for now I am only looking to use it on a Windows desktop environment but eventually would like to make it cross platform. So what I am really asking is

What would be the best language to use for this? I’m assuming that I’ll probably have to / will build a database down the line if I don’t / shouldn’t build one from the start.

8 – Approach to maintaining a custom, private, distribution

Our team has created a custom distribution complete with composer.json, deployment config files, lando files, a custom installation profile, htaccess configurations, etc. Downstream sites clone the upstream repo, run a few commands, and are up and running with a Drupal install in minutes.

Our goal is to maintain and leverage our custom distribution in a way that any modifications, additions, removals from upstream are communicated downstream.

Downstream sites won’t ever need to modify files from upstream so there should never be collisions or conflicts.

We tried to use git only but upon merging in changes from upstream, it warns about files that exist in the current repo that don’t exist in upstream, ultimately attempting to delete those files downstream. Ignoring or resetting those differences is not a viable option.

We want to be able to continuously update the upstream repo and pull those changes via composer (or git) as needed. We’d love for some checks and balances like release tags or composer to handle versioning for us.

I’ve tried treating the distro as a package (via gitlab) but instead of updating the downstream composer file on update, it simply adds the package as a dependency in composer.lock (sort of nesting it?)

What is the best practice approach for managing and maintaining a private, custom, Drupal distribution?

8 – Approach to maintaining custom, private, Drupal distribution

Our team has created a custom distribution complete with composer.json, deployment config files, lando files, a custom installation profile, htaccess configurations, etc. Downstream sites clone the upstream repo, run a few commands, and are up and running with a Drupal install in minutes.

Our goal is to maintain and leverage our custom distribution in a way that any modifications, additions, removals from upstream are communicated downstream.

Downstream sites won’t ever need to modify files from upstream so there should never be collisions or conflicts.

We tried to use git only but upon merging in changes from upstream, it warns about files that exist in the current repo that don’t exist in upstream, ultimately attempting to delete those files downstream. Ignoring or resetting those differences is not a viable option.

We want to be able to continuously update the upstream repo and pull those changes via composer (or git) as needed. We’d love for some checks and balances like release tags or composer to handle versioning for us.

Thoughts on implementation?

Why does the ratio of a chord and arc PQ in this unit circle approach 1 as PQ approaches 0?

I would like some help with this part in my textbook please:

It mentions that the chord and arc length of PQ approaches 1 as the arc PQ approaches 0; however I just can’t seem to see it. Thank you in advance.

python – Is this a good approach to stop a function when an error occurs and return appropriate response?

I am writing an API function using DRF where I want the API execution to stop if it fails in any of the steps and return an appropriate response. So I created a custom exception which takes an error code, and an error message like below.

``````class CustomException(Exception):
def __init__(self, status, msg):
self.status = status
self.message = msg
super().__init__(self.message + ': ' + str(self.status))

def __str__(self):
return 'ErrorCode: ' + str(self.status) + ' ErrorMessage:' + str(self.message)
``````

And I came up with the below code structure for the API function,

``````def place_order(request):
try:
response = is_cart_empty()
if response.status == 0:
err_msg = 'Cart cannot be empty'
raise CustomException(0, err_msg)

# Do something...

response = is_valid_user()
if response.status == 0:
err_msg = 'User is not valid'
raise CustomException(0, err_msg)

# Do something...

response = is_product_available()
if response.status == 0:
err_msg = 'Product out of stock'
raise CustomException(0, err_msg)

# Do something...

response_data = {
'status': 1,
'order_id': '1235'
}
except CustomException as e:
response_data = {
'status': e.status,
'error_message': e.message
}
except Exception as e:
traceback.print_exc()
print(e)
response_data = {
'status': 0,
'error_message': err_msg
}
return Response(data=json.dumps(response_data), status=status.HTTP_200_OK)
``````

I am using the same structure when I am accessing multiple resources like DB, AWS, external APIs etc, and if the code fails to work with any one of the resources.
Is this is a good design ? Is there any better/alternative way we can handle this ?

planning – Agile approach (vertical slicing) in ETL/ELT development

The question is: what do you think about using agile/iterative approach in ETL/ELT data warehouses/data lakes/lakehouses systems development? I often find that many business analysts / project managers tend to plan ingesting all data first, then building all semantic data and other horizontal layers only then build reports and go to the business. My experience is that ETL development is the area where agile approaches can bring most value to avoid rework risks. I have drawn the diagram in endeavour to make the point and to use this as an argument for vertical slices planning as opposed to horizontal ETL/ELT implementation.

What is your approach to developing an SEO strategy?

What is your approach to developing an SEO strategy?

.

How to approach a Poisson’s Equation of a square domain

As someone with severe Asperger’s I can’t understand programming and after 100s of hours trying to learn it just doesn’t click.

I am looking for any suggestions on material to learn to solve an equation such as

Poisson equation on a square domain of 51 by 51

$$U_(xx_) + U_(yy_) = xy$$

$$𝑢(0,y)=0; 𝑢(x, 0)=0; 𝑢_𝑛(51,y)=𝑥; u_n(x, 51)=y$$