Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 Site Related Forums
 The Yak Corral
 something corey will enjoy.. and jeff and arnold..

Author  Topic 

spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2006-03-15 : 05:48:37
have fun guys!!

http://mathtest.idiotworld.com/

Go with the flow & have fun! Else fight the flow

SamC
White Water Yakist

3467 Posts

Posted - 2006-03-15 : 07:35:02
I reeeeally wish you wouldn't post stuff like this! Argh! <comic expression of angst>

Would someone post the answers to the toughies?
Go to Top of Page

spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2006-03-15 : 07:41:45
outside of the box ones?
for those i only have the last one to get...

Go with the flow & have fun! Else fight the flow
Go to Top of Page

Arnold Fribble
Yak-finder General

1961 Posts

Posted - 2006-03-15 : 08:05:23
quote:
Originally posted by SamC
Would someone post the answers to the toughies?



Why? They're all in OEIS. Not that the "outside the box" ones have anything to do with Maths.
Go to Top of Page

spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2006-03-15 : 08:10:49
what's OEIS??
<EDIT>
Arnold no fair... now you've spoiled the fun
OEIS = The On-Line Encyclopedia of Integer Sequences
</EDIT>


well they do

last one is giving me trouble.
also can't figure out 59, 154, 605, 1111,

Go with the flow & have fun! Else fight the flow
Go to Top of Page

spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2006-03-15 : 08:19:39
ran the last one in OEIS... i mean come on... who outside of US could've known that....

Go with the flow & have fun! Else fight the flow
Go to Top of Page

Arnold Fribble
Yak-finder General

1961 Posts

Posted - 2006-03-15 : 08:28:53
quote:
Originally posted by spirit1

ran the last one in OEIS... i mean come on... who outside of US could've known that....



I agree, it's just not cricket. (No, that would be something like 18, 1, 79, 112, 40, 58, 123)
Go to Top of Page

jhermiz

3564 Posts

Posted - 2006-03-15 : 09:45:19
Sometimes you totally got to think outside of the box for some of this stuff. I got up to "Math Comes In" and was royally stumped.
:(


Keeping the web experience alive -- [url]http://www.web-impulse.com[/url]

RS Blog -- [url]http://weblogs.sqlteam.com/jhermiz[/url]
Go to Top of Page

TG
Master Smack Fu Yak Hacker

6065 Posts

Posted - 2006-03-15 : 10:02:15
Mladen, you were wise not to include me in the list of people who would enjoy that. <shudder>

btw, did you math geeks celebrate pi day yesterday? (March 14)

Be One with the Optimizer
TG
Go to Top of Page

spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2006-03-15 : 10:07:25
i might have if the subject would allow more chars

yeah we ate a lot of pies



Go with the flow & have fun! Else fight the flow
Go to Top of Page

Wanderer
Master Smack Fu Yak Hacker

1168 Posts

Posted - 2006-03-15 : 10:22:03
quote:
Originally posted by spirit1

what's OEIS??
<EDIT>
Arnold no fair... now you've spoiled the fun
OEIS = The On-Line Encyclopedia of Integer Sequences
</EDIT>


well they do

last one is giving me trouble.
also can't figure out 59, 154, 605, 1111,

Go with the flow & have fun! Else fight the flow



59 (+95 reverse) =
154 (+451) =
605 (+ 506) =
1111 (+1111)
=
2222

*##* *##* *##* *##*

Chaos, Disorder and Panic ... my work is done here!
Go to Top of Page

spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2006-03-15 : 10:36:48
got it already... thanx though

Go with the flow & have fun! Else fight the flow
Go to Top of Page

Wanderer
Master Smack Fu Yak Hacker

1168 Posts

Posted - 2006-03-15 : 10:39:35
np...

*##* *##* *##* *##*

Chaos, Disorder and Panic ... my work is done here!
Go to Top of Page

Arnold Fribble
Yak-finder General

1961 Posts

Posted - 2006-03-15 : 10:47:27
quote:

59 (+95) = 154 (+451) = 605 (+ 506) = 1111


But does it ever reach a palindromic number if you start with 196?
Go to Top of Page

spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2006-03-15 : 11:14:31
i'd go with no.

Go with the flow & have fun! Else fight the flow
Go to Top of Page

Wanderer
Master Smack Fu Yak Hacker

1168 Posts

Posted - 2006-03-15 : 11:24:46
Un less I've got a logic error, not in the first 81 additions. After that, I couldn't get any larger - float conversions gave me issues. Feel free to enhance/fix and give us an answer.

(feels nice to inject some SQL here :-))


set nocount on

declare @MathTable table (uid int identity (1,1), Number dec(38,0), NumberText char(100))
declare @Count int, @BaseNumber dec(38,0), @LoopCount int

set @BaseNumber = 196
set @Count = 1
set @LoopCount = 100

insert into @MathTable (Number,NumberText)
select @BaseNumber,cast(@BaseNumber as char(100))

select * from @MathTable

while @Count < @Loopcount
begin
insert into @MathTable (Number,NumberText)
select Number+cast(reverse(NumberText) as dec(38,0)),
cast (Number+ (cast(reverse(NumberText) as dec(38,0)))
as char(100))
from @MathTable where Uid = @Count
set @Count = @Count + 1
end

select uid,
Number,
case
when NumberText = reverse(NumberText) then 'Is Palindrome'
else ' NOT Palindrome'
end as [Palindrome?]
from @MathTable order by Uid desc


Results:

uid Number NumberText
----------- ---------------------------------------- ----------------------------------------------------------------------------------------------------
1 196 196

Server: Msg 8115, Level 16, State 2, Line 17
Arithmetic overflow error converting expression to data type numeric.
The statement has been terminated.
uid Number Palindrome?
----------- ---------------------------------------- ---------------
81 71233793175007298122189281057030833206 NOT Palindrome
80 16474800379447118011108106559729985745 NOT Palindrome
79 8787394689723559555548553279865047867 NOT Palindrome
78 1797953072701241777777132207161449896 NOT Palindrome
77 899477035806065888888571598630674898 NOT Palindrome
76 171869639709643252636224690693706727 NOT Palindrome
75 91385319354816681317562845302348408 NOT Palindrome
74 45747659181913285659330927106673654 NOT Palindrome
73 13258878097456662332665448018788423 NOT Palindrome
72 7178889593228875666877224058899706 NOT Palindrome
71 3589444802113893332894111974449853 NOT Palindrome
70 1326313072829535757534829271313622 NOT Palindrome
69 668656536414767878767414635656756 NOT Palindrome
68 159876958854887988978955775977805 NOT Palindrome
67 85383533877444544434477942439447 NOT Palindrome
66 17671139534403958504034349321776 NOT Palindrome
65 8836114272647029296571625205388 NOT Palindrome
64 1712373124704184482497411473217 NOT Palindrome
63 906182107397142240703710191608 NOT Palindrome
62 182280281681549295517528109327 NOT Palindrome
61 96640091285774647759309104658 NOT Palindrome
60 17786453745152322604573635887 NOT Palindrome
59 9442681822581660752291773438 NOT Palindrome
58 1758434620324786522027424867 NOT Palindrome
57 934217310162393261013712428 NOT Palindrome
56 175837936477498486373973857 NOT Palindrome
55 92918473189299188236491928 NOT Palindrome
54 17537224026299926194218357 NOT Palindrome
53 9264161958699957602603728 NOT Palindrome
52 1751196640799987135692157 NOT Palindrome
51 925153265399993573340628 NOT Palindrome
50 175095833209091234750057 NOT Palindrome
49 92502871604050616929528 NOT Palindrome
48 18408442064004592449047 NOT Palindrome
47 9749270977546801719568 NOT Palindrome
46 1795298270686072793597 NOT Palindrome
45 947154635293536341848 NOT Palindrome
44 177104867844767940077 NOT Palindrome
43 93507933867933969538 NOT Palindrome
42 47248966933966985264 NOT Palindrome
41 13305261530450734933 NOT Palindrome
40 7197630720180367016 NOT Palindrome
39 3603815405135183953 NOT Palindrome
38 1317620482294916822 NOT Palindrome
37 664304741147513356 NOT Palindrome
36 159482241005228405 NOT Palindrome
35 85191620502609247 NOT Palindrome
34 17653692772973576 NOT Palindrome
33 8827391431036288 NOT Palindrome
32 4413700670963144 NOT Palindrome
31 1400255515443103 NOT Palindrome
30 755127757721546 NOT Palindrome
29 159547977975595 NOT Palindrome
28 84724043932847 NOT Palindrome
27 17602285712176 NOT Palindrome
26 8801197801088 NOT Palindrome
25 1800098901007 NOT Palindrome
24 900544455998 NOT Palindrome
23 450822227944 NOT Palindrome
22 130992928913 NOT Palindrome
21 70446464506 NOT Palindrome
20 16403234045 NOT Palindrome
19 8746117567 NOT Palindrome
18 1794102596 NOT Palindrome
17 897100798 NOT Palindrome
16 454050344 NOT Palindrome
15 227574622 NOT Palindrome
14 111589511 NOT Palindrome
13 60744805 NOT Palindrome
12 35322452 NOT Palindrome
11 18211171 NOT Palindrome
10 10755470 NOT Palindrome
9 1067869 NOT Palindrome
8 187088 NOT Palindrome
7 94039 NOT Palindrome
6 52514 NOT Palindrome
5 13783 NOT Palindrome
4 7436 NOT Palindrome
3 1675 NOT Palindrome
2 887 NOT Palindrome
1 196 NOT Palindrome


*##* *##* *##* *##*

Chaos, Disorder and Panic ... my work is done here!
Go to Top of Page

spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2006-03-15 : 11:39:54
well i tried with this ... still nothing


private void button5_Click(object sender, EventArgs e)
{
ulong n = 196;

for (int i=0;i<10000000;i++)
{
ulong nRev;
ulong.TryParse(Reverse(n.ToString()), out nRev);
if (nRev == n )
txtResults.Text += n.ToString() + Environment.NewLine + Environment.NewLine;
n = n + nRev;
}

txtResults.Text += "Done! " + Environment.NewLine + Environment.NewLine;

}

private string Reverse(string x)
{
char[] c = x.ToCharArray(); /*convert to chararray*/
int l = x.Length - 1;
for (int i = 0; i < l; i++, l--)
{
c[i] ^= c[l];
c[l] ^= c[i];
c[i] ^= c[l];
}
string s = new string(c);
return s;
}


Go with the flow & have fun! Else fight the flow
Go to Top of Page

jhermiz

3564 Posts

Posted - 2006-03-15 : 13:27:01
quote:
Originally posted by spirit1

well i tried with this ... still nothing


private void button5_Click(object sender, EventArgs e)
{
ulong n = 196;

for (int i=0;i<10000000;i++)
{
ulong nRev;
ulong.TryParse(Reverse(n.ToString()), out nRev);
if (nRev == n )
txtResults.Text += n.ToString() + Environment.NewLine + Environment.NewLine;
n = n + nRev;
}

txtResults.Text += "Done! " + Environment.NewLine + Environment.NewLine;

}

private string Reverse(string x)
{
char[] c = x.ToCharArray(); /*convert to chararray*/
int l = x.Length - 1;
for (int i = 0; i < l; i++, l--)
{
c[i] ^= c[l];
c[l] ^= c[i];
c[i] ^= c[l];
}
string s = new string(c);
return s;
}


Go with the flow & have fun! Else fight the flow



I think this can be shown by induction.
It doesn't seem to evaluate to a palindrome at any case, but I don't have enough room on this thread to prove it (ring a bell?)



Keeping the web experience alive -- [url]http://www.web-impulse.com[/url]

RS Blog -- [url]http://weblogs.sqlteam.com/jhermiz[/url]
Go to Top of Page

spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2006-03-15 : 13:34:08
it probably can be... but i'm no math geek

Go with the flow & have fun! Else fight the flow
Go to Top of Page

jhermiz

3564 Posts

Posted - 2006-03-15 : 13:40:40
Ok I dont seem to get the first one for outside the box, it ends up being 42 from an episode of lost but look at this:

http://www.research.att.com/~njas/sequences/?q=4%2C8%2C15%2C16%2C23&sort=0&fmt=0&language=english


Keeping the web experience alive -- [url]http://www.web-impulse.com[/url]

RS Blog -- [url]http://weblogs.sqlteam.com/jhermiz[/url]
Go to Top of Page

rockmoose
SQL Natt Alfen

3279 Posts

Posted - 2006-03-15 : 17:35:27
Still no palindrome after 2000 digit numbers....
Ok, the brute force attack was fun, I see a pattern!, oh no wait, maybe not, ah well.
declare @s1 varchar(8000), @palindrome char(10)
set @s1 = '59'
--set @s1 = '196'

select @s1 as seednumber

-- loop and display...
while len(@s1) < 8000
begin
select @s1 = dbo.addLarge(@s1, reverse(@s1))
if @s1 = reverse(@s1) or len(@s1)%100 = 0
begin
set @palindrome = case when @s1 = reverse(@s1) then 'PALINDROME' else 'LEN='+ltrim(len(@s1)) end
raiserror('%s : %s',0,1,@palindrome,@s1) with nowait
end
end


if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[addLarge]') and xtype in (N'FN', N'IF', N'TF'))
drop function [dbo].[addLarge]
GO


/* adds 2 large integer strings
terribly slow algorithm though ...
*/
create function dbo.addLarge(@s1 varchar(7999), @s2 varchar(7999))
returns varchar(8000) as
begin
declare @s3 varchar(8000)
,@i int
,@rem int
,@result int
select @rem = 0
,@s3 = ''
,@s1 = case when len(@s1)<len(@s2) then replicate('0',len(@s2)-len(@s1)) + @s1 else @s1 end
,@s2 = case when len(@s2)<len(@s1) then replicate('0',len(@s1)-len(@s2)) + @s2 else @s2 end
,@i = len(@s1)

while @i > 0
begin
select @result = @rem + cast(substring(@s1,@i,1) as int) + cast(substring(@s2,@i,1) as int)
,@s3 = ltrim(@result%10) + @s3
,@rem = @result/10
,@i = @i - 1
end

return case when @rem = 0 then '' else ltrim(@rem) end + @s3
end
go

_______________________
Query cancelled by User

rockmooose
Go to Top of Page
    Next Page

- Advertisement -