MATHEMATICS

Minggu, 31 Juli 2011

The K programming language

Question

The decimal number, $585 = 10010010012_2$ (binary), is palindromic in both bases. Find the sum of all numbers, less than one million, which are palindromic in base 10 and base 2.

Problem 36  - Project Euler

Answer

+/&(&/{x~|x}'2 10_vs\:)'!_1e6

That is, in the K programming language. If Java is verbose then I would say that K is autistic. It has been estimated that there are not more than 1000 professional K-programmers. Most of them highly paid and employed in the high-end financial sector ( London, New York ).

Another example.

Question

The nth term of the sequence of triangle numbers is given by $t(n) = \frac{n (n+1) }{2}$, so the first ten triangle numbers are $1, 3, 6, 10, 15, 21, 28, 36, 45, 55$. By converting each letter in a word to a number corresponding to its alphabetical position and adding these values we form a word value. For example, the word value for SKY is $19 + 11 + 25 = 55 = t(10)$. If the word value is a triangle number then we shall call the word a triangle word. Using words.txt, a 16K text file containing nearly two-thousand common English words, how many are triangle words?

Problem 42  - Project Euler

Answer

+/((+/-64+6h$.:)'","\:*0:`words.txt)in{_.5*x*1+x}@!99

Again, in the K programming language. ( I used 4 lines in Mathematica, it would take 20+ lines in Java. )

Tidak ada komentar:

Posting Komentar