<?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"
	>

<channel>
	<title>Necessary and Sufficient</title>
	<atom:link href="http://www.necessaryandsufficient.net/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.necessaryandsufficient.net</link>
	<description>Damien Wintour's personal musings on technology, mathematics, startups and leadership.</description>
	<pubDate>Fri, 02 Jul 2010 09:54:34 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.6</generator>
	<language>en</language>
			<item>
		<title>Google Code Jam 2010: Snapper Chain</title>
		<link>http://www.necessaryandsufficient.net/2010/05/google-code-jam-2010-snapper-chain/</link>
		<comments>http://www.necessaryandsufficient.net/2010/05/google-code-jam-2010-snapper-chain/#comments</comments>
		<pubDate>Mon, 10 May 2010 13:23:40 +0000</pubDate>
		<dc:creator>Damien Wintour</dc:creator>
		
		<category><![CDATA[Uncategorized]]></category>

		<category><![CDATA[algorithms]]></category>

		<category><![CDATA[C++/C#]]></category>

		<category><![CDATA[Google]]></category>

		<category><![CDATA[mathematics]]></category>

		<category><![CDATA[puzzles]]></category>

		<guid isPermaLink="false">http://www.necessaryandsufficient.net/?p=3627</guid>
		<description><![CDATA[Code Jam 2010 started with a qualification round that was harder than previous years. The first problem, Snapper Chain, involves a series of N switches arranged in sequence, that toggle when you snap your fingers if they are receiving power. The problem asks that you indicate if a light plugged into the end of the [...]]]></description>
			<content:encoded><![CDATA[<p><img class="floatleft" title="codejame_logo" src="http://www.necessaryandsufficient.net/wp-content/uploads/2008/07/logo_image1.gif" alt="Google Code Jam" width="150" height="56" />Code Jam 2010 started with a qualification round that was harder than previous years. The first problem, Snapper Chain, involves a series of N switches arranged in sequence, that toggle when you snap your fingers if they are receiving power. The problem asks that you indicate if a light plugged into the end of the chain of N switches will be on after K toggles. A brute force evaluation of the state of the light would have a run time ~ O(NK). This isn't feasible since the upper limits on N and K are 30 and 10<sup>8</sup> respectively. That would take far too long to evaluate. Intuitively you know there must be some sort of pattern so in an effort to get clarity on it it's best to list the states for some toggles. So let's start with N=5 and see what we find...</p>
<div class="floatleft">
<table border="1" cellpadding="3" cellspacing="0" style="margin-left: 0px; margin-right: 10px;">
<tr>
<td>K</td>
<td>State</td>
</tr>
<tr>
<td>0</td>
<td>00000</td>
</tr>
<tr>
<td>1</td>
<td>10000</td>
</tr>
<tr>
<td>2</td>
<td>01000</td>
</tr>
<tr>
<td>3</td>
<td>11000</td>
</tr>
<tr>
<td>4</td>
<td>00100</td>
</tr>
<tr>
<td>5</td>
<td>10100</td>
</tr>
<tr>
<td>6</td>
<td>01100</td>
</tr>
<tr>
<td>7</td>
<td>11100</td>
</tr>
<tr>
<td>8</td>
<td>00010</td>
</tr>
<tr>
<td>9</td>
<td>10010</td>
</tr>
</table>
</div>
<div class="floatleft">
<table border="1" cellpadding="3" cellspacing="0" style="margin-left: 0px; margin-right: 10px;">
<tr>
<td>K</td>
<td>State</td>
</tr>
<tr>
<td>10</td>
<td>01010</td>
</tr>
<tr>
<td>11</td>
<td>11010</td>
</tr>
<tr>
<td>12</td>
<td>00110</td>
</tr>
<tr>
<td>13</td>
<td>10110</td>
</tr>
<tr>
<td>14</td>
<td>01110</td>
</tr>
<tr>
<td>15</td>
<td>11110</td>
</tr>
<tr>
<td>16</td>
<td>00001</td>
</tr>
<tr>
<td>17</td>
<td>10001</td>
</tr>
<tr>
<td>18</td>
<td>01001</td>
</tr>
<tr>
<td>19</td>
<td>11001</td>
</tr>
</table>
</div>
<div class="floatleft">
<table border="1" cellpadding="3" cellspacing="0" style="margin-left: 0px; margin-right: 10px;">
<tr>
<td>K</td>
<td>State</td>
</tr>
<tr>
<td>20</td>
<td>00101</td>
</tr>
<tr>
<td>21</td>
<td>10101</td>
</tr>
<tr>
<td>22</td>
<td>01101</td>
</tr>
<tr>
<td>23</td>
<td>11101</td>
</tr>
<tr>
<td>24</td>
<td>00011</td>
</tr>
<tr>
<td>25</td>
<td>10011</td>
</tr>
<tr>
<td>26</td>
<td>01011</td>
</tr>
<tr>
<td>27</td>
<td>11011</td>
</tr>
<tr>
<td>28</td>
<td>00111</td>
</tr>
<tr>
<td>29</td>
<td>10111</td>
</tr>
<tr>
<td>30</td>
<td>01111</td>
</tr>
<tr>
<td>31</td>
<td>11111</td>
</tr>
</table>
</div>
<p>Now it becomes clear how things work. The first switch toggles with every snap so it's immediately obvious that after an even number of snaps the light <em>cannot </em>be on. Conversely, if N=1 then the light would be on for all odd values of K. If N=2, then we can see that the light would be on when K=3, 7, 11, 15, 19, 23 27,31. That seems to be a pattern with common increments of 4. If N=3, the light would be on when K=7,15, 23,31 - common increments of 8. And for N=4, the light is on when K=15,31 - an increment of 16. It seems that the increments are powers of two. In other words, for a given N and K we can hypothesize that the light is only on when K satisfies the following formula:</p>
<p><center><img src="http://www.necessaryandsufficient.net/wp-content/uploads/2010/06/image010.gif" alt="" title="image010" width="229" height="52" class="aligncenter size-full wp-image-3651" /></center></p>
<p>Here <em>c</em> is any non-negative integer. In other words, the light is on after a certain number of  snaps and it comes back on after a cycle of 2<sup>N</sup> more snaps. Since N << K the summation term here is not a major concern. It is in fact the sum of a geometric progression so the summation could be replaced with a simpler term but since N is fairly small (<30) I didn't bother to optimise it further. I did add <em>memoization </em>to remember the sum of N items so we only ever need to calculate the sum of 30 items once. Here's some C# code to solve the problem:</p>
<p><!-- code formatted by http://manoli.net/csharpformat/ --></p>
<div class="csharpcode">
<pre><span class="lnum">   1:  </span><span class="kwrd">using</span> System;</pre>
<pre><span class="lnum">   2:  </span><span class="kwrd">using</span> System.Collections.Generic;</pre>
<pre><span class="lnum">   3:  </span><span class="kwrd">using</span> System.IO;</pre>
<pre><span class="lnum">   4:  </span>&nbsp;</pre>
<pre><span class="lnum">   5:  </span><span class="kwrd">namespace</span> GoogleCodeJam2010.Qualificiation.SnapperChain</pre>
<pre><span class="lnum">   6:  </span>{</pre>
<pre><span class="lnum">   7:  </span>    <span class="kwrd">class</span> Program</pre>
<pre><span class="lnum">   8:  </span>    {</pre>
<pre><span class="lnum">   9:  </span>        <span class="kwrd">static</span> <span class="kwrd">void</span> Main()</pre>
<pre><span class="lnum">  10:  </span>        {</pre>
<pre><span class="lnum">  11:  </span>            <span class="kwrd">const</span> <span class="kwrd">string</span> basePath = <span class="str">@""</span>;</pre>
<pre><span class="lnum">  12:  </span>            var infile = <span class="kwrd">new</span> StreamReader(basePath + <span class="str">"large.txt"</span>);</pre>
<pre><span class="lnum">  13:  </span>            var outfile = <span class="kwrd">new</span> StreamWriter(basePath + <span class="str">"output.txt"</span>);</pre>
<pre><span class="lnum">  14:  </span>&nbsp;</pre>
<pre><span class="lnum">  15:  </span>            var termSum = <span class="kwrd">new</span> Dictionary&lt;<span class="kwrd">int</span>, <span class="kwrd">ulong</span>&gt;();</pre>
<pre><span class="lnum">  16:  </span>            var cycle = <span class="kwrd">new</span> <span class="kwrd">ulong</span>[31];</pre>
<pre><span class="lnum">  17:  </span>            <span class="kwrd">ulong</span> sum = 0;</pre>
<pre><span class="lnum">  18:  </span>            <span class="kwrd">ulong</span> current = 1;</pre>
<pre><span class="lnum">  19:  </span>            <span class="kwrd">for</span> (<span class="kwrd">int</span> i = 0; i &lt; 31; i++)</pre>
<pre><span class="lnum">  20:  </span>            {</pre>
<pre><span class="lnum">  21:  </span>                sum = sum + current;</pre>
<pre><span class="lnum">  22:  </span>                termSum[i] = sum;</pre>
<pre><span class="lnum">  23:  </span>                current = current * 2;</pre>
<pre><span class="lnum">  24:  </span>                cycle[i] = current;</pre>
<pre><span class="lnum">  25:  </span>            }</pre>
<pre><span class="lnum">  26:  </span>            </pre>
<pre><span class="lnum">  27:  </span>            <span class="kwrd">int</span> t = Int32.Parse(infile.ReadLine());</pre>
<pre><span class="lnum">  28:  </span>            <span class="kwrd">for</span> (<span class="kwrd">int</span> caseNo = 1; caseNo &lt;= t; caseNo++)</pre>
<pre><span class="lnum">  29:  </span>            {</pre>
<pre><span class="lnum">  30:  </span>                var data = infile.ReadLine().Split(<span class="str">' '</span>);</pre>
<pre><span class="lnum">  31:  </span>                <span class="kwrd">int</span> n = Int32.Parse(data[0]);</pre>
<pre><span class="lnum">  32:  </span>                <span class="kwrd">ulong</span> k = UInt64.Parse(data[1]);</pre>
<pre><span class="lnum">  33:  </span>&nbsp;</pre>
<pre><span class="lnum">  34:  </span>                <span class="kwrd">string</span> answer = <span class="str">"OFF"</span>;</pre>
<pre><span class="lnum">  35:  </span>&nbsp;</pre>
<pre><span class="lnum">  36:  </span>                <span class="kwrd">if</span> ((k - termSum[n-1]) % cycle[n-1] == 0)</pre>
<pre><span class="lnum">  37:  </span>                    answer = <span class="str">"ON"</span>;</pre>
<pre><span class="lnum">  38:  </span>&nbsp;</pre>
<pre><span class="lnum">  39:  </span>                outfile.WriteLine(<span class="str">"Case #{0}: {1}"</span>, caseNo, answer);</pre>
<pre><span class="lnum">  40:  </span>            }</pre>
<pre><span class="lnum">  41:  </span>            infile.Close();</pre>
<pre><span class="lnum">  42:  </span>            outfile.Close();</pre>
<pre><span class="lnum">  43:  </span>        }</pre>
<pre><span class="lnum">  44:  </span>    }</pre>
<pre><span class="lnum">  45:  </span>}</pre>
</div>
]]></content:encoded>
			<wfw:commentRss>http://www.necessaryandsufficient.net/2010/05/google-code-jam-2010-snapper-chain/feed/</wfw:commentRss>
		</item>
		<item>
		<title>A Greek Tragedy : Sovereign Debt and Liquidity Issues</title>
		<link>http://www.necessaryandsufficient.net/2010/05/a-greek-tragedy-sovereign-debt-and-liquidity-issues/</link>
		<comments>http://www.necessaryandsufficient.net/2010/05/a-greek-tragedy-sovereign-debt-and-liquidity-issues/#comments</comments>
		<pubDate>Sat, 01 May 2010 18:13:22 +0000</pubDate>
		<dc:creator>Damien Wintour</dc:creator>
		
		<category><![CDATA[Uncategorized]]></category>

		<category><![CDATA[finance]]></category>

		<guid isPermaLink="false">http://www.necessaryandsufficient.net/?p=3610</guid>
		<description><![CDATA[To understand the current sovereign debt problems in Europe one has to understand the monetary policy options available to the government of a sovereign state. Basically, there are several options available to manage national debt:

Print More Money
Devalue the Currency
Raise Taxes
Raise More Money
Default

Let's run through each of these options and consider how it applies to the [...]]]></description>
			<content:encoded><![CDATA[<p>To understand the current sovereign debt problems in Europe one has to understand the monetary policy options available to the government of a sovereign state. Basically, there are several options available to manage national debt:</p>
<ol>
<li>Print More Money</li>
<li>Devalue the Currency</li>
<li>Raise Taxes</li>
<li>Raise More Money</li>
<li>Default</li>
</ol>
<p>Let's run through each of these options and consider how it applies to the current Greek situation, and perhaps soon to Spain and Portugal.</p>
<p><strong>Print More Money</strong></p>
<p>The majority of Greece's public debt is denominated in Euros - the "local" currency - which means that it could simply print more money to pay off its large debts (you can't do this if your debt is denominated in foreign currencies). Printing more of the local currency does have consequences - it causes <em>inflation </em>which effectively reduces the nominal value of all other debt denominated in the local currency.</p>
<p>However there is a problem here. Although technically and legally a sovereign state, the Greek government doesn't have all the fiscal options usually available to an independent nation. Because it uses the Euro, and that is a shared currency with other nations, it cannot simply print more money because that's controlled by the monetary union of the euro zone. This restriction is in place to prevent other member nations from suffering currency devaluations should a member nation decide to print more of the shared currency (Euros).</p>
<p>Problem one.</p>
<p><strong>Devalue the Currency</strong><br />
A government can devalue its local currency to make the domestic currency cheaper relative to other currencies. There are two implications of a devaluation. First, devaluation makes the country's exports relatively less expensive for foreigners. Second, the devaluation makes foreign products relatively more expensive for domestic consumers, thus discouraging imports. This may help to increase the country's exports and decrease imports, and may therefore help to reduce the current account deficit.</p>
<p>However, for the same reasons stated above - the usage of a shared currency - Greece is unable to devalue its "local" currency because its not in control of the Euro. </p>
<p>Problem two!!</p>
<p><strong>Cut Public Spending and Raise Taxes </strong><br />
To increase its revenue intake the Government can raise taxes in an effort to help pay down the public debt. This is politically unpopular and thus most governments are reluctant to consider it, unless backed into a corner. Greece is doing this, but due to the magnitude of public debt it's going to find it quite difficult to raise enough money fast enough using just this option. It's been reported that Greece owes 300 billion euros which represents a public deficit of 14% of the GDP.</p>
<p>Problem three!!! Now into the "options of last resort"...</p>
<p><strong>Raise More Money</strong><br />
Despite having debt problems, in order to service debts falling due Greece needs to raise more money through issuance of Government Bonds however this is a short-term solution at best. Its been reported that Greece needs to raise some 30+ billion Euros just to meets its obligations for the next 12 months. Taking on new debt obviously doesn't solve the problem of indebtedness long term, and flooding the market with sovereign bonds at a time when many investors think a default is likely causes investors to demand higher yields which makes debt raising a very expensive option. </p>
<p>Problem four!!!!</p>
<p><strong>Default on its Debt</strong><br />
Defaulting on its debt would cause Greece's sovereign credit rating to decrease causing it have to pay more for future borrowings, and industry also suffers. But because Greece is a member nation of the Euro zone any default on its behalf also affects other euro-nations like Germany, Spain, Portugal, and Italy.</p>
<p>A default is likely unless a sufficient large bailout package from the IMF and/or other Euro-nations gets put in place along with other measures. The 3-year 110 million euro package currently on offer courtesy of the IMF is a good start!</p>
<p><strong>Conclusion</strong><br />
Moral of the story... if you let your debt get out of control you are in for a lengthy period of financial hardship to recover. Indeed, that is what Greece currently faces, and its citizens will have little respect for the politicians responsible for monetary policy for letting such an unpleasant situation happen in the first place.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.necessaryandsufficient.net/2010/05/a-greek-tragedy-sovereign-debt-and-liquidity-issues/feed/</wfw:commentRss>
		</item>
		<item>
		<title>A Good Architect / Team Lead</title>
		<link>http://www.necessaryandsufficient.net/2010/04/a-good-architect-team-lead/</link>
		<comments>http://www.necessaryandsufficient.net/2010/04/a-good-architect-team-lead/#comments</comments>
		<pubDate>Sun, 25 Apr 2010 15:13:39 +0000</pubDate>
		<dc:creator>Damien Wintour</dc:creator>
		
		<category><![CDATA[Uncategorized]]></category>

		<category><![CDATA[architecture]]></category>

		<category><![CDATA[Management]]></category>

		<guid isPermaLink="false">http://www.necessaryandsufficient.net/?p=3600</guid>
		<description><![CDATA[Here's my top 10 for a good architect / team leader (in no particular order):

Has superb technical and communication skills that make him/her equally adept at communicating to business stakeholders and technical personnel.
Owns the day-to-day execution of a team by comitting to objectives, driving decision-making, and removing obstacles.
Understands the current and likely future requirements of [...]]]></description>
			<content:encoded><![CDATA[<p>Here's my top 10 for a good architect / team leader (in no particular order):</p>
<ol>
<li>Has superb technical and communication skills that make him/her equally adept at communicating to business stakeholders and technical personnel.</li>
<li>Owns the day-to-day execution of a team by comitting to objectives, driving decision-making, and removing obstacles.</li>
<li>Understands the <em>current </em>and <em>likely future requirements </em>of the business and designs a solution that will allow low-cost changes along anticipated change vectors.</li>
<li>Finds <em>simple solutions</em> to complex problems but, if need be, employs <em>complex solutions </em> such that the complexity is abstracted away from developers.</li>
<li>Ensures key infrastructure pieces have <em>strategic closure</em> so that team members don't need to ingest large doses of non-business-related code.</li>
<li>Cares about not only the technical and algorithmic aspects of technical solutions, but how these impact other team members in terms of productivity and frustration (aka inertia reduction).</li>
<li>Listens to feedback from others and cultivates a <a href="http://www.necessaryandsufficient.net/2010/04/a-culture-of-innovation/">collaborative, innovative culture</a> because he/she understands that good ideas can come from anywhere.</li>
<li>Holds the vision that the team is following, and can espouse that vision to others.</li>
<li>Insulates the team from external influences when necessary.</li>
<li>Is capable of attracting and retaining phenomenal developers because of the value they see in working with said architect/team lead.</li>
</ol>
]]></content:encoded>
			<wfw:commentRss>http://www.necessaryandsufficient.net/2010/04/a-good-architect-team-lead/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Lifted Conversions and Operators in C#</title>
		<link>http://www.necessaryandsufficient.net/2010/04/lifted-conversions-and-operators-in-c/</link>
		<comments>http://www.necessaryandsufficient.net/2010/04/lifted-conversions-and-operators-in-c/#comments</comments>
		<pubDate>Fri, 23 Apr 2010 17:51:55 +0000</pubDate>
		<dc:creator>Damien Wintour</dc:creator>
		
		<category><![CDATA[Uncategorized]]></category>

		<category><![CDATA[.Net]]></category>

		<category><![CDATA[C++/C#]]></category>

		<guid isPermaLink="false">http://www.necessaryandsufficient.net/?p=3570</guid>
		<description><![CDATA[Lifted Conversions
These apply to nullable value types that were introduced in .NET 2. Prior to this reference types were obviously nullable but value types, like int, long, double, decimal, etc, were NOT nullable making it hard to figure out if a value had been set or not without resorting to initializing the value types with [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Lifted Conversions</strong><br />
These apply to nullable value types that were introduced in .NET 2. Prior to this <em>reference types</em> were obviously nullable but <em>value types</em>, like int, long, double, decimal, etc, were NOT nullable making it hard to figure out if a value had been set or not without resorting to initializing the value types with some "magic value" like -1. The language designers for .NET implemented the Nullable<T> construct as a struct that wrapped a base value type, T, and conveniently there is a generic constraint to restrict T to be a value type [ where T: struct]. Now, rather than re-implement all the <em>implicit </em>conversions between value types for nullable value types they adopted a policy of <strong>lifted conversions</strong> from the underlying base value types. This is best illustrated with some some code doing implicit conversions:</p>
<div style="font-family: Courier New; font-size: 11pt; color: black; background: white;">
<p style="margin: 0px;"><span style="color: #2b91af;">&nbsp;&nbsp;&nbsp;&nbsp;1</span>&nbsp;<span style="color: blue;">int</span> i = 1;</p>
<p style="margin: 0px;"><span style="color: #2b91af;">&nbsp;&nbsp;&nbsp;&nbsp;2</span>&nbsp;<span style="color: blue;">long</span> j = 1;</p>
<p style="margin: 0px;"><span style="color: #2b91af;">&nbsp;&nbsp;&nbsp;&nbsp;3</span>&nbsp;</p>
<p style="margin: 0px;"><span style="color: #2b91af;">&nbsp;&nbsp;&nbsp;&nbsp;4</span>&nbsp;<span style="color: blue;">int</span>? ni = 1;</p>
<p style="margin: 0px;"><span style="color: #2b91af;">&nbsp;&nbsp;&nbsp;&nbsp;5</span>&nbsp;<span style="color: blue;">long</span>? nl = 1;</p>
<p style="margin: 0px;"><span style="color: #2b91af;">&nbsp;&nbsp;&nbsp;&nbsp;6</span>&nbsp;</p>
<p style="margin: 0px;"><span style="color: #2b91af;">&nbsp;&nbsp;&nbsp;&nbsp;7</span>&nbsp;j = i;&nbsp;&nbsp;&nbsp; &nbsp; <span style="color: green;">// fine</span></p>
<p style="margin: 0px;"><span style="color: #2b91af;">&nbsp;&nbsp;&nbsp;&nbsp;8</span>&nbsp;nl = ni;&nbsp;&nbsp;&nbsp; <span style="color: green;">// fine</span></p>
<p style="margin: 0px;"><span style="color: #2b91af;">&nbsp;&nbsp;&nbsp;&nbsp;9</span>&nbsp;</p>
<p style="margin: 0px;"><span style="color: #2b91af;">&nbsp;&nbsp;&nbsp;10</span>&nbsp;i = j;&nbsp;&nbsp;&nbsp; &nbsp; <span style="color: green;">// Compile error - downcasts need to be explicit</span></p>
<p style="margin: 0px;"><span style="color: #2b91af;">&nbsp;&nbsp;&nbsp;11</span>&nbsp;ni = nl;&nbsp;&nbsp;&nbsp; <span style="color: green;">// Compile error - downcasts need to be explicit</span></p>
<p style="margin: 0px;"><span style="color: #2b91af;">&nbsp;&nbsp;&nbsp;12</span>&nbsp;</p>
<p style="margin: 0px;"><span style="color: #2b91af;">&nbsp;&nbsp;&nbsp;13</span>&nbsp;ni = i;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: green;">// fine</span></p>
<p style="margin: 0px;"><span style="color: #2b91af;">&nbsp;&nbsp;&nbsp;14</span>&nbsp;ni = j;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: green;">// Compile error - no implicit cast from long to int?</span></p>
</div>
<p>
<p>Line 10 indicates the expected case where a downcast from a long to an int must be explicit thus this line causes a compilation error. Line 11 is attempting to do an implicit cast from a long? to an int? and because of the lack of an implicit cast from a long to an int, it too causes a compilation error. This is in stark contrast to Lines 7 and 8 where the opposite cast is being attempted, int to long and int? to long?. Line 7 works as expected because it is a widening conversion, and Line 8 works because a <strong>lifted conversion</strong> (from int to long) is being used. </p>
<p>Line 13 works fine too because a non-nullable value type has a narrower range of values than it's corresponding nullable value type, so a cast from T? to T is considered safe and can be done implicitly. </p>
<p>Note that lifted conversions are applicable not just to the predefined value types but also to any implicit conversions defined on user-defined value-types (structs). These can be defined using code such as this...</p>
<div style="font-family: Courier New; font-size: 11pt; color: black; background: white;">
<p style="margin: 0px;"><span style="color: blue;">public</span> <span style="color: blue;">struct</span> <span style="color: #2b91af;">Rotation</span></p>
<p style="margin: 0px;">{</p>
<p style="margin: 0px;">&nbsp;&nbsp;&nbsp; <span style="color: blue;">public</span> <span style="color: blue;">int</span> Degrees { <span style="color: blue;">get</span>; <span style="color: blue;">set</span>; }</p>
<p style="margin: 0px;">&nbsp;</p>
<p style="margin: 0px;">&nbsp;&nbsp;&nbsp; <span style="color: green;">// to implicitly cast an int to a Rotation</span></p>
<p style="margin: 0px;">&nbsp;&nbsp;&nbsp; <span style="color: blue;">public</span> <span style="color: blue;">static</span> <span style="color: blue;">implicit</span> <span style="color: blue;">operator</span> <span style="color: #2b91af;">Rotation</span>(<span style="color: blue;">int</span> value)</p>
<p style="margin: 0px;">&nbsp;&nbsp;&nbsp; {</p>
<p style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: blue;">return</span> <span style="color: blue;">new</span> <span style="color: #2b91af;">Rotation</span> { Degrees = value % 360 };</p>
<p style="margin: 0px;">&nbsp;&nbsp;&nbsp; }</p>
<p style="margin: 0px;">}</p>
</div>
<p><strong>Lifted Operators</strong><br />
Along similar lines as the lifted conversions on nullable value types, <strong>lifted operators</strong> allow predefined and user-defined operators that work for non-nullable value types also to work for nullable forms of those types. In other words, operators defined on T are available to T? where T is a value type (struct).</p>
<p>I've often heard programmers allude to this as a form of inheritance but that isn't correct. Both user-defined and predefined operators and conversions are defined as static methods (see below) and as such are not inherited. It's because of this that the concept of <em>lifted operators</em> is employed. Consider this simple value type with the addition operator overloaded:</p>
<div style="font-family: Courier New; font-size: 11pt; color: black; background: white;">
<p style="margin: 0px;"><span style="color: blue;">public</span> <span style="color: blue;">struct</span> <span style="color: #2b91af;">Rotation</span></p>
<p style="margin: 0px;">{</p>
<p style="margin: 0px;">&nbsp;&nbsp;&nbsp; <span style="color: blue;">public</span> <span style="color: blue;">int</span> Degrees { <span style="color: blue;">get</span>; <span style="color: blue;">set</span>; }</p>
<p style="margin: 0px;">&nbsp;</p>
<p style="margin: 0px;">&nbsp;&nbsp;&nbsp; <span style="color: blue;">public</span> <span style="color: blue;">static</span> <span style="color: #2b91af;">Rotation</span> <span style="color: blue;">operator</span> +(<span style="color: #2b91af;">Rotation</span> a, <span style="color: #2b91af;">Rotation</span> b)</p>
<p style="margin: 0px;">&nbsp;&nbsp;&nbsp; {</p>
<p style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: blue;">return</span> <span style="color: blue;">new</span> <span style="color: #2b91af;">Rotation</span> {Degrees = (a.Degrees + b.Degrees)%360};</p>
<p style="margin: 0px;">&nbsp;&nbsp;&nbsp; }</p>
<p style="margin: 0px;">}</p>
</div>
<p>When someone comes along after you and creates a Rotation? your overload of the + operator effectively becomes this:</p>
<div style="font-family: Courier New; font-size: 11pt; color: black; background: white;">
<p style="margin: 0px;">&nbsp;&nbsp;&nbsp; <span style="color: green;">// lifted operator for Rotation? is equivalent to...</span></p>
<p style="margin: 0px;">&nbsp;&nbsp;&nbsp; <span style="color: blue;">public</span> <span style="color: blue;">static</span> <span style="color: #2b91af;">Rotation</span>? <span style="color: blue;">operator</span> +(<span style="color: #2b91af;">Rotation</span>? a, <span style="color: #2b91af;">Rotation</span>? b)</p>
<p style="margin: 0px;">&nbsp;&nbsp;&nbsp; {</p>
<p style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: blue;">if</span> (a == <span style="color: blue;">null</span> || b == <span style="color: blue;">null</span> )</p>
<p style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: blue;">return</span> <span style="color: blue;">null</span>;</p>
<p style="margin: 0px;">&nbsp;</p>
<p style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: blue;">return</span> <span style="color: blue;">new</span> <span style="color: #2b91af;">Rotation</span>? </p>
<p style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; { </p>
<p style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; Degrees = (a.Value.Degrees + b.Value.Degrees) % 360 </p>
<p style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; };</p>
<p style="margin: 0px;">&nbsp;&nbsp;&nbsp; }</p>
</div>
<p>
<p>Effectively it does what you'd expect with the bonus <em>null propagation</em> logic added.</p>
<p>There are more subtleties involved in this (like the qualifying criteria for operators to be lifted, and what the type of the return value, if any, is for the lifted operator), so best consult Section 24.3.1. of the <a href="http://download.microsoft.com/download/9/8/f/98fdf0c7-2bbd-40d3-9fd1-5a4159fa8044/csharp%202.0%20specification_sept_2005.doc" target="_new">C# Language Specification</a>. Note that <a href="http://blogs.msdn.com/ericlippert/archive/2007/06/27/what-exactly-does-lifted-mean.aspx" target="_new">Eric Lippert has admitted</a> that the specification is a bit inconsistent with it's use of the term "lifted".</p>
]]></content:encoded>
			<wfw:commentRss>http://www.necessaryandsufficient.net/2010/04/lifted-conversions-and-operators-in-c/feed/</wfw:commentRss>
		</item>
		<item>
		<title>A Culture of Innovation</title>
		<link>http://www.necessaryandsufficient.net/2010/04/a-culture-of-innovation/</link>
		<comments>http://www.necessaryandsufficient.net/2010/04/a-culture-of-innovation/#comments</comments>
		<pubDate>Wed, 21 Apr 2010 05:14:53 +0000</pubDate>
		<dc:creator>Damien Wintour</dc:creator>
		
		<category><![CDATA[Uncategorized]]></category>

		<category><![CDATA[entrepreneurialism]]></category>

		<category><![CDATA[innovation]]></category>

		<guid isPermaLink="false">http://www.necessaryandsufficient.net/?p=3496</guid>
		<description><![CDATA[Not so long ago the magazine Fast Company published a list of the most innovative companies. Business Week also seems to run periodic articles on corporate innovation as well [that's Marissa Mayer of Google on the cover]. And, of course, there is a World Innovation forum for conference-junkies. Lots of experts, like Harvard professor Clayton [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://www.necessaryandsufficient.net/wp-content/uploads/2010/04/bwcover.gif" alt="" title="bwcover" width="225" height="300" class="floatright size-medium wp-image-3510" />Not so long ago the magazine <em>Fast Company</em> published a <a href="http://www.fastcompany.com/mic/2010/industry/most-innovative-technology-companies" target="_new">list</a> of the most innovative companies. <em>Business Week</em> also seems to run periodic articles on corporate innovation as well [that's Marissa Mayer of Google on the cover]. And, of course, there is a <a href="http://us.hsmglobal.com/contenidos/wifhome2010-agenda.html" target="_new">World Innovation forum</a> for conference-junkies. Lots of experts, like Harvard professor <a href="http://www.claytonchristensen.com/" target="_new">Clayton Christensen</a>, say innovation is necessary for <a href="http://www.nytimes.com/2009/05/24/business/24unboxed.html?_r=2&ref=technology" target="_new">both large and small companies</a> to prosper and many people have ideas about <a href="http://www.businessweek.com/debateroom/archives/2010/04/needs-based_inn.html" target="_new">how the innovation process should be done</a>. All this talk about innovation got me thinking about how do you go about encouraging internal innovation in a company. I mulled this over for a bit and here's what I came up with:</p>
<p><strong>Think Big</strong><br />
Many people limit their thinking and because of this are limited in their achievements. It's relatively rare for an individual or an organisation to aim low yet somehow end up achieving great success, thus it's necessary to think big and aim high if you wish to be successful. Thinking big often involves <a href="http://www.necessaryandsufficient.net/2010/01/innovation-takahashi-style/">embracing challenging problems</a> that others avoid because the do not want to or cannot address them. After all, if it was easy everyone would do it and therefore reduce the strategic value of doing it in the first place. </p>
<p><strong>Don't Bet Big</strong><br />
Innovation often conjures up the notion of <em>big </em>ideas produced by "big shots" that want to take <em>big bets</em> on a <em>big future</em>. You get the idea. The problem with the big bet approach is that you are limited to a small number of guesses and if you get it wrong it will go very badly.  A series of smaller bets is a much better approach. Ideas should be prototyped, tested (scientifically if possible), reviewed, and iterated upon. This reduces the risk by getting early feedback and validation of the concept, the business model, and the technology used to develop the product/service. It also helps the stakeholders avoid the "we can't turn back now attitude" that happens when big bets/decisions are made that later turn out to be not so great but there is too much invested and too much political damage for stakeholders to advise that the wrong path has been followed.</p>
<p><strong>Don't Innovate in Secret</strong><br />
"Innovation in secret" is where you don't tell anyone (your customers, your competitors, all of your employees) what you are doing and go off into the R&D cave and hopefully emerge with a killer product a few years later. Apple is famous for doing this and it works for them but it's an extremely risky proposition. There certainly will be a "stealth period" for some start-up companies and for both established and new companies you'll get a few years head start on your competition by doing secret innovation successfully, but a less risky route is to get feedback from select early-adopters and lift the veil of secrecy around your new product/service. Being shrouded in secrecy is more likely to lead to ill-informed decisions and makes it hard to follow the <em>fail fast policy</em> (see next point). The current trend of "crowdsourcing" is one way of harnessing the wisdom of crowds and getting fast feedback from early adopters on in-progress development. </p>
<p><strong>Encourage Risk Taking, Accept Failures, Fail Fast</strong><br />
There is a general belief held by many decision makers that people don't get [fired|demoted|vilified|chastised] for <em>being wrong</em>, they get [fired|demoted|vilified|chastised] for <em>being wrong and different</em>. Thus, they believe it's not in their best interest to take seemingly-radical new directions. This is true in many corporations but for innovation to prosper you need to encourage some risk-taking and more importantly accept that failure is part of the process. Once the internal innovators in the company see that failure doesn't mean excommunication they are more likely to innovate. Of course, you want to try to <strong>fail fast</strong> - so the cost of failure to the company is minimised. This is done by following the second point - make small bets, and by identifying the major risk elements and tackling those elements as early as practically possible. For example, if your product deployment strategy critically depends on customers willingly installing a certain browser plugin, or customers willingly adopting a different behaviour for a particular task, you might want to mitigate this risk very early otherwise even perfect technical execution is going to be irrelevant.<br />
<img src="http://www.necessaryandsufficient.net/wp-content/uploads/2010/04/nepa_cubes_innovation.jpg" alt="" title="innovation" width="300" height="257" class="floatright size-medium wp-image-3508" /><br />
<strong>Reward Good Ideas</strong><br />
People are less likely to devote time to breakthrough innovations if they know they will be rewarded only with a token gesture. If an idea returns a lucrative business outcome it's sensible to financially reward those who created the innovation. After all, people who are clever enough to contribute innovative ideas are smart enough to recognize imbalances in the contribution:compensation ratio and these people will be the first to leave if they feel under-appreciated or under-compensated.</p>
<p><strong>Adopt a Meritocracy</strong><br />
Good ideas are good ideas. Don't let hierarchy, people's job title, length of service with the company, or people's level of remuneration be an issue when judging ideas. This motivates all of the company's employees to contribute to the innovation process which increases your likelihood of success because, although it's hard to believe, <a href="http://www.udemy.com/ideas-come-from-everywhere" target="_new">good ideas can come from anywhere</a>. Personally, I find people who come from a scientific background better at doing this. The facts are gathered and analysed and rational decisions made in the absence of ego and other extraneous influences. Flat hierarchies also assist in this regard because there is less chance of HIPPOs killing projects. [HIPPOs=highest paid person's opinion]</p>
<p><strong>Attitude is Important</strong><br />
Hire super-ambitious people, imaginative people, avaricious people,  people who want to change the world, people who are passionate, people who have the X-factor (if you can find them). Sure stuff needs to <a href="http://www.necessaryandsufficient.net/2008/07/smart-and-gets-things-done/" traget="_new">get done</a> and it's hard to co-ordinate a bunch of very-opinionated people, but for innovation to happen you need people like this. I very much like this list of personal qualities for entrepreneurial employees taken from Gifford Pinchot's book <em>Intrapreneuring</em> and brought to my attention by <a href="http://streambase.typepad.com/streambase_stream_process/2010/01/bigcompanyinnovation.html" target="_new"> Mark Palmer</a>, CEO of Streambase.<br />
<center><img src="http://www.necessaryandsufficient.net/wp-content/uploads/2010/04/intrapeneur.jpg" alt="" title="intrapeneur" width="500" height="666" class="aligncenter size-full wp-image-3533" /></center></p>
]]></content:encoded>
			<wfw:commentRss>http://www.necessaryandsufficient.net/2010/04/a-culture-of-innovation/feed/</wfw:commentRss>
		</item>
	</channel>
</rss>
