﻿<?xml version='1.0' encoding='UTF-8'?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/"><channel><title>SQLServerCentral / SQL Server 2008 / SQL Server 2008 - General  / Puzzle, I used SQL to see what happend next. / Latest Posts</title><generator>InstantForum.NET v2.9.0</generator><description>SQLServerCentral</description><link>http://www.sqlservercentral.com/Forums/</link><webMaster>notifications@sqlservercentral.com</webMaster><lastBuildDate>Mon, 20 May 2013 16:06:32 GMT</lastBuildDate><ttl>20</ttl><item><title>RE: Puzzle, I used SQL to see what happend next.</title><link>http://www.sqlservercentral.com/Forums/Topic1408954-391-1.aspx</link><description>[quote][b]mickyT (1/21/2013)[/b][hr]Always love a puzzle :-) so here's my solution.  I'm not sure if my grouping method will work further down the line, however it seems to work for 10 iterations.  There is probably a better way of doing this.[/code][/quote]Thanks for your contribution,Using your solution I saw that the conclusion of that the string is going to loop is not correct. (And therefore my suprise was not correct).So I have to retract that conclusion now. (Sorry).Yes it is a very elegant puzzle. (Is my opinion).Ben Brugman</description><pubDate>Thu, 24 Jan 2013 05:51:06 GMT</pubDate><dc:creator>ben.brugman</dc:creator></item><item><title>RE: Puzzle, I used SQL to see what happend next.</title><link>http://www.sqlservercentral.com/Forums/Topic1408954-391-1.aspx</link><description>Always love a puzzle :-) so here's my solution.  I'm not sure if my grouping method will work further down the line, however it seems to work for 10 iterations.  There is probably a better way of doing this.I have made use of the delimitedSplit8k function ... [url]http://www.sqlservercentral.com/articles/Tally+Table/72993/[/url][code="sql"]declare @s varchar(4000) = '1'declare @iterations int = 10declare @i int = 1print cast(@i as varchar(10)) + ': ' + @swhile @i &amp;lt;= @iterationsbegin	select @s = 		ltrim(			(				select ' ' + cast(count(*) as varchar(10)) + ' ' + item as [text()]				from (					select itemnumber, item, itemnumber - rank() over (partition by item order by itemnumber) g					from dbo.delimitedSplit8k(@s,' ')					) a				group by item, g				order by min(itemnumber)				FOR XML PATH (''), TYPE).value('text()[1]', 'varchar(8000)')			)					--select itemnumber, item, itemnumber - row_number() over (order by item) g					--from dbo.delimitedSplit8k(@s,' ')	set @i += 1	print cast(@i as varchar(10)) + ': ' + @send[/code]</description><pubDate>Mon, 21 Jan 2013 16:33:18 GMT</pubDate><dc:creator>mickyT</dc:creator></item><item><title>RE: Puzzle, I used SQL to see what happend next.</title><link>http://www.sqlservercentral.com/Forums/Topic1408954-391-1.aspx</link><description>[quote][b]ben.brugman (1/18/2013)[/b][hr]Some time ago I came across this puzzle.I do not want to spoil the satisfaction of solving this puzzle yourself.So I'll give the solution to the puzzle later on.[/quote]:-D  I never thought of using SQL to 'solve' this puzzle.  I first saw it while reading Cliff Stoll's book [url=http://en.wikipedia.org/wiki/The_Cuckoo's_Egg]The Cuckoo's Egg[/url] in the late 90's and it's been a fun one to share ever since. Sam</description><pubDate>Mon, 21 Jan 2013 08:34:19 GMT</pubDate><dc:creator>samalex</dc:creator></item><item><title>RE: Puzzle, I used SQL to see what happend next.</title><link>http://www.sqlservercentral.com/Forums/Topic1408954-391-1.aspx</link><description>Because off another thread I thougth about this puzzle.Because the puzzle is solved mainly using a lot of REPLACE functions.Analytical I had allready determined that there would never be a four in the string. But I still build in a safeguard in case I had made a mistake in the analys or otherwise.Also I build in a length restriction and a number of loops restriction.The string does not continue to grow (was supprised a little bit by that). It starts 'repeating' itself after a few loops.ADDITIONAL, my conclusion that the string does not continue to grow was not correct. So I should have investigated further, before jumping to that conclusion. 20130124 13:47 (Sorry::crying:)Maybe my next 'project' is building a Turing machine based on the replace only. (The length of the bittape will be limited and not be endless as in the Turing machine).Ben Brugmen.[code="sql"]declare @continue int = 1declare @DeString varchar(4000) = '1'declare @counter int = 0While @continue = 1beginset @DeString = REPLACE(@destring, '1111','fourone')set @DeString = REPLACE(@destring, '111','threeone')set @DeString = REPLACE(@destring, '11','twoone')set @DeString = REPLACE(@destring, '1','oneone')set @DeString = REPLACE(@destring, '2222','fourtwo')set @DeString = REPLACE(@destring, '222','threetwo')set @DeString = REPLACE(@destring, '22','twotwo')set @DeString = REPLACE(@destring, '2','onetwo')set @DeString = REPLACE(@destring, '3333','fourthree')set @DeString = REPLACE(@destring, '333','threethree')set @DeString = REPLACE(@destring, '33','twothree')set @DeString = REPLACE(@destring, '3','onethree')set @DeString = REPLACE(@destring, 'three','3')set @DeString = REPLACE(@destring, 'two','2')set @DeString = REPLACE(@destring, 'one','1')print convert(varchar(4),@counter)+'   '+convert(varchar(20),datalength(@destring)) +'   ' + convert(varchar(200),@destring) set @counter = @counter + 1if @counter &amp;gt; 100 begin set @continue = 0 endif @DeString like '%four%' begin set @continue = 0 endif datalength(@destring)&amp;gt;2000 begin set @continue = 0 endend  [/code]</description><pubDate>Mon, 21 Jan 2013 01:35:28 GMT</pubDate><dc:creator>ben.brugman</dc:creator></item><item><title>RE: Puzzle, I used SQL to see what happend next.</title><link>http://www.sqlservercentral.com/Forums/Topic1408954-391-1.aspx</link><description>Spoiler alert, Here is the solution to the puzzle.Spoiler alert, Here is the solution to the puzzle.[quote][b]ben.brugman (1/18/2013)[/b][hr][code="plain"]-- Puzzle.---- Using SQL I wanted to see what happend with the following puzzle.--------                      1--                     1 1--                     2 1--                   1 2 1 1--                 1 1 1 2 2 1--                 3 1 2 2 1 1------ Question is wat is the next line?-- And the line after that?---- How does this progress when you continue?-- For the last question I used SQL.[/code]First line contains a 1, each next line describes the the line above.So the first line contains one 1. (1 1).The second line contains two 1's (2 1)The third line contains one 2 and one 1  (1 2 1 1)etc.I used replaces to continue this trend, just to see what was happening. I'll post the script for that in a next episode, not to give away part of the 'knowledge'. I used some of the kwowledge to build the solution. I would like to see other solutions, often others can come up with a far more elegant (or more efficient or both) solutions.Although posts not always contain have a usable solution, I always learn from the anwsers, often showing solution methods and techniques which open my mind.ben brugman[/quote]</description><pubDate>Sat, 19 Jan 2013 03:59:40 GMT</pubDate><dc:creator>ben.brugman</dc:creator></item><item><title>Puzzle, I used SQL to see what happend next.</title><link>http://www.sqlservercentral.com/Forums/Topic1408954-391-1.aspx</link><description>Some time ago I came across this puzzle.I do not want to spoil the satisfaction of solving this puzzle yourself.So I'll give the solution to the puzzle later on.[code="plain"]-- Puzzle.---- Using SQL I wanted to see what happend with the following puzzle.--------                      1--                     1 1--                     2 1--                   1 2 1 1--                 1 1 1 2 2 1--                 3 1 2 2 1 1------ Question is wat is the next line?-- And the line after that?---- How does this progress when you continue?-- For the last question I used SQL.[/code]I used SQL to see what was happening further, but with primitive code,  I would like to see other solutions with SQL.For the basic solution to the puzzel, I'll post later on, with a spoiler warning in the message.Always learning from the anwsers,ben brugman</description><pubDate>Fri, 18 Jan 2013 08:48:00 GMT</pubDate><dc:creator>ben.brugman</dc:creator></item></channel></rss>