கணக்கு போடலாமா?

வித்தை தெரிந்தால், நீங்களும் புலியே!

Saturday 29 January, 2011

ஒன்பது இலக்க எண்

கண்டு பிடிங்க : - ஒரு ஒம்போது டிஜிட்டு நம்பர் .. 1 முதல் 9 வரை உள்ள எல்லா முழு எண்களும், ஒவ்வொரு எண்ணும் ஒரேமுறை மட்டுமே வருமாறு அமைந்தது..

இடது பக்கம் முதல் n டிஜிட்டுகள 'n 'ஆல வகுத்தா மிச்சம் வராது..
( for all the values of 'n' = 1, 2, 3, 4, 5, 6, 7, 8, & 9 )

உதாரணம்..
'123456789 '
இதுல இடது பக்கம் முதல், வரும் முதல் டிஜிட் 1 , ஒன்னால் வகுபடும், மீதி இல்லாமல்)
முதல் இரண்டு இலக்கங்கள்  '12 ' - இரண்டால் வகுபடும்.

ஆனால்..
1234 / 4
308 ஈவு ( quotient ), 2 (remainder ) மீதி வரும்.

1234567 / 7
176366 ஈவு  ( quotient  ) -- 5 மீதி (remainder )  வரும்.

எனவே அந்த எண் 123456789 கிடையாது..

சரியான எண்னை கண்டுபிடியுங்கள் பார்க்கலாம் ?

இந்த புதிரை எனது நண்பர் ஒருவரும், நானும் சேர்ந்து ஒரு இரவு முழுவதும் கலந்தாலோசித்து விடையை கண்டு பிடித்தோம். அதன் அடுத்த தினம், 'சி' புரோக்ராம் எழுதியும் கண்டுபிடிக்க வகை செய்தேன் ( பன்னிரண்டு ஆண்டுகளுக்கு முன்னர் ).
விடையுடன், அந்த 'சி' புரோக்ராமையும் தருகிறேன், வேண்டுமானால். போர்ட்ரானிலும்   பிரோக்ராம் எழுதியுள்ளேன். அல்காரிதம் (வெரி சிம்பிள்) தந்தால் கூடப் போதுமோ ?


இதற்கு ஒரே ஒரு விடைதான் இருக்கிறது.. அது இதான் சிறப்பம்சம்.

விடை கண்டுபிடித்த அனைவருக்கும் வாழ்த்துகள்.  (ஏதோ.. என்னால முடிஞ்சது)

#include<stdio.h>
main()
{
int i1,i2,i3,i4,i5,i6,i7,i8,i9,n,j1,j2,j3,j4,j5,j6,j7,j8,j9,nn;

j1=1; j2=10; j3=100; j4=1000; j5=10000; j6=100000; j7=1000000; j8=10000000; j9=100000000;

for(i1=1;i1<=9;i1++)
{
for(i2=1;i2<=9;i2++)
{
n=(i2*j1+ i1*j2)%2;
if(n==0)
{
for(i3=1;i3<=9;i3++)
{
n=(i3*j1+ i2*j2+ i1*j3)%3;
if(n==0)
{
for(i4=1;i4<=9;i4++)
{
n=(i4*j1+ i3*j2+ i2*j3+ i1*j4)%4;
if(n==0)
{
for(i5=1;i5<=9;i5++)
{
n=(i5*j1+ i4*j2+ i3*j3+ i2*j4+ i1*j5)%5;
if(n==0)
{
for(i6=1;i6<=9;i6++)
{
n=(i6*j1+ i5*j2+ i4*j3+ i3*j4+ i2*j5+ i1*j6)%6;
if(n==0)
{
for(i7=1;i7<=9;i7++)
{
n=(i7*j1+ i6*j2+ i5*j3+ i4*j4+ i3*j5+ i2*j6+ i1*j7)%7;
if(n==0)
{
for(i8=1;i8<=9;i8++)
{
n=(i8*j1+ i7*j2+ i6*j3+ i5*j4+ i4*j5+ i3*j6+ i2*j7+ i1*j8)%8;
if(n==0)
{
for(i9=1;i9<=9;i9++)
{
nn=(i9*j1+ i8*j2+ i7*j3+ i6*j4+ i5*j5+ i4*j6+ i3*j7+ i2*j8+ i1*j9);
n=nn%9;
if(n==0 && i1!=i2 && i1 != i2 && i1 != i3 && i1 != i4 && i1 != i5 && i1 != i6 && i1 != i7 && i1 != i8 && i1 != i9 && i2 != i3 && i2 != i4 && i2 != i5 && i2 != i6 && i2 != i7 && i2 != i8 && i2 != i9 && i3 != i4 && i3 != i5 && i3 != i6 && i3 != i7 && i3 != i8 && i3 != i9 && i4 != i5 && i4 != i6 && i4 != i7 && i4 != i8 && i4 != i9 && i5 != i6 && i5 != i7 && i5 != i8 && i5 != i9 && i6 != i7 && i6 != i8 && i6 != i9 && i7 != i8 && i7 != i9 && i8 != i9 )
printf("The number is %d \n",nn);
} } } } } } } } } } } } } } } } }
---------------------------------------

22 comments:

மதுரை சரவணன் said...

புரியல...

அனு said...

ஹிஹி.. நான் நினைச்ச அளவுக்கு இந்த கணக்கு அவ்வளவு ஈஸி இல்ல.. இது வரைக்கும் ஒரு ஃபுல் பேப்பர் காலியாகிடுச்சி.. :)

ஆன்ஸர் கண்டுபிடிக்கறதுக்கு இன்னும் எவ்வளவு பேப்பர் (A4) தேவைப்படும்னு சொல்ல முடியும்களா??

middleclassmadhavi said...

381654729

அனு said...

அஞ்சாறு பேப்பர், நாலஞ்சு பிஸ்கட், ரெண்டு மூணு காபிக்கு அப்புறம் ஒரு வழியா விடைய கண்டுபிடிச்சாச்சு..

Answer is 381654729

எப்படி கண்டுபிடிச்சேன்னு explain பண்ண முடியல.. :(
Divisibility Rules + Calculator + konjam logic..

4th,5th,6th positionல இருந்து ஆரம்பிக்கறது ஈஸின்னு நினக்கிறேன்.. coz we know that it is divisible by 3, 5th position is '5'. 6th digit is even no

அனு said...

my two cents:
இதுல 0வையும் include பண்ணியிருந்தா that 10 digit number can be divided by 10 'coz the last digit will be '0' :)

இந்த கணக்கு கஷ்டமா இருந்தாலும் இண்ட்ரெஸ்டிங்கா இருந்தது..

எஸ்.கே said...

பதில் :

381654729

3 - 1ஆல் மீதமின்றி வகுபடும்
38 - 2ஆல் மீதமின்றி வகுபடும்
381 - 3ஆல் மீதமின்றி வகுபடும்
3816 - 4ஆல் மீதமின்றி வகுபடும்
38165 - 5ஆல் மீதமின்றி வகுபடும்
381654 - 6ஆல் மீதமின்றி வகுபடும்
3816547 - 7ஆல் மீதமின்றி வகுபடும்
38165472 - 8ஆல் மீதமின்றி வகுபடும்
381654729 - 9ஆல் மீதமின்றி வகுபடும்

ரமேஷ்- ரொம்ப நல்லவன்(சத்தியமா) said...

Maths? hehe. no idea

பெசொவி said...

எஸ்கே, அனு & middleclassmadhavi
விடை சரி.

Madhavan Srinivasagopalan said...

// my two cents:
இதுல 0வையும் include பண்ணியிருந்தா that 10 digit number can be divided by 10 'coz the last digit will be '0' :) //

இதத்தான் பத்தோட பதின்னொன்னு.. சாரி.. சாரி... ஒம்போதொட பத்துனு சொல்லுவாங்களோ ?
நல்ல ஐடியா..?

Madhavan Srinivasagopalan said...

// ஆன்ஸர் கண்டுபிடிக்கறதுக்கு இன்னும் எவ்வளவு பேப்பர் (A4) தேவைப்படும்னு சொல்ல முடியும்களா?? //

கணணி இருக்க பேப்பறேன் ?

Madhavan Srinivasagopalan said...

// மதுரை சரவணன் said...

புரியல... //

நாலஞ்சு படிச்சுப் பாருங்க புரியும்..

வெங்கட் said...

The ANSWER is

381654729

மாலா ( Mrs.Venkat ) said...

@ அனு.,

// ஹிஹி.. நான் நினைச்ச அளவுக்கு
இந்த கணக்கு அவ்வளவு ஈஸி இல்ல..
இது வரைக்கும் ஒரு ஃபுல் பேப்பர் காலியாகிடுச்சி.. :) //

இது ரொம்ப ஈஸியான கணக்கு தான்..
நான் 10 Mins கண்டுபிடிச்சிட்டேன்..

ஆன்ஸர் 381654729

வெங்கட் said...

@ மாலா.,

// நான் 10 Mins கண்டுபிடிச்சிட்டேன்.. //

நான் 2 Mins-ல கண்டுபிடிச்சிட்டேன்..
எந்த வெப்சைட்ல இதுக்கு Answer
இருக்குன்னு..

ஹி., ஹி., ஹி..!!!

http://puzzles4you.blogspot.com/2008/05/what-is-9-digit-number.html

பெசொவி said...

@ Mala(Mrs. Venkat)

Congrats!

@ Venkat
Congrats (for getting the answer from your wife and posting here) :)

Madhavan Srinivasagopalan said...

மேலே உள்ள 'சி' பிரோக்ராம்மை, gccயில் compile செய்து, execute செய்யவும்.

Thanks to all.. keep coming.

அனு said...

@மாலா

//இது ரொம்ப ஈஸியான கணக்கு தான்..
நான் 10 Mins கண்டுபிடிச்சிட்டேன்..//

ஹிஹி... நீங்க யாரு.. உங்க பரம்பரை என்ன.. இதெல்லாம் ஒரு பெரிய கணக்கா உங்களுக்கு??

(நிறைய பேரு சொல்லியிருக்குறத பாத்தா இது ஈஸியான கணக்கு தான் போல.. நான் தான் குழம்பியிருக்கேன் :) )

அனு said...

@Madhavan
//மேலே உள்ள 'சி' பிரோக்ராம்மை, gccயில் compile செய்து, execute செய்யவும்//

இதில் looping ஜாஸ்தியாக இருப்பதால் system performance கம்மியாகிடும்.. இதுக்கு பதிலா ஒரு integer array எடுத்து 1 to 9 store பண்ணி அதை conditionக்கு தகுந்த bubble/quick sort பண்ணினா answer சீக்கிரம் கிடைச்சிடும் :) (For checking, array has to be converted to number by multiplying digits with 10,100... according to their places)

இப்படிக்கு,
எதிலும் குற்றம் கண்டுபிடிப்போர் சங்கம் :)

middleclassmadhavi said...

வெங்கட் - //நான் 2 Mins-ல கண்டுபிடிச்சிட்டேன்..
எந்த வெப்சைட்ல இதுக்கு Answer
இருக்குன்னு..//

இந்த வெப்சைட்டப் பாருங்க, இதே படத்தோட இருக்கு!
http://www.puzzlelog.com/2010/09/nine-digit-number.html

Madhavan Srinivasagopalan said...

ஆமாம் அனு..
இதை விட வேகமா எக்ஸிகூட் பண்ணுற எபிசிஎன்ட் பிரோகிராம் எழுதலாம். நா சிம்பிளா எழுதினேன். முடிஞ்சா எழுதி எனக்கு ஈமெயில் பண்ணுங்க.. தாங்க்ஸ்.

நா சொல்ல method நெறையா லூப் இருக்கு.
ஆனால் விடை டக்குனு வந்திடுது.. நா என்ன ராக்கெட்டா விடப் போறேன், மைக்ரோ செகண்டுல விடை எதிர் பாக்குறதுக்கு.

நன்றி மாதவி..
எனக்கு திரிந்த இந்த கணக்கை, கூகிள் உதவியோடு படம் தேர்ந்தெடுத்தேன்.
எல்லா மேட்டரையும் தெரிஞ்சு காப்பி அடிக்கல..

@ ஆல்

உங்களுக்குத் தெரிந்த கணக்கு அல்லது பசில்ல உங்களோட பில்லாகுல (அனு ?) அல்லது எங்களுக்கு அனுப்பினா இந்த பிளாக்ல போடுறோம்..

"யாம் பெற்ற இன்பம், இவ்வையகம் பெருக " -- கான்செப்ட்.

Unknown said...

வணக்கங்களும், வாழ்த்துக்களும்.

Radha said...

If we attack methodically, we can get it in say 30 mins or so. :-)
1) 5th position is 5.
2) 2nd, 4th, 6th and 8th positions should be even.
3) Odd numbers occupy rest of the 5 positions.
3) Number till 8th position is divisible by 8. So, the 3-digit number occupying positions 6th, 7th and 8th should be divisible by 8.

4)Given that 6th and 8th positions are even numbers and combining condition(3), the set of possible numbers for 6th,7th and 8th positions are:
{216, 416, 816, 432, 632, 832, 472, 672, 872, 296, 496, 896}
Let us call this set A.

5) Number till 3rd position is divisible 3.

6) Given that 1st position is odd, 2nd position is even and 3rd is odd, the set of possible numbers divisible by 3 are:
{
123, 129, 147, 183, 189,
321, 369, 381,
729, 741, 789,
921, 963, 981, 987
}

7) Given that the number till 4th position is divisible by 4, and that the 4th position is an even number, append even numbers to the above set of numbers such that the last two digits are divisible by 4. Avoid repetition of digits. The set gets slightly larger.
{
1236, 1296, 1472, 1476, 1832, 1836, 1892,1896,
3216, 3692, 3812, 3816,
7296, 7412, 7416, 7892, 7896,
9216, 9632, 9812, 9816, 9872, 9876
}
8) Append 5 to all the numbers in the above set. Let us call this new set as set B.
{
12365, 12965, 14725, 14765, 18325, 18365, 18925,18965,
32165, 3692, 38125, 38165,
72965, 74125, 74165, 78925, 78965,
92165, 96325, 98125, 98165, 98725, 98765
}
9) Combine set A and set B, avoiding repetitions. Don't worry. We will still have only a handful of numbers as digits can't be repeated.
10) Rule out those that don't satisfy divisibility by 6.
11) In the left over numbers, try to identify the one that is divisible by 7.
You will hit 38165472.
12) Obviously 9 gets the 9th position.
Final answer - 381654729

[No point in trying divisibility by 9 rule as sum of digits 1 to 9 is 45 which is divisible by 9. So all permutations will be divisible by 9]
~
yours friendly,
radhamohan