Please refer to the example problem from the image attached. Can someone explain why only on 5th day all mothers cry? [Is it something related to ‘necessary’ & ‘sufficient’ conditions?]

# Tag: common

## For an abelian group, is the order of a+b the lowest common multiple of orders a+b

A true or false question, is there a counter example or short proof for this statement?

Let G be an abelian group. For all a, b ∈ G the order of a + b is the lowest

common multiple of the orders of a and b.

## How to organize common android UI components such as comment section?

I’m developing a social media app. One of the common components is the comment section. I’m wondering how I can organize my code better to reduce redundancy, because I think it doesn’t make sense if I created the same XML file for every screen that uses the comment section and all the logics needed. But if I make a reusable component will there be any drawbacks, in terms of flexibility and maintainability? I wanted to know what’s the best approach on this.

## design patterns – Is there a website to search for architectural approaches to solving common problems?

Suppose I want to build a graphics editor app.

Is there a place I can go (google isn’t helping) to find out what different people have done, how they’ve been able to extend on their design, etc?

Sort of like a search engine where you search for some feature/system capability and the results are solutions and different approaches one can take?

And maybe those are broken down by technology used:

- web, dekstop, mobile, etc

## design – Is it common / Does it make sense to reuse microservices in a desktop application?

Lets say we have a microservice architecture consisting of:

- multiple frontend clients, e.g. an Android App, an iOS App, and a Javascript Web Frontend
- a Java Spring (HTTP Rest) microservice to access user data
- a Java Spring (HTTP Rest) microservice to access application data
- a keycloak authentication microservice

Lets assume that all of this works fine with the backend microservices deployed in the cloud. Now, we want to create a desktop application. This desktop application should also work when the user does not have access to the Internet, given that he had Internet access before at some point.

Reusing the Javascript Web Frontend in the Desktop application is quite easy with Electron, that should not be a problem. In theory, we could ship the Electron app with the jar files of the Java Spring backend services, and let the Electron app start these in a background process (given that the user has Java installed). Then, after authenticating with the authentication microservice in the cloud, the app would have to download the user and application data and store it in a local database, e.g. a file-based SQLite DB. The backend microservices running locally would use this local DB as a source, therefore they are able to work without Internet access.

Does this make sense? Is it common? My thoughts on this are:

- Reusing a lot of code is super good, especially because the tasks of the Java Spring microservices would be exactly the same locally as in the cloud
- Requiring the user to have Java installed is not so good, it kind of ruins the nice Electron experience where everything is self-contained
- In reality, there might be more microservices, including stuff like Consul, maybe requiring the user to have more stuff installed. Running all of that on the user’s machine might be a overkill, also might be quite bad for performance

## algorithms – Find if two numbers are linked by a greatest common divisor

Two numbers $x,y$ are ‘connected’ if $gcd(x,y)>g$. Here $gcd$ is the greatest common divisor. A path exists between two numbers $x,y$ if given $g$ and $n$ there is a sequence of numbers that connect $x$ to $y$ such that all numbers along the path are less than or equal to $n$.

## linear algebra – Show all $ntimes n$ matrices which $AB=BA$ have a common eigenvector

If $S$ is the set of all complex $n times n$ matrices and for any two arbitrary $A$ and $B$ in $S$ we have $AB=BA$ then all matrices in $S$ have a common eigenvector.

I can show the result for two digonalizable matrix. But I don’t know how to show that for all matrices in $S$. Also there is no condition of being digonalizable in this question.

## linear algebra – Show all $ntimes n$ matrices which $AB=BA$ have a common eigenvector

If $S$ is the set of all complex $n times n$ matrices and for any two arbitrary $A$ and $B$ in $S$ we have $AB=BA$ then all matrices in $S$ have a common eigenvector.

I can show the result for two digonalizable matrix. But I don’t know how to show that for all matrices in $S$. Also there is no condition of being digonalizable in this question.

## algorithms – Find distinct groups with no common parents

Your privacy

By clicking “Accept all cookies”, you agree Stack Exchange can store cookies on your device and disclose information in accordance with our Cookie Policy.

## Euclidean algorithm to determine GCD (greatest common divisor) in C — alternative method

### Unnecessary function calls

My quick thought is that you are making an unnecessary function call.

```
unsigned temp;
while ((temp = a % b)) {
a = b;
b = temp;
}
```

The thing with the doubled parentheses is a hack to keep some compilers from warning you that you may be doing an unintentional assignment. It should make no functional difference.

This does fewer assignments. Three compared to four in your version. And it makes no function calls. Typically a function call is more involved than an assignment. Because it has to first save the current state, then jump somewhere else and do work, and finally restore the original state. The save and restore steps themselves often involve assignments. And those may be relatively expensive assignments from register to cache or memory. Whereas that loop can be done with three registers (or even two if the compiler optimizes out `temp`

by doubling the code).

```
while ((a = a % b)) {
if (!(b = b % a)) {
return a;
}
}
```

No `temp`

in that version, but duplicate logic. I wouldn’t normally recommend writing that code. But it would be a perfectly legitimate compiler optimization if there is a shortage of available registers.

Note: if you only call this function a few times, this won’t make a difference. Use whatever you find more readable. But if you are calling GCD in your main loop, it is possible that efficiency will matter. If efficiency does matter, my revised version (the first one) will (absent compiler optimizations) probably be faster than your version. While premature optimizations are to be avoided, there is little harm in picking the more efficient version if you have two working versions. And GCD is exactly the kind of problem that may be subject to profiling that would lead to that kind of optimization. So many sources may offer the best optimized algorithm rather than an alternative.

I find it a best practice to never use the statement form of control structures and always use the block form. I also prefer the brackets on the same line as the control structure. The latter is very much opinion, but the former is based on actual experience with bugs caused by editing.

### Be careful of types

I also find it a bit risky that your variables are `unsigned`

in the original function but `int`

in the `swap_numbers`

function. This presumably works because the `unsigned`

and `int`

types use the same storage width. But that’s an implementation detail. Is that implementation detail guaranteed always? I don’t know off-hand. Perhaps you already did that work and do know. But you don’t say that you know and there’s no comment explaining when you can and cannot use `swap_numbers`

.

For example, what would happen if used with an `unsigned long`

? On some systems, that might work because `int`

and `long`

are the same width. On other systems, you may only swap part of the numbers. Possibly only some of the time (because if the bytes that you are swapping happen to be the ones with data, it might not matter).

You might fix this by switching from pointers to handles (pointers to pointers).

```
void swap_numbers(void **a, void **b)
{
void *temp = *a;
*a = *b;
*b = temp;
}
unsigned euklid_iterative(unsigned *a, unsigned *b)
{
while ((*a = *a % *b))
{
swap_numbers(&a, &b);
}
return *b;
}
```

But it might be easier just to write a `swap_unsigned`

function. Or write out the swap entirely as I did originally.

All code in this post is untested. Not even for compilable syntax much less correct logic. Use at your own risk.