# Blogs

## C++: Why should I breakup my expressions?

### One Line Expressions

There has been and I'm sure there still are many talks about whether to write it all on one line or break up expressions on many lines.

### One Line Pros

The only pro I can think of for having everything on the same line is conciseness. For example:

*dst++ = *src++;

This is a very clear statement for most every C/C++ programmer.

I have to agree with this fact and I at times use such lines of code too...

### One Line Cons

Now, I write very large libraries and programs (thousands when not ten of thousands or even hundreds of thousand lines of code....) and it ...

## Meta-programming, promoting a type without changing the sign

Today I found that one of my functions would overflow. Here is a simplified version of it:

template<typename T>
T scale(T value, T position, T count)
{
return (value * position) / count;
}


As we can see, all variables are of type T. So if the multiplication overflows, the function returns an invalid result. To fix this, I wanted to promote all the variables to the latest possible integer (keeping the sign) or double (in my case the support for floating points was just for the type float so no need for long double.)

As a result I wrote a structure using meta-programming as ...

Today I wanted to work on the schedule of a project with the proper dependencies. More or less, I had the project tasks laid out as a long list (As I would if I were the only one to work on said project) and I needed to answer two main questions:

• How much will it cost?
• How many resources do we need?

The other question, which is always really hard to answer as a software developer, was: Can you make it happen in 6 months? But you know the answer to that one: Of Course! (and 6 months later: Not!)

So, I remembedered seeing a manager using MS Project which is what it is. In ...

## ASCII Art Pony

Isn't that cool?

I just find it really facinating that some people have an eye to draw anything with anything (in this case, a little pony with wings using just ASCII characters.)

Have you ever tried to come up with a drawing of your own that would look as good as this one?

      ,;;*;;;;,
.-';-');;.
/'  .-.  /*;;
.'    \d    \;;               .;;;,
/ o          \;    ,__.     ,;*;;;*;,
\__, _.__,'   \_.-') __)--.;;;;;*;;;;,
"";;;\       /-')_) __)  \' ';;;;;;
;*;;;        -') )_)  |\ |  ;;;;*;
...

## Getting a Proper Random Number on a Computer

99.9% of the time, I see people using random number generator in their software.

Say you have a random function b() that generates random bits. Each time you call b(), you either get 0 or 1.

Now, in most cases people are going to get a larger number, say you write a function r() which returns 8 such bits. You could write it like this:

int r()
{
return (b() << 7)
| (b() << 6)
| (b() << 5)
| (b() << 4)
| (b() << 3)
| (b() << 2)
| (b() << 1)
| (b() << 0);
}`

Assuming you have a ...

## Some Math

Mean

The mean of a set of values $(x_1, x_2, ..., x_n)$ is often represented by $\overline{x}$. The calculation of the mean is:

[display]\overline{x} = \mu = {\sum_{i=1}^n x_i \over n}[/display]

The mean may make use of weights (p):

[display]\overline{x} = \mu = {\sum_{i=1}^n x_i p_i \over \sum_{i=1}^n p_i}[/display]

You may want to normalize your weights, which means that their sum will equal 1, with the following:

[display]w_i = {p_i \over {\sum_{j=1}^n p_j}}[/display]

With normalized weights, you can simplify with the following:

[display]\overline{x} = \mu = ...

## Very Difficult Game of Shinsen-Sho

I like a game of Shisen-Sho once in a while. Usually, it's pretty easy. I may have to try 2 or 3 times, but I finish those games fast.

This one, though, it was way harder and it took me many tries before succeeding. But it worked. After a while and many attempts, I finally resolved it.

Unfortunately, the game does not allow us to save the game, I'm wondering whether the author would be willing to offer such an option at some point. I guess I have to post an issue asking such if it's not already available in the latest version.

There is the game as a screenshot (Click to ...

## Solve a in a power n equal b

Finding the value of a in equation (1):

 an = b (1)

can be resolved using logarithms.

First, transform equation (1) to equation (2):

 ln(an) = ln(b) (2)

Now we can easily extract the power (n) by changing it into a multiplication:

 n × ln(a) = ln(b) (3)

From equation (3), we know what the logarithm of a is equal to:

 (4)

Finally, we can write an equation as a = something.

 ...

I learned about Radon gas as I'm now working in Real Estate at Diverse Realty.

The gas reacts quickly and when that happens it emits some radio active energy. If you are close by, you will therefore be radiated.

We have found, over time, that a small amount of radiation is good for us. Not only that, we actually emit radiation ourselves. More than what Radon gas in our homes generates.

Actually, a smoke alarm system makes use of a decaying bit of radio active material. Those rays go in all directions for a long time.We channel a certain amount in two specific tubes, one of which is ...