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

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

Project Euler Problem 17 – Number letter counts August 8, 2013

Filed under: Project Euler — whoami @ 19:56
Tags: ,

/* Warning: Donot try extracting answer from this and sumbit. This will not help you in Long Run */


/* Project Euler Problem 17 */
/*

If the numbers 1 to 5 are written out in words: one, two, three, four, five, then there are 3 + 3 + 5 + 4 + 4 = 19 letters used in total.

If all the numbers from 1 to 1000 (one thousand) inclusive were written out in words, how many letters would be used?

NOTE: Do not count spaces or hyphens. For example, 342 (three hundred and forty-two) contains 23 letters and 115 (one hundred and fifteen) contains 20
letters. The use of "and" when writing out numbers is in compliance with British usage.
*/

#include<stdio.h>
#include<string.h>

int main()
{

int i,j;
char str[100];

char str2[][100]={"one", "two", "three", "four", "five", "six", "seven", "eight", "nine",
"ten", "eleven", "twelve", "thirteen", "fourteen", "fifteen", "sixteen", "seventeen", "eighteen", "nineteen",
"twenty", "thirty", "forty", "fifty", "sixty", "seventy", "eighty", "ninety", "hundred",
"thousand"};
int tot=0;


for(i=1;i<1000;i++)
{
//one digit number 1-9
if(i/10 == 0)
{
tot+=strlen(str2[i-1]);
printf("%s\n",str2[i-1]);

}
//two digit number 10-99
else if(i/100 == 0)
{
if(i>=10 && i<=19)
{
tot+=strlen(str2[i-1]);
printf("%s\n",str2[i-1]);
}
else if( i%10 == 0 )
{
tot+=strlen(str2[18+i/10-1]);
printf("%s\n",str2[18+i/10-1]);
}
else
{
int unit=i%10;
int tens=(i/10)%10;
tot=tot+strlen(str2[unit-1]) + strlen(str2[18+tens-1]);
printf("%s-%s\n",str2[18+tens-1], str2[unit-1]);
}

}
//three digit number 100-999
else if(i/1000 == 0)
{
tot+=strlen("hundred");
if(i%100 == 0)
{
tot= tot + strlen(str2[i/100-1]);
printf("%s hundred\n",str2[i/100-1] );
}
else if(i%10 == 0)
{
int hundredth=i/100;
int tens=((i/10)%10);
if(tens == 1)
{
tot=tot+strlen(str2[hundredth-1]) + strlen("ten")+strlen("and");
printf("%s hundred and ten\n",str2[hundredth-1]);

}
else
{
tot=tot+strlen(str2[hundredth-1])+strlen(str2[18+tens-1])+strlen("and");
printf("%s hundred and %s\n",str2[hundredth-1],str2[18+tens-1]);
}
}
else
{
int hundredth=i/100;
int tens=(i/10)%10;
int units=i%10;

tot=tot+strlen(str2[hundredth-1])+strlen("and");
printf("%s hundred and ", str2[hundredth-1]);
if(tens == 1)
{
tot=tot+strlen(str2[9+units]);
printf("%s\n",str2[9+units]);
}
else if(tens == 0)
{
tot=tot+strlen(str2[units-1]);
printf("%s\n",str2[units-1]);
}
else
{
tot=tot+strlen(str2[18+tens-1]) + strlen(str2[units-1]);
printf("%s-%s\n",str2[18+tens-1], str2[units-1]);
}
}
}
//sleep(1);
}

tot=tot+strlen("onethousand");
printf("one thousand\n");
printf("%d",tot);
return 0;
}

Advertisements
 

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