C,C++/JAVA/BASH/ASM ARENA

वह प्रदीप जो दीख रहा है झिलमिल दूर नही है थक कर बैठ गये क्या भाई मन्जिल दूर नही है चिन्गारी बन गयी लहू की बून्द गिरी जो पग से चमक रहे पीछे मुड देखो चरण-चिनह जगमग से बाकी होश तभी तक, जब तक जलता तूर नही है थक कर बैठ गये क्या भाई मन्जिल दूर नही है अपनी हड्डी की मशाल से हृदय चीरते तम का, सारी रात चले तुम दुख झेलते कुलिश का। एक खेय है शेष, किसी विध पार उसे कर जाओ; वह देखो, उस पार चमकता है मन्दिर प्रियतम का। आकर इतना पास फिरे, वह सच्चा शूर नहीं है; थककर बैठ गये क्या भाई! मंज़िल दूर नहीं है। दिशा दीप्त हो उठी प्राप्त कर पुण्य-प्रकाश तुम्हारा, लिखा जा चुका अनल-अक्षरों में इतिहास तुम्हारा। जिस मिट्टी ने लहू पिया, वह फूल खिलाएगी ही, अम्बर पर घन बन छाएगा ही उच्छ्वास तुम्हारा। और अधिक ले जाँच, देवता इतन क्रूर नहीं है। थककर बैठ गये क्या भाई! मंज़िल दूर नहीं है।

Project Euler Problem 57 – Square root convergents March 22, 2013

Filed under: Project Euler — whoami @ 11:33
Tags: , , , ,

It is possible to show that the square root of two can be expressed as an infinite continued fraction.

√ 2 = 1 + 1/(2 + 1/(2 + 1/(2 + … ))) = 1.414213…

By expanding this for the first four iterations, we get:

1 + 1/2 = 3/2 = 1.5
1 + 1/(2 + 1/2) = 7/5 = 1.4
1 + 1/(2 + 1/(2 + 1/2)) = 17/12 = 1.41666…
1 + 1/(2 + 1/(2 + 1/(2 + 1/2))) = 41/29 = 1.41379…

The next three expansions are 99/70, 239/169, and 577/408, but the eighth expansion, 1393/985, is the first example where the number of digits in the numerator exceeds the number of digits in the denominator.

In the first one-thousand expansions, how many fractions contain a numerator with more digits than denominator?

Euler57

 

Project Euler Problem 204 Generalised Hamming Numbers March 21, 2013

Filed under: Project Euler — whoami @ 08:46
Tags: , , , ,

A Hamming number is a positive number which has no prime factor larger than 5.
So the first few Hamming numbers are 1, 2, 3, 4, 5, 6, 8, 9, 10, 12, 15.
There are 1105 Hamming numbers not exceeding 108.

We will call a positive number a generalised Hamming number of type n, if it has no prime factor larger than n.
Hence the Hamming numbers are the generalised Hamming numbers of type 5.

How many generalised Hamming numbers of type 100 are there which don’t exceed 10^9?

Hint: Generate prime number less than 100. Check for all the number in range 1-10^9, whether all prime number <100 divides them totally to get final remaining number as 1. Is this happens for particular number then add it to your list otherwise don’t add the number to the list.

euler204

 

Project Euler Problem 206 Concealed Square March 20, 2013

Filed under: Project Euler — whoami @ 12:41

Find the unique positive integer whose square has the form 1_2_3_4_5_6_7_8_9_0,
where each “_” is a single digit.

My solution..PROJECT EULER PROBLEM 206 – Concealed Square

 

My misconception about Compound assignment operators in C,C++ March 18, 2013

Filed under: Uncategorized — whoami @ 09:41
Tags: , , ,

Today i got cleared of a very big misconception about Compound assignment operators.

I had wrongly understood statements like

A -=b+c as A=A-b+cBut correct is A -=b+c is same as A = A – (b+c)

More explanation can be find here

I have built this wrong concept because in elementary C books there was rarely mentioning of three variables for compound assignment operator examples. Like

The last example(bottom) below i never came through 😦

expression

evaluation

value += increase;

value = value + increase;

a -= 5;

a = a - 5;

a /= b;

a = a / b;

price *= units + 1;

price = price * (units + 1)