<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: How to solve the Josephus problem in SQL</title>
	<atom:link href="http://oraqa.com/2007/12/16/how-to-solve-the-josephus-problem-in-sql/feed/" rel="self" type="application/rss+xml" />
	<link>http://oraqa.com/2007/12/16/how-to-solve-the-josephus-problem-in-sql/</link>
	<description>Oracle Question and Answer</description>
	<lastBuildDate>Mon, 19 Dec 2011 14:21:07 -0700</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: newkid</title>
		<link>http://oraqa.com/2007/12/16/how-to-solve-the-josephus-problem-in-sql/comment-page-1/#comment-282</link>
		<dc:creator>newkid</dc:creator>
		<pubDate>Fri, 25 Jun 2010 16:29:10 +0000</pubDate>
		<guid isPermaLink="false">http://oraqa.com/2007/12/16/how-to-solve-the-josephus-problem-in-sql/#comment-282</guid>
		<description>&lt;pre&gt;
11GR2:
WITH t (cnt,people,pos,eliminated) AS (
   SELECT MAX(ROWNUM) cnt,MAX(SYS_CONNECT_BY_PATH(LPAD(ROWNUM,4),&#039;,&#039;)),6,&#039;&#039;  FROM DUAL CONNECT BY ROWNUM&lt;=:input_num
   UNION ALL
   SELECT cnt-1,SUBSTR(people,1,pos-1)&#124;&#124;SUBSTR(people,pos+5)
         ,CASE WHEN pos+5&lt;LENGTH(SUBSTR(people,1,pos-1)&#124;&#124;SUBSTR(people,pos+5)) THEN pos+5
               WHEN pos+5&lt;LENGTH(people) THEN 1
               ELSE 6
          END
         ,CAST(eliminated&#124;&#124;SUBSTR(people,pos,5) AS VARCHAR2(200))
     FROM t 
    WHERE cnt&gt;1
   )
SELECT people,eliminated FROM t WHERE cnt=1;

PEOPLE
-------------------------------------------------------
ELIMINATED
-------------------------------------------------------
,   5
,   2,   4,   6,   8,  10,   3,   7,   1,   9
&lt;/pre&gt;</description>
		<content:encoded><![CDATA[<pre>
11GR2:
WITH t (cnt,people,pos,eliminated) AS (
   SELECT MAX(ROWNUM) cnt,MAX(SYS_CONNECT_BY_PATH(LPAD(ROWNUM,4),',')),6,''  FROM DUAL CONNECT BY ROWNUM&lt;=:input_num
   UNION ALL
   SELECT cnt-1,SUBSTR(people,1,pos-1)||SUBSTR(people,pos+5)
         ,CASE WHEN pos+5&lt;LENGTH(SUBSTR(people,1,pos-1)||SUBSTR(people,pos+5)) THEN pos+5
               WHEN pos+5&lt;LENGTH(people) THEN 1
               ELSE 6
          END
         ,CAST(eliminated||SUBSTR(people,pos,5) AS VARCHAR2(200))
     FROM t
    WHERE cnt&gt;1
   )
SELECT people,eliminated FROM t WHERE cnt=1;

PEOPLE
-------------------------------------------------------
ELIMINATED
-------------------------------------------------------
,   5
,   2,   4,   6,   8,  10,   3,   7,   1,   9
</pre>
]]></content:encoded>
	</item>
</channel>
</rss>

