Monday, February 1, 2021

Life is similar to fire

 Similarities between life (as in organisms) and fire:

- If it all goes out (dies), it has to start again by an event happening. For fire you would have to create sparks and for organisms some chain of events would have to happen.

- Life and fire reproduce

- They create heat, and get the heat from a fuel


It makes me think, the most important thing to organisms could be things that relate to fire. For example, reproducing is like fire (and obviously people think it's important). If you were a candle, you would be taking another candle and lighting it, and then you will die, but the candle you lit will survive you. Then the candle (your offspring) will do the same thing.

Another one of these things is knowledge, where if all the humans for example, forgot an idea, it would have to be discovered again.

Not just knowledge in the mind, but physical knowledge too, because the body of an organism is an expression of its surroundings, like the terrain, temperature, and other organisms in its habitat. The human physical form is physical information about the surroundings of that human and its ancestors.

The difference with this physical and mental knowledge though, is that the physical information is lost forever when the organism dies, unless a clone is made.


Sunday, November 29, 2020

Thinking is feeling

 I believe when you're able to read your thoughts, you're subconsciously feeling them.

To start off, all of the five senses are feeling in some way. 

Touching = feeling

Tasting = feeling, but picking up different things than normal touching

Smelling = feeling the particles

Hearing = feeling the vibrations

Seeing = feeling vibrations, but different vibrations than hearing


I think that humans subconsciously feel their brain from the inside and that's how we're able to read our own thoughts, but some are unreadable, which is the subconscious. 

If it's true, this leads to something else, which is that if you subconsciously feel another part of your body like your gut, what data do you get from it?

Friday, February 28, 2020

10 Identical Bottles of Pills "Variant"

The statement was

We have 10 identical bottles of identical pills (each bottle contain hundred of pills). Out of 10 bottles 9 have 1 gram of pills but 1 bottle has pills of weight of 1.1 gram. Given a measurement scale, how would you find the heavy bottle? You can use the scale only once.

And I misunderstood the problem as that the 9 bottles each had 1 gram worth of pills, so each pill in the 9 bottles would weigh in the range [0, 1].

My answer to this problem was like the original problem's solution, but to make it obvious which bottle it was, you needed to add more pills from each bottle.

Let's say we're weighing bottle 1, and we want to add pills from the remaining 9 bottles.

- If the answer is bottle 1, the weight will be in the range [110, 110+]
- If the answer is the last bottle that we don't add pills to the scale from, the weight will be in the range [1, 9]
- If the answer is bottle b and we added x pills from bottle b to the scale, the weight will be in the range [1+b*1.1, 8+b*1.1]

The lower bound is 1+b*1.1 because in the lowest case, all the pills from the bottles will be 0, and the +1 comes from putting the whole bottle of 1 on the scale.

The upper bound is 8+b*1.1 because we only need to add pills from all but 1 bottle since if the last bottle we don't use is the heaviest, the weight will be in the range [1, 9].

To avoid these weight ranges from conflicting so we can uniquely determine the heavier bottle, the number of pills added from each bottle will be in order from 1 to 10:
100, 10, 20, 30, 40, 50, 60, 70, 80, 0

The ranges of the weights for each of these amounts if that bottle is the heaviest will be:
[110, 110+], [12, 19], [23, 29], [34, 41], [45, 52], [56, 63], [67, 74], [78, 85], [89, 96], [1, 9]

Wednesday, October 2, 2019

Intuitive way to solve MAXEXPR

This isn't my solution but it's an intuitive solution without obvious math like Lagrange or Cauchy Schwarz. 
link

Sunday, August 11, 2019

Codeforces 1200D - White Lines Solution

Tags: prefix sums

The first thing you should think when you see this problem is prefix sums because it looks like this problem can be done in O(n*n).

1. Count the number of white lines there already are (like in WWW there's already 1 white line)

2. Create 2 arrays, a 2D horizontal prefix sum array and a 2D vertical prefix sum array.

3. For each horizontal line from the left then, if it's at most K places away from becoming a line horizontally, mark that position as 1.
Example 1:
BBB
WBB
BBB

If K = 2, the horizontal sum array (before you spread the sums to be a prefix sum array) would be
0 0 0
0 1 0
0 0 0

If K = 3, the horizontal sum array would be
1 1 1
1 0 0
1 0 0

4. For each vertical line from the top, if it's at most K places away from becoming a line vertically, mark that position as 1.
Example 2:

If K = 1, the vertical sum array would be
0 0 0
0 1 0
0 0 0

If K = 2, the vertical sum array would be
0 1 0
0 1 0
0 0 0

5. Then, you spread the sums. For the horizontal sum array, you spread the sums vertically and for the vertical you spread them horizontally.
Like the K = 2 array from Example 1, when you spread it vertically, it looks like this:
0 0 0
0 1 0
0 1 0

And for the K = 1 array from Example 2, you spread it like this:
0 0 0
0 1 1
0 0 0

You find out why we do it this way in step 6.

6. Iterate through all the cells where you can put the eraser (i = 1, 2, 3... N-K, j = i, 2, 3... N-K). From the horizontal sum array, get the vertical sum of the column j. Then from the vertical sum array, get the horizontal sum of the row i. These sums add to the number of lines because they are the number of lines that need at most K more cells to form lines. I think it's easier to understand in an example.


From example 2, we have
BWB
BBB
BWB

Let's say K = 2.

The vertical sum array will be
0 1 0
0 1 0
0 0 0

The horizontal sum array will be
0 0 0
0 0 0
0 0 0

Then, after we spread the sums, the vertical sum array will be
0 1 1
0 1 1
0 0 0

Then, we check every cell. If we check cell (0, 1), the sum we get is 1.
0 1 0 (getting the sum of 0+1 from the prefix array above)
0 1 0
0 0 0
Which is 1, and we can get this from the prefix sum array (the one above this array)  by doing arr[0][2]-arr[0][0].

Another example:
BWB
WBW
BWB
K = 1

The vertical array will be
0 0 0
0 1 0
0 0 0

The horizontal array will be
0 0 0
0 1 0
0 0 0

Spreading the sums, the vertical array will be
0 0 0
0 1 1
0 0 0

The horizontal array will be
0 0 0
0 1 0
0 1 0

When we try (1, 1),  the sum we get is in the bolded parts above (we only go 1 far since K = 1).

My submission: https://codeforces.com/contest/1200/submission/58621782

Thursday, August 8, 2019

Codeforces 1202B - You Are Given a Decimal String Solution

Tags: brute force

The realization to this problem to make is that even though there can be up to 2*10^6 characters in the string, the number of combinations of 2 adjacent characters is 10*10 (00, 01, 02... all combinations). So then, for each of these combinations, you calculate the frequencies of each combination and keep that in an array. 

Then, you iterate over every counter (0-0, 0-1, 0-2...) let's call them and j, and then for each counter, iterate over all combinations of possible adjacent characters (00, 01, 02...), let's call the first one a and second one b (like in 01, a is 0 and b is 1). Use a BFS (breadth first search) to find the shortest path from a to b using the i-j counter, and make sure that if a == b, then the BFS doesn't end when you put a into the queue (because the BFS checks if the current node is equal to b). If it's not possible for the i-j counter to reach b, then the answer for this counter is -1. Otherwise, the answer is (the frequency of a and b next to each other in the string)*((shortest distance from a to b using i-j counter)-1), and this is added to the sum for this counter. There's a -1 for the distance from a to b because the distance still counts b, which is already in the string.

Example:

08408

For the frequencies:
08: 2
84: 1
40: 1

Then iterate over each counter:
Let's say, i = 0  j = 1 (counter 0-1)
Then iterate over each adjacent number combinations:
Let's say, a = 0  b = 8
Starting from 0, the minimum distance from 0 to 8 using a 0-1 counter is 8. Since 08's frequency is 2, we add 2*(8-1) to the 0-1 counter's sum.

My submission (I'm using links w/ ads, tell me if it doesn't work for you): http://stfly.io/uhWA3r

Tuesday, August 6, 2019

Nature Logic Problem

Sometimes you see a spider web that spans from one place to another far place. For example, there's 2 trees next to each other and there's a string of spider silk 4 feet long between them. Assuming the spider can't jump/crawl from one tree to another, how does it get it's silk string to go from one tree to the other tree? (Look it up to see the answer)