<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	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/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>peter</title>
	<atom:link href="http://blog.tmiz.net/?feed=rss2" rel="self" type="application/rss+xml" />
	<link>http://blog.tmiz.net</link>
	<description>a life with shift</description>
	<lastBuildDate>Tue, 07 Sep 2010 17:10:03 +0000</lastBuildDate>
	<language>ja</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>ちゃんと自分、何も見ないで15パズルぐらい…</title>
		<link>http://blog.tmiz.net/?p=331</link>
		<comments>http://blog.tmiz.net/?p=331#comments</comments>
		<pubDate>Tue, 07 Sep 2010 16:59:08 +0000</pubDate>
		<dc:creator>tmiz</dc:creator>
				<category><![CDATA[C++]]></category>
		<category><![CDATA[ソフト]]></category>

		<guid isPermaLink="false">http://blog.tmiz.net/?p=331</guid>
		<description><![CDATA[ちゃんと自分、何も見ないで15パズルぐらい書けるだろうか。。。。 ちょっと試してみた。 コマンドで遊ぶ15パズルを書く。いつものCみたいなC＋＋で。 //! (C) 2010 tmiz.net #include &#60;stdio.h&#62; #include &#60;time.h&#62; #include &#60;stdlib.h&#62; &#160; enum &#123; D_UP = 0, D_RIGHT, D_DOWN, D_LEFT &#125;; &#160; class Table &#123; public: explicit Table&#40;&#41;; virtual ~Table&#40;&#41;; void init&#40;&#41;; void randomize&#40;int s&#41;; void printTable&#40;&#41;; void moveNumber&#40;int i&#41;; int getState&#40;&#41;; &#160; private: bool canMove&#40;int i&#41;; void move&#40;int i&#41;; int findZero&#40;&#41;; int [...]]]></description>
			<content:encoded><![CDATA[<p>ちゃんと自分、何も見ないで15パズルぐらい書けるだろうか。。。。<br />
ちょっと試してみた。</p>
<p>コマンドで遊ぶ15パズルを書く。いつものCみたいなC＋＋で。<br />
<span id="more-331"></span></p>

<div class="wp_syntax"><div class="code"><pre class="cpp" style="font-family:monospace;"><span style="color: #666666;">//! (C) 2010 tmiz.net</span>
<span style="color: #339900;">#include &lt;stdio.h&gt;</span>
<span style="color: #339900;">#include &lt;time.h&gt;</span>
<span style="color: #339900;">#include &lt;stdlib.h&gt;</span>
&nbsp;
<span style="color: #0000ff;">enum</span> <span style="color: #008000;">&#123;</span>
    D_UP <span style="color: #000080;">=</span> <span style="color: #0000dd;">0</span>,
    D_RIGHT,
    D_DOWN,
    D_LEFT
<span style="color: #008000;">&#125;</span><span style="color: #008080;">;</span>
&nbsp;
<span style="color: #0000ff;">class</span> Table
<span style="color: #008000;">&#123;</span>
<span style="color: #0000ff;">public</span><span style="color: #008080;">:</span>
    <span style="color: #0000ff;">explicit</span> Table<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
    <span style="color: #0000ff;">virtual</span> ~Table<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
    <span style="color: #0000ff;">void</span> init<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
    <span style="color: #0000ff;">void</span> randomize<span style="color: #008000;">&#40;</span><span style="color: #0000ff;">int</span> s<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
    <span style="color: #0000ff;">void</span> printTable<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
    <span style="color: #0000ff;">void</span> moveNumber<span style="color: #008000;">&#40;</span><span style="color: #0000ff;">int</span> i<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
    <span style="color: #0000ff;">int</span> getState<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
&nbsp;
<span style="color: #0000ff;">private</span><span style="color: #008080;">:</span>
    <span style="color: #0000ff;">bool</span> canMove<span style="color: #008000;">&#40;</span><span style="color: #0000ff;">int</span> i<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
    <span style="color: #0000ff;">void</span> move<span style="color: #008000;">&#40;</span><span style="color: #0000ff;">int</span> i<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
    <span style="color: #0000ff;">int</span> findZero<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
    <span style="color: #0000ff;">int</span> mTable<span style="color: #008000;">&#91;</span><span style="color: #0000dd;">16</span><span style="color: #008000;">&#93;</span><span style="color: #008080;">;</span>
<span style="color: #008000;">&#125;</span><span style="color: #008080;">;</span>
&nbsp;
&nbsp;
Table<span style="color: #008080;">::</span><span style="color: #007788;">Table</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
    init<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
<span style="color: #008000;">&#125;</span>
&nbsp;
Table<span style="color: #008080;">::</span>~Table<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
<span style="color: #008000;">&#125;</span>
&nbsp;
<span style="color: #0000ff;">void</span> Table<span style="color: #008080;">::</span><span style="color: #007788;">init</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
    <span style="color: #0000ff;">int</span> i <span style="color: #000080;">=</span> <span style="color: #0000dd;">1</span>, j <span style="color: #000080;">=</span> <span style="color: #0000dd;">0</span><span style="color: #008080;">;</span>
    <span style="color: #0000ff;">for</span> <span style="color: #008000;">&#40;</span><span style="color: #008080;">;</span> i <span style="color: #000080;">&lt;</span> <span style="color: #0000dd;">16</span><span style="color: #008080;">;</span> i<span style="color: #000040;">++</span>, j<span style="color: #000040;">++</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
	mTable<span style="color: #008000;">&#91;</span>j<span style="color: #008000;">&#93;</span> <span style="color: #000080;">=</span> i<span style="color: #008080;">;</span>
    <span style="color: #008000;">&#125;</span>
    mTable<span style="color: #008000;">&#91;</span><span style="color: #0000dd;">15</span><span style="color: #008000;">&#93;</span> <span style="color: #000080;">=</span> <span style="color: #0000dd;">0</span><span style="color: #008080;">;</span>
<span style="color: #008000;">&#125;</span>
&nbsp;
<span style="color: #0000ff;">void</span> Table<span style="color: #008080;">::</span><span style="color: #007788;">printTable</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
    <span style="color: #0000dd;">printf</span><span style="color: #008000;">&#40;</span><span style="color: #FF0000;">&quot;-------------------<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
    <span style="color: #0000ff;">int</span> i <span style="color: #000080;">=</span> <span style="color: #0000dd;">0</span><span style="color: #008080;">;</span>
    <span style="color: #0000ff;">for</span> <span style="color: #008000;">&#40;</span>i <span style="color: #000080;">=</span> <span style="color: #0000dd;">0</span><span style="color: #008080;">;</span> i <span style="color: #000080;">&lt;</span> <span style="color: #0000dd;">16</span><span style="color: #008080;">;</span> i<span style="color: #000040;">++</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
	<span style="color: #0000ff;">if</span> <span style="color: #008000;">&#40;</span>mTable<span style="color: #008000;">&#91;</span>i<span style="color: #008000;">&#93;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
	    <span style="color: #0000dd;">printf</span><span style="color: #008000;">&#40;</span><span style="color: #FF0000;">&quot; %2d&quot;</span>, mTable<span style="color: #008000;">&#91;</span>i<span style="color: #008000;">&#93;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
	<span style="color: #008000;">&#125;</span> <span style="color: #0000ff;">else</span> <span style="color: #008000;">&#123;</span>
	    <span style="color: #0000dd;">printf</span><span style="color: #008000;">&#40;</span><span style="color: #FF0000;">&quot;   &quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
	<span style="color: #008000;">&#125;</span>
	<span style="color: #0000ff;">if</span> <span style="color: #008000;">&#40;</span><span style="color: #008000;">&#40;</span>i <span style="color: #000040;">%</span> <span style="color: #0000dd;">4</span><span style="color: #008000;">&#41;</span><span style="color: #000080;">==</span><span style="color: #0000dd;">3</span><span style="color: #008000;">&#41;</span> <span style="color: #0000dd;">printf</span><span style="color: #008000;">&#40;</span><span style="color: #FF0000;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span> 
    <span style="color: #008000;">&#125;</span>
<span style="color: #008000;">&#125;</span>
&nbsp;
<span style="color: #0000ff;">int</span> Table<span style="color: #008080;">::</span><span style="color: #007788;">findZero</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
    <span style="color: #0000ff;">int</span> i <span style="color: #000080;">=</span> <span style="color: #0000dd;">0</span><span style="color: #008080;">;</span>
    <span style="color: #0000ff;">for</span> <span style="color: #008000;">&#40;</span><span style="color: #008080;">;</span>i <span style="color: #000080;">&lt;</span> <span style="color: #0000dd;">16</span><span style="color: #008080;">;</span> i<span style="color: #000040;">++</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
	<span style="color: #0000ff;">if</span> <span style="color: #008000;">&#40;</span>mTable<span style="color: #008000;">&#91;</span>i<span style="color: #008000;">&#93;</span> <span style="color: #000080;">==</span> <span style="color: #0000dd;">0</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
	    <span style="color: #0000ff;">return</span> i<span style="color: #008080;">;</span>
	<span style="color: #008000;">&#125;</span>
    <span style="color: #008000;">&#125;</span>
<span style="color: #008000;">&#125;</span>
&nbsp;
<span style="color: #0000ff;">bool</span> Table<span style="color: #008080;">::</span><span style="color: #007788;">canMove</span><span style="color: #008000;">&#40;</span><span style="color: #0000ff;">int</span> m<span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
    <span style="color: #0000ff;">int</span> pos <span style="color: #000080;">=</span> findZero<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
    <span style="color: #0000ff;">int</span> x <span style="color: #000080;">=</span> pos <span style="color: #000040;">%</span> <span style="color: #0000dd;">4</span><span style="color: #008080;">;</span>
    <span style="color: #0000ff;">int</span> y <span style="color: #000080;">=</span> pos <span style="color: #000040;">/</span> <span style="color: #0000dd;">4</span><span style="color: #008080;">;</span>
&nbsp;
    <span style="color: #0000ff;">switch</span> <span style="color: #008000;">&#40;</span>m<span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
    <span style="color: #0000ff;">case</span> D_UP<span style="color: #008080;">:</span> <span style="color: #008000;">&#123;</span>
	<span style="color: #0000ff;">if</span> <span style="color: #008000;">&#40;</span>y <span style="color: #000080;">==</span> <span style="color: #0000dd;">0</span><span style="color: #008000;">&#41;</span> <span style="color: #0000ff;">return</span> <span style="color: #0000ff;">false</span><span style="color: #008080;">;</span>
	<span style="color: #0000ff;">break</span><span style="color: #008080;">;</span>
    <span style="color: #008000;">&#125;</span>
    <span style="color: #0000ff;">case</span> D_DOWN<span style="color: #008080;">:</span> <span style="color: #008000;">&#123;</span>
	<span style="color: #0000ff;">if</span> <span style="color: #008000;">&#40;</span>y <span style="color: #000080;">==</span> <span style="color: #0000dd;">3</span><span style="color: #008000;">&#41;</span> <span style="color: #0000ff;">return</span> <span style="color: #0000ff;">false</span><span style="color: #008080;">;</span>
	<span style="color: #0000ff;">break</span><span style="color: #008080;">;</span>
    <span style="color: #008000;">&#125;</span>
    <span style="color: #0000ff;">case</span> D_LEFT<span style="color: #008080;">:</span> <span style="color: #008000;">&#123;</span>
	<span style="color: #0000ff;">if</span> <span style="color: #008000;">&#40;</span>x <span style="color: #000080;">==</span> <span style="color: #0000dd;">0</span><span style="color: #008000;">&#41;</span> <span style="color: #0000ff;">return</span> <span style="color: #0000ff;">false</span><span style="color: #008080;">;</span>
	<span style="color: #0000ff;">break</span><span style="color: #008080;">;</span>
    <span style="color: #008000;">&#125;</span>
    <span style="color: #0000ff;">case</span> D_RIGHT<span style="color: #008080;">:</span> <span style="color: #008000;">&#123;</span>
	<span style="color: #0000ff;">if</span> <span style="color: #008000;">&#40;</span>x <span style="color: #000080;">==</span> <span style="color: #0000dd;">3</span><span style="color: #008000;">&#41;</span> <span style="color: #0000ff;">return</span> <span style="color: #0000ff;">false</span><span style="color: #008080;">;</span>
	<span style="color: #0000ff;">break</span><span style="color: #008080;">;</span>
    <span style="color: #008000;">&#125;</span>
    <span style="color: #0000ff;">default</span><span style="color: #008080;">:</span>
	<span style="color: #0000ff;">break</span><span style="color: #008080;">;</span>
    <span style="color: #008000;">&#125;</span>
    <span style="color: #0000ff;">return</span> <span style="color: #0000ff;">true</span><span style="color: #008080;">;</span>
<span style="color: #008000;">&#125;</span>
&nbsp;
<span style="color: #0000ff;">void</span> swap<span style="color: #008000;">&#40;</span><span style="color: #0000ff;">int</span> <span style="color: #000040;">*</span>a, <span style="color: #0000ff;">int</span> <span style="color: #000040;">*</span>b<span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
    <span style="color: #0000ff;">int</span> temp<span style="color: #008080;">;</span>
    temp <span style="color: #000080;">=</span> <span style="color: #000040;">*</span>a<span style="color: #008080;">;</span>
    <span style="color: #000040;">*</span>a <span style="color: #000080;">=</span> <span style="color: #000040;">*</span>b<span style="color: #008080;">;</span>
    <span style="color: #000040;">*</span>b <span style="color: #000080;">=</span> temp<span style="color: #008080;">;</span>
<span style="color: #008000;">&#125;</span>
&nbsp;
<span style="color: #0000ff;">void</span> Table<span style="color: #008080;">::</span><span style="color: #007788;">move</span><span style="color: #008000;">&#40;</span><span style="color: #0000ff;">int</span> m<span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
    <span style="color: #0000ff;">int</span> pos <span style="color: #000080;">=</span> findZero<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
    <span style="color: #0000ff;">switch</span> <span style="color: #008000;">&#40;</span>m<span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
    <span style="color: #0000ff;">case</span> D_UP<span style="color: #008080;">:</span> <span style="color: #008000;">&#123;</span>
	swap<span style="color: #008000;">&#40;</span><span style="color: #000040;">&amp;</span>mTable<span style="color: #008000;">&#91;</span>pos <span style="color: #000040;">-</span> <span style="color: #0000dd;">4</span><span style="color: #008000;">&#93;</span>, <span style="color: #000040;">&amp;</span>mTable<span style="color: #008000;">&#91;</span>pos<span style="color: #008000;">&#93;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
	<span style="color: #0000ff;">break</span><span style="color: #008080;">;</span>
    <span style="color: #008000;">&#125;</span>
    <span style="color: #0000ff;">case</span> D_DOWN<span style="color: #008080;">:</span> <span style="color: #008000;">&#123;</span>
	swap<span style="color: #008000;">&#40;</span><span style="color: #000040;">&amp;</span>mTable<span style="color: #008000;">&#91;</span>pos <span style="color: #000040;">+</span> <span style="color: #0000dd;">4</span><span style="color: #008000;">&#93;</span>, <span style="color: #000040;">&amp;</span>mTable<span style="color: #008000;">&#91;</span>pos<span style="color: #008000;">&#93;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
	<span style="color: #0000ff;">break</span><span style="color: #008080;">;</span>
    <span style="color: #008000;">&#125;</span>
    <span style="color: #0000ff;">case</span> D_LEFT<span style="color: #008080;">:</span> <span style="color: #008000;">&#123;</span>
	swap<span style="color: #008000;">&#40;</span><span style="color: #000040;">&amp;</span>mTable<span style="color: #008000;">&#91;</span>pos <span style="color: #000040;">-</span> <span style="color: #0000dd;">1</span><span style="color: #008000;">&#93;</span>, <span style="color: #000040;">&amp;</span>mTable<span style="color: #008000;">&#91;</span>pos<span style="color: #008000;">&#93;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
	<span style="color: #0000ff;">break</span><span style="color: #008080;">;</span>
    <span style="color: #008000;">&#125;</span>
    <span style="color: #0000ff;">case</span> D_RIGHT<span style="color: #008080;">:</span> <span style="color: #008000;">&#123;</span>
	swap<span style="color: #008000;">&#40;</span><span style="color: #000040;">&amp;</span>mTable<span style="color: #008000;">&#91;</span>pos <span style="color: #000040;">+</span> <span style="color: #0000dd;">1</span><span style="color: #008000;">&#93;</span>, <span style="color: #000040;">&amp;</span>mTable<span style="color: #008000;">&#91;</span>pos<span style="color: #008000;">&#93;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
	<span style="color: #0000ff;">break</span><span style="color: #008080;">;</span>
    <span style="color: #008000;">&#125;</span>
    <span style="color: #0000ff;">default</span><span style="color: #008080;">:</span>
	<span style="color: #0000ff;">break</span><span style="color: #008080;">;</span>
    <span style="color: #008000;">&#125;</span>
<span style="color: #008000;">&#125;</span>
&nbsp;
<span style="color: #0000ff;">void</span> Table<span style="color: #008080;">::</span><span style="color: #007788;">moveNumber</span><span style="color: #008000;">&#40;</span><span style="color: #0000ff;">int</span> m<span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
    <span style="color: #0000ff;">int</span> pos <span style="color: #000080;">=</span> findZero<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>    
    <span style="color: #0000ff;">if</span> <span style="color: #008000;">&#40;</span><span style="color: #008000;">&#40;</span>pos<span style="color: #000080;">&gt;=</span><span style="color: #0000dd;">4</span><span style="color: #008000;">&#41;</span> <span style="color: #000040;">&amp;&amp;</span> <span style="color: #008000;">&#40;</span>mTable<span style="color: #008000;">&#91;</span>pos<span style="color: #000040;">-</span><span style="color: #0000dd;">4</span><span style="color: #008000;">&#93;</span> <span style="color: #000080;">==</span> m<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
	<span style="color: #0000ff;">if</span> <span style="color: #008000;">&#40;</span>canMove<span style="color: #008000;">&#40;</span>D_UP<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
	    move<span style="color: #008000;">&#40;</span>D_UP<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
	<span style="color: #008000;">&#125;</span>
	<span style="color: #0000ff;">return</span><span style="color: #008080;">;</span>
    <span style="color: #008000;">&#125;</span>   
    <span style="color: #0000ff;">if</span> <span style="color: #008000;">&#40;</span><span style="color: #008000;">&#40;</span>pos<span style="color: #000080;">&lt;</span><span style="color: #0000dd;">12</span><span style="color: #008000;">&#41;</span> <span style="color: #000040;">&amp;&amp;</span> <span style="color: #008000;">&#40;</span>mTable<span style="color: #008000;">&#91;</span>pos<span style="color: #000040;">+</span><span style="color: #0000dd;">4</span><span style="color: #008000;">&#93;</span> <span style="color: #000080;">==</span> m<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
	<span style="color: #0000ff;">if</span> <span style="color: #008000;">&#40;</span>canMove<span style="color: #008000;">&#40;</span>D_DOWN<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
	    move<span style="color: #008000;">&#40;</span>D_DOWN<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
	<span style="color: #008000;">&#125;</span>
	<span style="color: #0000ff;">return</span><span style="color: #008080;">;</span>
    <span style="color: #008000;">&#125;</span>   
    <span style="color: #0000ff;">if</span> <span style="color: #008000;">&#40;</span><span style="color: #008000;">&#40;</span>pos<span style="color: #000080;">&gt;=</span><span style="color: #0000dd;">1</span><span style="color: #008000;">&#41;</span> <span style="color: #000040;">&amp;&amp;</span> <span style="color: #008000;">&#40;</span>mTable<span style="color: #008000;">&#91;</span>pos<span style="color: #000040;">-</span><span style="color: #0000dd;">1</span><span style="color: #008000;">&#93;</span> <span style="color: #000080;">==</span> m<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
	<span style="color: #0000ff;">if</span> <span style="color: #008000;">&#40;</span>canMove<span style="color: #008000;">&#40;</span>D_LEFT<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
	    move<span style="color: #008000;">&#40;</span>D_LEFT<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
	<span style="color: #008000;">&#125;</span>
	<span style="color: #0000ff;">return</span><span style="color: #008080;">;</span>
    <span style="color: #008000;">&#125;</span>
    <span style="color: #0000ff;">if</span> <span style="color: #008000;">&#40;</span><span style="color: #008000;">&#40;</span>pos<span style="color: #000080;">&lt;</span><span style="color: #0000dd;">15</span><span style="color: #008000;">&#41;</span> <span style="color: #000040;">&amp;&amp;</span> <span style="color: #008000;">&#40;</span>mTable<span style="color: #008000;">&#91;</span>pos<span style="color: #000040;">+</span><span style="color: #0000dd;">1</span><span style="color: #008000;">&#93;</span> <span style="color: #000080;">==</span> m<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
	<span style="color: #0000ff;">if</span> <span style="color: #008000;">&#40;</span>canMove<span style="color: #008000;">&#40;</span>D_RIGHT<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
	    move<span style="color: #008000;">&#40;</span>D_RIGHT<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
	<span style="color: #008000;">&#125;</span>
	<span style="color: #0000ff;">return</span><span style="color: #008080;">;</span>
    <span style="color: #008000;">&#125;</span>
<span style="color: #008000;">&#125;</span>
&nbsp;
<span style="color: #0000ff;">int</span> Table<span style="color: #008080;">::</span><span style="color: #007788;">getState</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
    <span style="color: #0000ff;">int</span> i <span style="color: #000080;">=</span> <span style="color: #0000dd;">0</span>, j <span style="color: #000080;">=</span> <span style="color: #0000dd;">1</span><span style="color: #008080;">;</span>
    <span style="color: #0000ff;">for</span> <span style="color: #008000;">&#40;</span><span style="color: #008080;">;</span> i<span style="color: #000080;">&lt;</span><span style="color: #0000dd;">15</span><span style="color: #008080;">;</span> i<span style="color: #000040;">++</span>,j<span style="color: #000040;">++</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
	<span style="color: #0000ff;">if</span> <span style="color: #008000;">&#40;</span>mTable<span style="color: #008000;">&#91;</span>i<span style="color: #008000;">&#93;</span> <span style="color: #000040;">!</span><span style="color: #000080;">=</span> j<span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
	    <span style="color: #0000ff;">break</span><span style="color: #008080;">;</span>
	<span style="color: #008000;">&#125;</span>
    <span style="color: #008000;">&#125;</span>
    <span style="color: #0000ff;">if</span> <span style="color: #008000;">&#40;</span>i <span style="color: #000080;">==</span> <span style="color: #0000dd;">15</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
	<span style="color: #666666;">//clear</span>
	<span style="color: #0000ff;">return</span> <span style="color: #0000dd;">1</span><span style="color: #008080;">;</span>
    <span style="color: #008000;">&#125;</span>
    <span style="color: #666666;">//continue</span>
    <span style="color: #0000ff;">return</span> <span style="color: #0000dd;">0</span><span style="color: #008080;">;</span>
<span style="color: #008000;">&#125;</span>
&nbsp;
&nbsp;
<span style="color: #0000ff;">void</span> Table<span style="color: #008080;">::</span><span style="color: #007788;">randomize</span><span style="color: #008000;">&#40;</span><span style="color: #0000ff;">int</span> step<span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
    <span style="color: #666666;">//init table</span>
    <span style="color: #0000dd;">srand</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#40;</span><span style="color: #0000ff;">unsigned</span> <span style="color: #0000ff;">int</span><span style="color: #008000;">&#41;</span><span style="color: #0000dd;">time</span><span style="color: #008000;">&#40;</span><span style="color: #0000ff;">NULL</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
    <span style="color: #0000ff;">int</span> i <span style="color: #000080;">=</span> <span style="color: #0000dd;">0</span><span style="color: #008080;">;</span>
    <span style="color: #0000ff;">for</span> <span style="color: #008000;">&#40;</span><span style="color: #008080;">;</span> i <span style="color: #000080;">&lt;</span> step<span style="color: #008080;">;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
	<span style="color: #0000ff;">int</span> m <span style="color: #000080;">=</span> <span style="color: #0000dd;">rand</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #000040;">%</span> <span style="color: #0000dd;">4</span><span style="color: #008080;">;</span>
	<span style="color: #0000ff;">if</span> <span style="color: #008000;">&#40;</span>canMove<span style="color: #008000;">&#40;</span>m<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
	    move<span style="color: #008000;">&#40;</span>m<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
	    i<span style="color: #000040;">++</span><span style="color: #008080;">;</span>
	    <span style="color: #0000ff;">continue</span><span style="color: #008080;">;</span>
	<span style="color: #008000;">&#125;</span>
    <span style="color: #008000;">&#125;</span>
<span style="color: #008000;">&#125;</span>
&nbsp;
<span style="color: #0000ff;">int</span> main<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
    Table t<span style="color: #008080;">;</span>
    t.<span style="color: #007788;">randomize</span><span style="color: #008000;">&#40;</span><span style="color: #0000dd;">13</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
    t.<span style="color: #007788;">printTable</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
&nbsp;
    <span style="color: #0000ff;">int</span> i <span style="color: #000080;">=</span> <span style="color: #0000dd;">100</span><span style="color: #008080;">;</span>
    <span style="color: #0000ff;">while</span> <span style="color: #008000;">&#40;</span>i<span style="color: #000040;">--</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
        <span style="color: #0000ff;">char</span> buf<span style="color: #008000;">&#91;</span><span style="color: #0000dd;">100</span><span style="color: #008000;">&#93;</span><span style="color: #008080;">;</span>
	<span style="color: #0000dd;">printf</span><span style="color: #008000;">&#40;</span><span style="color: #FF0000;">&quot;Time:%d  Next Number =&gt; &quot;</span>, i<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
	<span style="color: #0000dd;">scanf</span><span style="color: #008000;">&#40;</span><span style="color: #FF0000;">&quot;%s&quot;</span>, buf<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
	<span style="color: #0000ff;">int</span> iNum <span style="color: #000080;">=</span> <span style="color: #0000dd;">atoi</span><span style="color: #008000;">&#40;</span>buf<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
	t.<span style="color: #007788;">moveNumber</span><span style="color: #008000;">&#40;</span>iNum<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
	t.<span style="color: #007788;">printTable</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
	<span style="color: #0000ff;">if</span> <span style="color: #008000;">&#40;</span>t.<span style="color: #007788;">getState</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #000080;">==</span> <span style="color: #0000dd;">1</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
	    <span style="color: #0000dd;">printf</span><span style="color: #008000;">&#40;</span><span style="color: #FF0000;">&quot;Congratulations. You win the game.<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
	    <span style="color: #0000ff;">return</span> <span style="color: #0000dd;">0</span><span style="color: #008080;">;</span>
	<span style="color: #008000;">&#125;</span>
    <span style="color: #008000;">&#125;</span>
    <span style="color: #0000dd;">printf</span><span style="color: #008000;">&#40;</span><span style="color: #FF0000;">&quot;Time Over<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
    <span style="color: #0000ff;">return</span> <span style="color: #0000dd;">0</span><span style="color: #008080;">;</span>
<span style="color: #008000;">&#125;</span></pre></div></div>

<p>mainの2行目のt.randmize(n)のnの数を増やして難しくできる（100ぐらいが普通だと思う）。<br />
iPhoneから、SSHクライアントで接続して、サーバ上で遊んでみたりできた。</p>
<p>ちゃんとガワを作ってiPhoneアプリにでもしようかなぁ。以下、実行例</p>

<div class="wp_syntax"><div class="code"><pre class="cpp" style="font-family:monospace;">$ .<span style="color: #000040;">/</span>a.<span style="color: #007788;">out</span> 
<span style="color: #000040;">-------------------</span>
  <span style="color: #0000dd;">1</span>  <span style="color: #0000dd;">2</span>  <span style="color: #0000dd;">3</span>  <span style="color: #0000dd;">4</span>
  <span style="color: #0000dd;">5</span>  <span style="color: #0000dd;">6</span>  <span style="color: #0000dd;">7</span>  <span style="color: #0000dd;">8</span>
  <span style="color: #0000dd;">9</span> <span style="color: #0000dd;">10</span> <span style="color: #0000dd;">15</span>   
 <span style="color: #0000dd;">13</span> <span style="color: #0000dd;">14</span> <span style="color: #0000dd;">12</span> <span style="color: #0000dd;">11</span>
Time<span style="color: #008080;">:</span><span style="color: #0000dd;">99</span>  Next Number <span style="color: #000080;">=&gt;</span> <span style="color: #0000dd;">11</span>
<span style="color: #000040;">-------------------</span>
  <span style="color: #0000dd;">1</span>  <span style="color: #0000dd;">2</span>  <span style="color: #0000dd;">3</span>  <span style="color: #0000dd;">4</span>
  <span style="color: #0000dd;">5</span>  <span style="color: #0000dd;">6</span>  <span style="color: #0000dd;">7</span>  <span style="color: #0000dd;">8</span>
  <span style="color: #0000dd;">9</span> <span style="color: #0000dd;">10</span> <span style="color: #0000dd;">15</span> <span style="color: #0000dd;">11</span>
 <span style="color: #0000dd;">13</span> <span style="color: #0000dd;">14</span> <span style="color: #0000dd;">12</span>   
Time<span style="color: #008080;">:</span><span style="color: #0000dd;">98</span>  Next Number <span style="color: #000080;">=&gt;</span> <span style="color: #0000dd;">12</span>
<span style="color: #000040;">-------------------</span>
  <span style="color: #0000dd;">1</span>  <span style="color: #0000dd;">2</span>  <span style="color: #0000dd;">3</span>  <span style="color: #0000dd;">4</span>
  <span style="color: #0000dd;">5</span>  <span style="color: #0000dd;">6</span>  <span style="color: #0000dd;">7</span>  <span style="color: #0000dd;">8</span>
  <span style="color: #0000dd;">9</span> <span style="color: #0000dd;">10</span> <span style="color: #0000dd;">15</span> <span style="color: #0000dd;">11</span>
 <span style="color: #0000dd;">13</span> <span style="color: #0000dd;">14</span>    <span style="color: #0000dd;">12</span>
Time<span style="color: #008080;">:</span><span style="color: #0000dd;">97</span>  Next Number <span style="color: #000080;">=&gt;</span> <span style="color: #0000dd;">15</span>
<span style="color: #000040;">-------------------</span>
  <span style="color: #0000dd;">1</span>  <span style="color: #0000dd;">2</span>  <span style="color: #0000dd;">3</span>  <span style="color: #0000dd;">4</span>
  <span style="color: #0000dd;">5</span>  <span style="color: #0000dd;">6</span>  <span style="color: #0000dd;">7</span>  <span style="color: #0000dd;">8</span>
  <span style="color: #0000dd;">9</span> <span style="color: #0000dd;">10</span>    <span style="color: #0000dd;">11</span>
 <span style="color: #0000dd;">13</span> <span style="color: #0000dd;">14</span> <span style="color: #0000dd;">15</span> <span style="color: #0000dd;">12</span>
Time<span style="color: #008080;">:</span><span style="color: #0000dd;">96</span>  Next Number <span style="color: #000080;">=&gt;</span> <span style="color: #0000dd;">11</span>
<span style="color: #000040;">-------------------</span>
  <span style="color: #0000dd;">1</span>  <span style="color: #0000dd;">2</span>  <span style="color: #0000dd;">3</span>  <span style="color: #0000dd;">4</span>
  <span style="color: #0000dd;">5</span>  <span style="color: #0000dd;">6</span>  <span style="color: #0000dd;">7</span>  <span style="color: #0000dd;">8</span>
  <span style="color: #0000dd;">9</span> <span style="color: #0000dd;">10</span> <span style="color: #0000dd;">11</span>   
 <span style="color: #0000dd;">13</span> <span style="color: #0000dd;">14</span> <span style="color: #0000dd;">15</span> <span style="color: #0000dd;">12</span>
Time<span style="color: #008080;">:</span><span style="color: #0000dd;">95</span>  Next Number <span style="color: #000080;">=&gt;</span> <span style="color: #0000dd;">12</span>
<span style="color: #000040;">-------------------</span>
  <span style="color: #0000dd;">1</span>  <span style="color: #0000dd;">2</span>  <span style="color: #0000dd;">3</span>  <span style="color: #0000dd;">4</span>
  <span style="color: #0000dd;">5</span>  <span style="color: #0000dd;">6</span>  <span style="color: #0000dd;">7</span>  <span style="color: #0000dd;">8</span>
  <span style="color: #0000dd;">9</span> <span style="color: #0000dd;">10</span> <span style="color: #0000dd;">11</span> <span style="color: #0000dd;">12</span>
 <span style="color: #0000dd;">13</span> <span style="color: #0000dd;">14</span> <span style="color: #0000dd;">15</span>   
Congratulations. <span style="color: #007788;">You</span> win the game.</pre></div></div>


<div style="font-size:0px;height:0px;line-height:0px;margin:0;padding:0;clear:both"></div>]]></content:encoded>
			<wfw:commentRss>http://blog.tmiz.net/?feed=rss2&amp;p=331</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>16ビット整数入れたらフラグ文字列が出てくるようなワンライナー -Python備忘-</title>
		<link>http://blog.tmiz.net/?p=324</link>
		<comments>http://blog.tmiz.net/?p=324#comments</comments>
		<pubDate>Tue, 07 Sep 2010 14:05:03 +0000</pubDate>
		<dc:creator>tmiz</dc:creator>
				<category><![CDATA[python]]></category>
		<category><![CDATA[ソフト]]></category>

		<guid isPermaLink="false">http://blog.tmiz.net/?p=324</guid>
		<description><![CDATA[自分のための備忘です。
16ビット整数入れたら、フラグ文字列が出てくるようなワンライナーを書いてみました。


>>> func = (lambda a:''.join(["%d" % d for d in [(lamb [...]]]></description>
			<content:encoded><![CDATA[<p>自分のための備忘です。<br />
16ビット整数入れたら、フラグ文字列が出てくるようなワンライナーを書いてみました。</p>
<p><span id="more-324"></span></p>
<pre class="brush:python">
>>> func = (lambda a:''.join(["%d" % d for d in [(lambda a,i:(a &#038; (1 << i)) and 1 or 0)(a,i) for i in range(7,-1,-1)]]))
>>> func(0x0f)
'00001111'
>>> func(0x01)
'00000001'
</pre>
<p>Pythonを計算機代わりにしていて、かつ、とっさにビットが出てこないダメな僕にはオススメです。</p>

<div style="font-size:0px;height:0px;line-height:0px;margin:0;padding:0;clear:both"></div>]]></content:encoded>
			<wfw:commentRss>http://blog.tmiz.net/?feed=rss2&amp;p=324</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Google Developer Day 2010にいけるらしい</title>
		<link>http://blog.tmiz.net/?p=317</link>
		<comments>http://blog.tmiz.net/?p=317#comments</comments>
		<pubDate>Fri, 03 Sep 2010 17:50:19 +0000</pubDate>
		<dc:creator>tmiz</dc:creator>
				<category><![CDATA[未分類]]></category>

		<guid isPermaLink="false">http://blog.tmiz.net/?p=317</guid>
		<description><![CDATA[Google Developer DayのDevQuizに合格してました。
いけるみたいです。

DevQuizというやつは、成績的には、以下のような感じでした。

まぁ、現役の技術者ですから、これぐらいが普通なんじゃな [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.google.co.jp/events/developerday/2010/tokyo/" target="_blank">Google Developer Day</a>のDevQuizに合格してました。<br />
いけるみたいです。<br />
<span id="more-317"></span></p>
<p>DevQuizというやつは、成績的には、以下のような感じでした。<br />
<img src="http://gyazo.com/967a4637531f5d0702aef181328c6b14.png"></p>
<p>まぁ、現役の技術者ですから、これぐらいが普通なんじゃないかと思っています。まぁ、AndroidケータイもGAEもやってませんけどねw。</p>

<div style="font-size:0px;height:0px;line-height:0px;margin:0;padding:0;clear:both"></div>]]></content:encoded>
			<wfw:commentRss>http://blog.tmiz.net/?feed=rss2&amp;p=317</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>oauthでSigned Request -python備忘-</title>
		<link>http://blog.tmiz.net/?p=283</link>
		<comments>http://blog.tmiz.net/?p=283#comments</comments>
		<pubDate>Fri, 27 Aug 2010 15:29:14 +0000</pubDate>
		<dc:creator>tmiz</dc:creator>
				<category><![CDATA[python]]></category>
		<category><![CDATA[ソフト]]></category>
		<category><![CDATA[見かけたもの]]></category>

		<guid isPermaLink="false">http://blog.tmiz.net/?p=283</guid>
		<description><![CDATA[またもや自分向け備忘です。
Google Developer&#8217;s Dayで、OAuthのTwo Legged Request（署名付きリクエスト）でリクエストを送れという問題が出てました。


http:// [...]]]></description>
			<content:encoded><![CDATA[<p>またもや自分向け備忘です。</p>
<p>Google Developer&#8217;s Dayで、OAuthのTwo Legged Request（署名付きリクエスト）でリクエストを送れという問題が出てました。</p>
<p><span id="more-283"></span></p>
<blockquote><p>
http://gdd-2010-quiz-japan.appspot.com/oauth/XXXXXXXXXX にリクエストを送信してください。<br />
HTTP の POST メソッドを用いて、 hello=world (キーが hello で値が world となるPOSTデータ) というパラメータを送信してください。<br />
OAuth のパラメータは、 Authorization ヘッダに含める形式 で送信してください。 その際、認証の realm には devquiz という文字列を使用してください。<br />
POST データや GET パラメータに OAuth のパラメータを含める形式には対応していません。<br />
OAuth 署名を作成する際に、下記の consumer key と consumer secret を使用してください。<br />
Consumer key: XXXXXXXXXXXXXXXXX<br />
Consumer secret: XXXXXXXXXXXXXXXXX<br />
OAuth 署名方式は HMAC-SHA1 を使用してください。 その他の署名方式には対応していません。
</p></blockquote>
<p>こういうのはマニュアルをヒキヒキやれば、できるもので、ザクッとできました。</p>
<pre class="brush:python">
import urllib,urllib2
from oauth import oauth
# Request URL
url = "http://gdd-2010-quiz-japan.appspot.com/oauth/XXXXXXXXXX"
# CONSUMER
consumer_key = 'XXXXXXXXXXXXXXXXX'
secret_key   = 'XXXXXXXXXXXXXXXXX'
# Post Param
params = {'hello' : 'world'};
# REQUEST DATA
consumer = oauth.OAuthConsumer(consumer_key, secret_key)
request = oauth.OAuthRequest.from_consumer_and_token(consumer,http_method='POST',http_url=url,parameters=params,)
request.sign_request(oauth.OAuthSignatureMethod_HMAC_SHA1(), consumer, None)
r = urllib2.Request(url, headers=request.to_header(realm="devquiz"))
data = urllib.urlencode(params)
try:
    print urllib2.urlopen(r, data).read()
except urllib2.HTTPError, e:
    print e
</pre>
<p>OAuthに慣れてくれというGoogleのDeveloperに対する願望が表れた問題でした。</p>
<p><iframe src="http://rcm-jp.amazon.co.jp/e/cm?lt1=_blank&#038;bc1=000000&#038;IS2=1&#038;bg1=FFFFFF&#038;fc1=000000&#038;lc1=0000FF&#038;t=bakingpowder-22&#038;o=9&#038;p=8&#038;l=as1&#038;m=amazon&#038;f=ifr&#038;md=1X69VDGQCMF7Z30FM082&#038;asins=4797353953" style="width:120px;height:240px;" scrolling="no" marginwidth="0" marginheight="0" frameborder="0"></iframe></p>

<div style="font-size:0px;height:0px;line-height:0px;margin:0;padding:0;clear:both"></div>]]></content:encoded>
			<wfw:commentRss>http://blog.tmiz.net/?feed=rss2&amp;p=283</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>全順列を納めたリスト -python備忘-</title>
		<link>http://blog.tmiz.net/?p=264</link>
		<comments>http://blog.tmiz.net/?p=264#comments</comments>
		<pubDate>Thu, 26 Aug 2010 15:30:36 +0000</pubDate>
		<dc:creator>tmiz</dc:creator>
				<category><![CDATA[python]]></category>
		<category><![CDATA[ソフト]]></category>
		<category><![CDATA[見かけたもの]]></category>

		<guid isPermaLink="false">http://blog.tmiz.net/?p=264</guid>
		<description><![CDATA[自分のための備忘です。
Google Developer Day 2010のDevQuizで、Google Map APIの巡回セールスマン問題が出ました。日本の地点の緯度経度と名称が複数示されて、ある地点から行って帰っ [...]]]></description>
			<content:encoded><![CDATA[<p>自分のための備忘です。</p>
<p>Google Developer Day 2010のDevQuizで、Google Map APIの<a href="http://ja.wikipedia.org/wiki/巡回セールスマン問題">巡回セールスマン問題</a>が出ました。日本の地点の緯度経度と名称が複数示されて、ある地点から行って帰ってくるには、どのルートが一番近いのかを、Google Map APIを使って解けという問題でした。</p>
<p>巡回セールスマン問題は、真っ当にやるとNP困難なので、いちばん簡単な方法は、「全ルートを挙げて、その長さを列挙し、一番短いのを見つける」という方法です。効率は悪いです。でも、そんな力技でやろうとして、Pythonで全順列（all permutations）リストが必要になり、その生成関数を書きました。</p>
<p><span id="more-264"></span></p>
<pre class="brush:python">
def all_permutations(list, length = 0):
	def _impl(length, list, ret = [], last = []):
		if len(last) == length:
			ret.append(last[::])
		else:
			for item in list:
				last.append(item)
				tmpList = list[::]
				tmpList.remove(item)
				_impl(length, tmpList, ret, last)
				last.remove(item)
	ret = []
	if length is 0 or length > len(list):
		length = len(list)
	_impl(length, list, ret)
	return ret
</pre>
<p>もっと短く書ける気はするんですが、とりあえず困らない程度に書きました。<br />
使い方は以下のような感じ。</p>
<pre class="brush:python">
>>> all_permutations([1,2,3])
[[1, 2, 3], [1, 3, 2], [2, 1, 3], [2, 3, 1], [3, 1, 2], [3, 2, 1]]
>>> all_permutations(['a','b','c'],2)
[['a', 'b'], ['a', 'c'], ['b', 'a'], ['b', 'c'], ['c', 'a'], ['c', 'b']]
</pre>
<p>ザクッと全探索で、一回しか実行しませんーーみたいなときに使えそうです。自分には、すごい役立ちました。</p>
<p><iframe src="http://rcm-jp.amazon.co.jp/e/cm?lt1=_blank&#038;bc1=000000&#038;IS2=1&#038;bg1=FFFFFF&#038;fc1=000000&#038;lc1=0000FF&#038;t=bakingpowder-22&#038;o=9&#038;p=8&#038;l=as1&#038;m=amazon&#038;f=ifr&#038;md=1X69VDGQCMF7Z30FM082&#038;asins=4797353953" style="width:120px;height:240px;" scrolling="no" marginwidth="0" marginheight="0" frameborder="0"></iframe></p>

<div style="font-size:0px;height:0px;line-height:0px;margin:0;padding:0;clear:both"></div>]]></content:encoded>
			<wfw:commentRss>http://blog.tmiz.net/?feed=rss2&amp;p=264</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Magic TrackPad買いました</title>
		<link>http://blog.tmiz.net/?p=256</link>
		<comments>http://blog.tmiz.net/?p=256#comments</comments>
		<pubDate>Sat, 31 Jul 2010 02:58:08 +0000</pubDate>
		<dc:creator>tmiz</dc:creator>
				<category><![CDATA[ハードウェア]]></category>

		<guid isPermaLink="false">http://blog.tmiz.net/?p=256</guid>
		<description><![CDATA[
Magic TrackPadを渋谷のApple Storeで買ってきました。
なんか、Mac OS Xの「ウインドウ」みたいですよね。赤とオレンジと緑のグミを並べるとかすると、いっそうそんなふうに見えるかも。


使っ [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://farm5.static.flickr.com/4148/4845442130_9f86390b77_s.jpg"></p>
<p>Magic TrackPadを渋谷のApple Storeで買ってきました。<br />
なんか、Mac OS Xの「ウインドウ」みたいですよね。赤とオレンジと緑のグミを並べるとかすると、いっそうそんなふうに見えるかも。</p>
<p><span id="more-256"></span></p>
<p><a href="http://www.flickr.com/photos/tmiz/4845437274/" title="Magic TrackPad by tmiz, on Flickr"><img src="http://farm5.static.flickr.com/4108/4845437274_818c533be5.jpg" width="500" height="375" alt="Magic TrackPad" /></a></p>
<h3>使ってみての感想</h3>
<p>いいですねぇ。トラックボール派なので、設置面積が膨らむ入力インタフェースはあり得ない、腕の移動距離が大きいのはあり得ない、と言い続けてきたわけですが、これなら、トラックボールじゃなくても満足できるかもしれません。ノートと違い、スペースキーの下におかなくていいのも便利。それと、3本4本のジェスチャはやっぱり便利。とくにExposeですかね。おおむね満足です。</p>
<h3>それと。。</h3>
<p>ただまぁ、プログラマーにしか関係ありませんが、HID UtilitiesでGeneric Desktop X/Yをマウスとして認識するのに値が0しかとれない問題をみつけて、Apple Developer Forumに投げたりとかしてみました。</p>
<p>新しすぎると、こういったものでもトラブルがありますね（泣。</p>
<p><iframe src="http://rcm-jp.amazon.co.jp/e/cm?lt1=_blank&#038;bc1=000000&#038;IS2=1&#038;bg1=FFFFFF&#038;fc1=000000&#038;lc1=0000FF&#038;t=bakingpowder-22&#038;o=9&#038;p=8&#038;l=as1&#038;m=amazon&#038;f=ifr&#038;md=1X69VDGQCMF7Z30FM082&#038;asins=B003XKO2LW" style="width:120px;height:240px;" scrolling="no" marginwidth="0" marginheight="0" frameborder="0"></iframe></p>

<div style="font-size:0px;height:0px;line-height:0px;margin:0;padding:0;clear:both"></div>]]></content:encoded>
			<wfw:commentRss>http://blog.tmiz.net/?feed=rss2&amp;p=256</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Pasteboard Recorder 2.07をリリース</title>
		<link>http://blog.tmiz.net/?p=237</link>
		<comments>http://blog.tmiz.net/?p=237#comments</comments>
		<pubDate>Fri, 30 Jul 2010 17:43:03 +0000</pubDate>
		<dc:creator>tmiz</dc:creator>
				<category><![CDATA[ソフト]]></category>

		<guid isPermaLink="false">http://blog.tmiz.net/?p=237</guid>
		<description><![CDATA[
Pasteboard Recorder 2.07をリリースしました。
今回の変更は見た目の変更を含むので、ちょっと、ドキドキです。


主な変更点は以下のとおりです。
-ショートカット早見表示
-ログイン時の自動起動項 [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://gyazo.com/85ad499433eb4dc5683ba9cbf65cb47f.png" width=70%><br />
Pasteboard Recorder 2.07をリリースしました。<br />
今回の変更は見た目の変更を含むので、ちょっと、ドキドキです。</p>
<p><span id="more-237"></span></p>
<p><img src="http://tg.tmiz.net/softwares/pr2/pr2_title_en.png" width=80%></p>
<p>主な変更点は以下のとおりです。<br />
-ショートカット早見表示<br />
-ログイン時の自動起動項目に追加する機能<br />
-Preferencesの整理と挙動の調整<br />
-非Activate時の半透明<br />
-固定フレーズ挿入機能<br />
-日時をペーストバッファにホットキーで挿入<br />
-64ビット対応（Snow Leopard以降）<br />
-バグ修正（結構たくさん）</p>
<p>いろいろ手間をかけました。</p>
<p><img src="http://gyazo.com/b43edeedbb56ef7779da763ca661ba95.png" width=70%></p>
<p>上記の画面は、固定フレーズ挿入機能です。この画面はPreferenceに含まれています。ペーストボードを、ここで指定した文字列に、キー一発で入れ替えます。<br />
[ctrl]+[option]+[shift]+[1]〜[9]で切り替えられます。[ctrl]+[option]+[shift]+[0]では「日時文字列」に入れ替えます。ここの値はユーザースコープのプリファレンスに保存されます（Windowsでゆうところのユーザーのレジストリに保存されます）。</p>
<p>ダウンロードはこちらからどうぞ。<br />
<a href="http://tg.tmiz.net/softwares/pr2/index.html">http://tg.tmiz.net/softwares/pr2/index.html</a></p>
<h3>PR2トピック</h3>
<p><a href="http://www.macupdate.com/info.php/id/19935/pasteboard-recorder">MacUpdate単体で5000ダウンロード</a>を超えました。<br />
<a href="http://www.apple.com/downloads/macosx/productivity_tools/index_top.html">AppleのDownloadsのProductivity ToolsのMost Popular</a>でさりげなく15位（20位以内だと1ページ目）をキープ。</p>
<p>アクティブユーザーはそれほど多くないでしょうけど、それなりに好評なようでよかったです。</p>
<p>以下のMacFanに2/9ページを使って紹介されていました。<br />
<a href="http://www.flickr.com/photos/tmiz/4844786623/" title="Untitled by tmiz, on Flickr"><img src="http://farm5.static.flickr.com/4148/4844786623_08107f563d_m.jpg" width="180" height="240" alt="Untitled" /></a><br />
連絡がなかったんで、知ったのは後日で、先日やっと図書館で見つけたわけですが。。。入手はできませんでした。</p>
<p>それ以外にも「Mac100% vol.9」という雑誌では1/2ページで紹介していただいています。こちらのほうはムックで、入手できます。</p>

<div style="font-size:0px;height:0px;line-height:0px;margin:0;padding:0;clear:both"></div>]]></content:encoded>
			<wfw:commentRss>http://blog.tmiz.net/?feed=rss2&amp;p=237</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>ざ、スカイ</title>
		<link>http://blog.tmiz.net/?p=234</link>
		<comments>http://blog.tmiz.net/?p=234#comments</comments>
		<pubDate>Tue, 13 Jul 2010 09:59:20 +0000</pubDate>
		<dc:creator>tmiz</dc:creator>
				<category><![CDATA[見かけたもの]]></category>

		<guid isPermaLink="false">http://blog.tmiz.net/?p=234</guid>
		<description><![CDATA[日本語って、面白いものです。


]]></description>
			<content:encoded><![CDATA[<p>日本語って、面白いものです。</p>
<p><a href="http://blog.tmiz.net/wp-content/uploads/2010/07/p_2048_1536_356DD123-C16D-4299-8D6D-0B2AE915C2EF.jpeg"><img src="http://blog.tmiz.net/wp-content/uploads/2010/07/p_2048_1536_356DD123-C16D-4299-8D6D-0B2AE915C2EF.jpeg" alt="" class="alignnone size-full" width=256px/></a></p>

<div style="font-size:0px;height:0px;line-height:0px;margin:0;padding:0;clear:both"></div>]]></content:encoded>
			<wfw:commentRss>http://blog.tmiz.net/?feed=rss2&amp;p=234</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>ガット</title>
		<link>http://blog.tmiz.net/?p=232</link>
		<comments>http://blog.tmiz.net/?p=232#comments</comments>
		<pubDate>Tue, 13 Jul 2010 02:08:18 +0000</pubDate>
		<dc:creator>tmiz</dc:creator>
				<category><![CDATA[見かけたもの]]></category>

		<guid isPermaLink="false">http://blog.tmiz.net/?p=232</guid>
		<description><![CDATA[なんか、分かった。


]]></description>
			<content:encoded><![CDATA[<p>なんか、分かった。</p>
<p><a href="http://blog.tmiz.net/wp-content/uploads/2010/07/p_2048_1536_1E0D0172-E5A1-4789-8D49-82DAB61F6C6B.jpeg"><img src="http://blog.tmiz.net/wp-content/uploads/2010/07/p_2048_1536_1E0D0172-E5A1-4789-8D49-82DAB61F6C6B.jpeg" alt="" width="225" height="300" class="alignnone size-full wp-image-364" /></a></p>

<div style="font-size:0px;height:0px;line-height:0px;margin:0;padding:0;clear:both"></div>]]></content:encoded>
			<wfw:commentRss>http://blog.tmiz.net/?feed=rss2&amp;p=232</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Pasteboard Recorder 2.06をリリース</title>
		<link>http://blog.tmiz.net/?p=221</link>
		<comments>http://blog.tmiz.net/?p=221#comments</comments>
		<pubDate>Thu, 08 Jul 2010 05:33:25 +0000</pubDate>
		<dc:creator>tmiz</dc:creator>
				<category><![CDATA[ソフト]]></category>
		<category><![CDATA[Pasteboard Recorder]]></category>
		<category><![CDATA[Tool]]></category>

		<guid isPermaLink="false">http://blog.tmiz.net/?p=221</guid>
		<description><![CDATA[
Pasteboard Recorder 2.06をリリースしました。
今回の変更の目玉は、新機能「プレインテキスト化」です。
現在のペーストボード上にあるアイテムから、プレインテキスト以外の情報を除外し、ただのプレイン [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://www.macupdate.com/images/icons/19935.png"></p>
<p>Pasteboard Recorder 2.06をリリースしました。<br />
今回の変更の目玉は、新機能「プレインテキスト化」です。<br />
現在のペーストボード上にあるアイテムから、プレインテキスト以外の情報を除外し、ただのプレインテキストのデータだけがペーストボード上にある状態にする機能です。<br />
別に記録中でなくても使えます。</p>
<p><span id="more-221"></span></p>
<p></p>
<p>この機能は、何のためにあるかというと、「スティッキーズ」「Evernoteのノート機能」など、いわゆるリッチテキストのテキストフィールドに対して、Webブラウザで範囲指定で断片をペーストしたとき、通常ならリッチテキスト属性までペーストされますが、その前に、この「プレインテキスト化」機能を使うことで、それを避けることができるというわけです。</p>
<p>プレインテキスト化は、キーボードショートカットで可能です。それもホットキー対応なので、[command]+[option]+[P]と入力するだけで、Pasteboard Recorderが前面になくても、動作します。また、ステータスメニューの「Convert to Plain Text」からでも実行することが可能です。</p>
<p><a href="http://www.flickr.com/photos/tmiz/4773689280/"; title="test by tmiz, on Flickr"><img src="http://farm5.static.flickr.com/4118/4773689280_40c7c618a4.jpg"; width="500" height="261" alt="test" /></a></p>
<p>上記の画像は使用画像です。通常だったら、左側のようにSafariで範囲選択してコピーして、それをスティッキーズに貼付けようとすると、右上のようになると思います。「プレインテキスト化」をすると、右下のようにテキストのみが貼付けられます。</p>
<p>もし、あなたが、何かのエディタを利用中、ブラウザで得た情報をコピペしようとして、リッチテキスト属性が残ってしまうのが嫌で、テキストエディタに一度貼付けてからEvernoteに貼り付けてるような人ならば、ぜひ、この機能を使ってみてください。</p>
<ul>
<li><a href="http://bit.ly/cRGPlM">Pasteboard Recorder 2.06</a></li>
</ul>

<div style="font-size:0px;height:0px;line-height:0px;margin:0;padding:0;clear:both"></div>]]></content:encoded>
			<wfw:commentRss>http://blog.tmiz.net/?feed=rss2&amp;p=221</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
