Showing posts with label human brain. Show all posts
Showing posts with label human brain. Show all posts

Sunday, April 26, 2015

    As soon as completed, it will be possible for a business man in New York to dictate instructions, and have them instantly appear in type at his office in London or elsewhere. He will be able to call up, from his desk, and talk to any telephone subscriber on the globe, without any change whatever in the existing equipment. An inexpensive instrument, not bigger than a watch, will enable its bearer to hear anywhere, on sea or land, music or song, the speech of a political leader, the address of an eminent man of science, or the sermon of an eloquent clergyman, delivered in some other place, however distant. In the same manner any picture, character, drawing, or print can be transferred from one to another place. Millions of such instruments can be operated from but one plant of this kind.
    More important than all of this, however, will be the transmission of power, without wires…

© Nikola Tesla


Thursday, May 17, 2012

Do not be afraid to seem a fool

"Do not be afraid to seem a fool, be afraid to be a fool." (c)

Tuesday, May 15, 2012

Project Euler, problem 13 solution

Problem 13

Let's use the power of math coprocessor ;)

JavaScript (Spider Monkey)

var numbers = [
    3.7107287533902102798797998220837590246510135740250,
    4.6376937677490009712648124896970078050417018260538,
    ............... etc
    5.3503534226472524250874054075591789781264330331690
];

var sum = 0;
for(var i = numbers.length - 1; i > -1; --i) {
    sum += numbers[i];
}
var result = sum * 10000000000;
print(result.toString().substring(0,10));

// time: 0.01s memory: 4984 kB

Congratulations, the answer you gave to problem 13 is correct.
You are the 67470th person to have solved this problem.

Friday, May 11, 2012

Project Euler, Problem 5 solution

Problem 5

First of all I wanted refresh my school math knowledge here.
Then I've wrote the optimized program.
And then I read this:

"24 Jul 2004 01:43 am
bitRAKE (Assembler)

This does not require programming at all.
Compute the prime factorization of each number from 1 to 20, and multiply the greatest power of each prime together:
20 = 2^2 * 5
19 = 19
18 = 2 * 3^2
17 = 17
16 = 2^4
15 = 3 * 5
14 = 2 * 7
13 = 13
11 = 11
All others are included in the previous numbers."

So you better type into Linux command shell 'bc' and then 2^4 * 3^2 * 5 * 7 * 11 * 13 * 17 * 19


Congratulations, the answer you gave to problem 5 is correct.
You are the 131586th person to have solved this problem.

Sunday, May 6, 2012

How to determine whether a number is degree of given number?

For example, 128 is 27, 65536 is 216 etc.
Question: how to determine whether a number 794889263257962974796277498092801308291525640763748664903194643469338087775424965801409745320266996710649718116931109481559848982586784968419475084821084743272680947722675151641735826243378403750534655587182832000457137589153821622272 is degree of 2 or not?
Answer: f**k off it is easy :)

Well, how?

OK, let's consider the case with 2. We have the number system with base of 2, where:
decimal 0 == binary 0
decimal 1 == binary 1
decimal 2 == binary 10
decimal 4 == binary 100
decimal 8 == binary 1000
decimal 16 == binary 10000
etc.

Don't you see now, how to? ;)

Question: how to determine whether a number 340282366920938463463374607431768211456 is degree of 16 or not?
Answer: ? (But now you know, how to get it!)

Monday, April 30, 2012

Project Euler, Problem 16 solution

Problem 16

I like Free Software Foundation, Inc.
I like to use the right tool for the right job too.
So to get the number I typed 'bc' in the Linux command line and then '2^1000'.
Well, now I am ready to calculate the sum via JavaScript (SpiderMonkey):

 
var a="copypasted value from my command line as STRING";
var sum = 0;
for(var i = a.length - 1; i > -1; --i) sum += parseInt(a.charAt(i));
print(sum);

(time: 0.02s memory: 4984 kB on usual PC)

Congratulations, the answer you gave to problem 16 is correct.
You are the 70718th person to have solved this problem.

Project Euler, Problem 15 solution

Problem 15

"Starting in the top left corner of a 2×2 grid, there are 6 routes (without backtracking) to the bottom right corner. How many routes are there through a 20×20 grid?"

This problem is about permutations and so called central binomial coefficient (the binomial theorem you must remember from the school). And do you remember the Pascal's triangle? If not, check it here. (If you still don't understand what I am talking about you can see the complete solution here).
All you need is to observe that for a NxN grid there are (2n)!/(n!)2 possible ways of getting from one corner to the other one and in our case it will be 40!/(20!)2. If you are still unable to calculate it you can use A000984.
But if you still want to get the answer by yourself, do not rush to crack factorials with your lovely brute force with 350 lines of C++ code, let's start from... little cheat.
We have some ways for cheat.
Of course we could use the J language to get the central binomial coefficient:
(! +:) 20x
or even more shorter:
20!40x
but it isn't real cheat. There is a better way: http://www.google.com/search?q=40+choose+20
Bingo? Btw. tell me truth, did you know that the Google calculator has the operator 'choose'? Brilliant, isn't? You just command "40 choose 20" and Google gives you the answer: please, master! Try the same way to ask Google for money ;)


Well, now let's start thinking.

Rudy Penteado from Brazil codes in Assembler language. He discovered that:
"This is what I find 2 months ago when I solved it:
Each movement in the horizontal is a zero.
Each movement in the vertical is a one.
1st binary# in this series:
0000000000000000000011111111111111111111
last:
1111111111111111111100000000000000000000
For the numbers in between, the amount of zeros should be the same as ones.
In other words, the ones and zeros have to be rearranged."

Easy, isn't? Try to code this in Assembler.
I won't. I did my solution with some magic too:

JavaScript (Spidermonkey)

var ans = 1;
for(var c = 40, d = 1; c > 20; --c, ++d) ans = (ans * c)/d;
print(ans);

// time: 0.02s memory: 4984 kB

Congratulations, the answer you gave to problem 15 is correct.
You are the 53180th person to have solved this problem.

Sunday, April 29, 2012

Project Euler, Problem 8 solution

"Problem 8
Find the greatest product of five consecutive digits in the 1000-digit number."

Well, this problem can be solved even without computer.
Just use the best tool that you never had: your brain ;)
Use the "Find" command in your favorite text editor to highlight all 9 in the given 1000-digit number.
Is it not easy to find a combination of 99879?


But if you wanna code:

JavaScript (Spidermonkey)

var initial = [the given 1000-digit number as array of integers];
var answer = 0;
var sum = 0;
var bestsum = 0;
var tarr = [5];
for(var c = initial.length - 1; c --> 3;) {
    sum = 0;
    for(var s = c; s > c-5; --s)
        sum += initial[s];

    if(sum > bestsum) {
        bestsum = sum;
        for(var j = c, i = 4; j > c-5; --j, --i)
            tarr[i] = initial[j];
    }
}
answer = tarr[0] * tarr[1] * tarr[2] * tarr[3] * tarr[4];
print(answer);