<?xml version="1.0" encoding="utf-8"?>
<!-- generator="wordpress/2.1.3" -->
<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/"
	>

<channel>
	<title>Daily Dose of Excel</title>
	<link>http://www.dailydoseofexcel.com</link>
	<description>Daily posts of Excel tips...and other stuff</description>
	<pubDate>Sun, 04 Jan 2009 20:44:55 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.1.3</generator>
	<language>en</language>
			<item>
		<title>Euler Problem 102</title>
		<link>http://www.dailydoseofexcel.com/archives/2009/01/04/euler-problem-102/</link>
		<comments>http://www.dailydoseofexcel.com/archives/2009/01/04/euler-problem-102/#comments</comments>
		<pubDate>Sun, 04 Jan 2009 20:44:55 +0000</pubDate>
		<dc:creator>Michael</dc:creator>
		
		<category><![CDATA[General]]></category>

		<guid isPermaLink="false">http://www.dailydoseofexcel.com/archives/2009/01/04/euler-problem-102/</guid>
		<description><![CDATA[Euler Problem 102 asks:


'Three distinct points are plotted at random on a Cartesian plane, for which 
'-1000 LTE x, y LTE 1000, such that a triangle is formed.
'
'Consider the following two triangles:
'
'A(-340,495), B(-153,-910), C(835,-947)
'
'X(-175,41), Y(-421,-714), Z(574,-645)
'
'It can be verified that triangle ABC contains the origin, whereas 
'triangle XYZ does not.
'
'Using triangles.txt (right click and 'Save [...]]]></description>
			<content:encoded><![CDATA[<p>Euler Problem 102 asks:</p>
<div class="syntax_hilite">
<div id="vb-5">
<div class="vb"><span style="color: #007F00;">'Three distinct points are plotted at random on a Cartesian plane, for which </span><br />
<span style="color: #007F00;">'-1000 LTE x, y LTE 1000, such that a triangle is formed.</span><br />
<span style="color: #007F00;">'</span><br />
<span style="color: #007F00;">'Consider the following two triangles:</span><br />
<span style="color: #007F00;">'</span><br />
<span style="color: #007F00;">'A(-340,495), B(-153,-910), C(835,-947)</span><br />
<span style="color: #007F00;">'</span><br />
<span style="color: #007F00;">'X(-175,41), Y(-421,-714), Z(574,-645)</span><br />
<span style="color: #007F00;">'</span><br />
<span style="color: #007F00;">'It can be verified that triangle ABC contains the origin, whereas </span><br />
<span style="color: #007F00;">'triangle XYZ does not.</span><br />
<span style="color: #007F00;">'</span><br />
<span style="color: #007F00;">'Using triangles.txt (right click and 'Save Link/Target As...'), a 27K text </span><br />
<span style="color: #007F00;">'file containing the co-ordinates of one thousand &quot;random&quot; triangles, find </span><br />
<span style="color: #007F00;">'the number of triangles for which the interior contains the origin.</span><br />
<span style="color: #007F00;">'</span><br />
<span style="color: #007F00;">'NOTE: The first two examples in the file represent the triangles in the </span><br />
<span style="color: #007F00;">'example given above. </span></div>
</div>
</div>
<p></p>
<p>In the above, LTE is "less than or equal", to outsmart the html bugs.</p>
<p>Any triangle that has all-positive x-coordinates, or all-negative x-coordinates, or similarly all-positive or all-negative y-coordinates, can not contain the origin.  A pre-screen will throw all those out.  When I first solved this problem, I looked for triangles with both a positive and a negative y-intercept, coupled with both a positive and negative x-intercept, and counted those triangles.  That was a successful strategy.  LINEST() will return x-intercepts it you swap known-xs and known-ys in the formula.  The code looked like this:</p>
<div class="syntax_hilite">
<div id="vb-6">
<div class="vb">YIntercept<span style="color:#008800;">&#40;</span><span style="color: #cc66cc;">3</span>, <span style="color: #cc66cc;">1</span><span style="color:#008800;">&#41;</span> = Application.WorksheetFunction.Index<span style="color:#008800;">&#40;</span> _<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Application.WorksheetFunction.LinEst<span style="color:#008800;">&#40;</span>Known_Ys, Known_Xs<span style="color:#008800;">&#41;</span>, <span style="color: #cc66cc;">2</span><span style="color:#008800;">&#41;</span><br />
&nbsp;<br />
XIntercept<span style="color:#008800;">&#40;</span><span style="color: #cc66cc;">3</span>, <span style="color: #cc66cc;">1</span><span style="color:#008800;">&#41;</span> = Application.WorksheetFunction.Index<span style="color:#008800;">&#40;</span> _<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Application.WorksheetFunction.LinEst<span style="color:#008800;">&#40;</span>Known_Xs, Known_Ys<span style="color:#008800;">&#41;</span>, <span style="color: #cc66cc;">2</span><span style="color:#008800;">&#41;</span></div>
</div>
</div>
<p></p>
<p>It's right out of the Help for LINEST(), or at least the y-intercept part is.  However, after I checked my answer in I read another strategy that was just so flat-out neat that I coded it up.  It uses Heron's Law which calculates the area of a triangle based on a calculation of the semi-perimeter, or 1/2 the sum of the sides:  The area of a triangle, given the lengths a,b,c of the sides, is A = sqrt s*(s-a)*(s-b)*(s-c), where s is the semiperimeter 0.5*(a+b+c).  If we calculate the area of the suspect triangle, and then the area of the three sub-triangles with a common vertex of the origin, if the sum of the sub-triangle areas equals the area of the whole, then the origin must be within the suspect triangle.  That code looked like this:</p>
<div class="syntax_hilite">
<div id="vb-7">
<div class="vb"><span style="color: #0000DD;">Option</span> <span style="color: #0000DD;">Explicit</span><br />
<span style="color: #0000DD;">Option</span> <span style="color: #0000DD;">Base</span> <span style="color: #cc66cc;">1</span><br />
<span style="color: #0000DD;">Sub</span> Problem_102B<span style="color:#008800;">&#40;</span><span style="color:#008800;">&#41;</span><br />
&nbsp; &nbsp;<span style="color: #0000DD;">Dim</span> Triangle<span style="color:#008800;">&#40;</span><span style="color: #cc66cc;">1000</span><span style="color:#008800;">&#41;</span> <span style="color: #0000DD;">As</span> <span style="color: #0000DD;">Variant</span><br />
&nbsp; &nbsp;<span style="color: #0000DD;">Dim</span> i&nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #0000DD;">As</span> <span style="color: #0000DD;">Long</span><br />
&nbsp; &nbsp;<span style="color: #0000DD;">Dim</span> j&nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #0000DD;">As</span> <span style="color: #0000DD;">Long</span><br />
&nbsp; &nbsp;<span style="color: #0000DD;">Dim</span> Most&nbsp; &nbsp; <span style="color: #0000DD;">As</span> <span style="color: #0000DD;">Long</span><br />
&nbsp; &nbsp;<span style="color: #0000DD;">Dim</span> Impossible <span style="color: #0000DD;">As</span> <span style="color: #0000DD;">Boolean</span><br />
&nbsp; &nbsp;<span style="color: #0000DD;">Dim</span> IsTest&nbsp; <span style="color: #0000DD;">As</span> <span style="color: #0000DD;">Boolean</span><br />
&nbsp; &nbsp;<span style="color: #0000DD;">Dim</span> x<span style="color:#008800;">&#40;</span><span style="color: #cc66cc;">3</span><span style="color:#008800;">&#41;</span>&nbsp; &nbsp; <span style="color: #0000DD;">As</span> <span style="color: #0000DD;">Long</span>&nbsp; <span style="color: #007F00;">'X Coordinates</span><br />
&nbsp; &nbsp;<span style="color: #0000DD;">Dim</span> Y<span style="color:#008800;">&#40;</span><span style="color: #cc66cc;">3</span><span style="color:#008800;">&#41;</span>&nbsp; &nbsp; <span style="color: #0000DD;">As</span> <span style="color: #0000DD;">Long</span>&nbsp; <span style="color: #007F00;">'Y Coordinates</span><br />
&nbsp; &nbsp;<span style="color: #0000DD;">Dim</span> d<span style="color:#008800;">&#40;</span><span style="color: #cc66cc;">3</span><span style="color:#008800;">&#41;</span>&nbsp; &nbsp; <span style="color: #0000DD;">As</span> <span style="color: #0000DD;">Double</span>&nbsp; &nbsp;<span style="color: #007F00;">'Distance between points</span><br />
&nbsp; &nbsp;<span style="color: #0000DD;">Dim</span> O<span style="color:#008800;">&#40;</span><span style="color: #cc66cc;">3</span><span style="color:#008800;">&#41;</span>&nbsp; &nbsp; <span style="color: #0000DD;">As</span> <span style="color: #0000DD;">Double</span>&nbsp; &nbsp;<span style="color: #007F00;">'Distance from points to (0,0)</span><br />
&nbsp; &nbsp;<span style="color: #0000DD;">Dim</span> Area&nbsp; &nbsp; <span style="color: #0000DD;">As</span> <span style="color: #0000DD;">Double</span>&nbsp; &nbsp;<span style="color: #007F00;">'Triangle area</span><br />
&nbsp; &nbsp;<span style="color: #0000DD;">Dim</span> a<span style="color:#008800;">&#40;</span><span style="color: #cc66cc;">3</span><span style="color:#008800;">&#41;</span>&nbsp; &nbsp; <span style="color: #0000DD;">As</span> <span style="color: #0000DD;">Double</span>&nbsp; &nbsp;<span style="color: #007F00;">'Sub-triangle area</span><br />
&nbsp; &nbsp;<span style="color: #0000DD;">Dim</span> T&nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #0000DD;">As</span> <span style="color: #0000DD;">Single</span><br />
&nbsp; &nbsp;<span style="color: #0000DD;">Dim</span> Answer&nbsp; <span style="color: #0000DD;">As</span> <span style="color: #0000DD;">Long</span><br />
&nbsp; &nbsp;<span style="color: #0000DD;">Const</span> <span style="color: #0000DD;">text</span>&nbsp; <span style="color: #0000DD;">As</span> <span style="color: #0000DD;">String</span> = <span style="color: #ff0000;">"D:\Downloads\Euler\triangles.txt"</span><br />
&nbsp;<br />
&nbsp; &nbsp;T = <span style="color: #0000DD;">Timer</span><br />
&nbsp; &nbsp;IsTest = False<br />
&nbsp; &nbsp;<span style="color: #0000DD;">If</span> IsTest <span style="color: #0000DD;">Then</span><br />
&nbsp; &nbsp; &nbsp; Most = <span style="color: #cc66cc;">2</span><br />
&nbsp; &nbsp;<span style="color: #0000DD;">Else</span><br />
&nbsp; &nbsp; &nbsp; Most = <span style="color: #cc66cc;">1000</span><br />
&nbsp; &nbsp;<span style="color: #0000DD;">End</span> <span style="color: #0000DD;">If</span><br />
&nbsp;<br />
&nbsp; &nbsp;i = <span style="color: #cc66cc;">1</span><br />
&nbsp; &nbsp;<span style="color: #0000DD;">Open</span> <span style="color: #0000DD;">text</span> <span style="color: #0000DD;">For</span> <span style="color: #0000DD;">Input</span> <span style="color: #0000DD;">As</span> #1&nbsp; &nbsp;<span style="color: #007F00;">'1000 lines, comma delimited</span><br />
&nbsp; &nbsp;<span style="color: #0000DD;">Do</span> <span style="color: #0000DD;">While</span> <span style="color: #0000DD;">Not</span> <span style="color: #0000DD;">EOF</span><span style="color:#008800;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color:#008800;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #0000DD;">Line</span> <span style="color: #0000DD;">Input</span> #1, Triangle<span style="color:#008800;">&#40;</span>i<span style="color:#008800;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; Triangle<span style="color:#008800;">&#40;</span>i<span style="color:#008800;">&#41;</span> = <span style="color: #0000DD;">Split</span><span style="color:#008800;">&#40;</span>Triangle<span style="color:#008800;">&#40;</span>i<span style="color:#008800;">&#41;</span>, <span style="color: #ff0000;">","</span><span style="color:#008800;">&#41;</span>&nbsp; &nbsp;<span style="color: #007F00;">'zero-based array</span><br />
&nbsp; &nbsp; &nbsp; i = i + <span style="color: #cc66cc;">1</span><br />
&nbsp; &nbsp;<span style="color: #0000DD;">Loop</span><br />
&nbsp; &nbsp;<span style="color: #0000DD;">Close</span> #1<br />
&nbsp;<br />
&nbsp; &nbsp;<span style="color: #0000DD;">For</span> i = <span style="color: #cc66cc;">1</span> <span style="color: #0000DD;">To</span> Most<br />
&nbsp; &nbsp; &nbsp; Impossible = False<br />
&nbsp;<br />
&nbsp; &nbsp; &nbsp; x<span style="color:#008800;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color:#008800;">&#41;</span> = Triangle<span style="color:#008800;">&#40;</span>i<span style="color:#008800;">&#41;</span><span style="color:#008800;">&#40;</span><span style="color: #cc66cc;">0</span><span style="color:#008800;">&#41;</span>&nbsp; &nbsp;<span style="color: #007F00;">'zero-based array</span><br />
&nbsp; &nbsp; &nbsp; Y<span style="color:#008800;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color:#008800;">&#41;</span> = Triangle<span style="color:#008800;">&#40;</span>i<span style="color:#008800;">&#41;</span><span style="color:#008800;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color:#008800;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; x<span style="color:#008800;">&#40;</span><span style="color: #cc66cc;">2</span><span style="color:#008800;">&#41;</span> = Triangle<span style="color:#008800;">&#40;</span>i<span style="color:#008800;">&#41;</span><span style="color:#008800;">&#40;</span><span style="color: #cc66cc;">2</span><span style="color:#008800;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; Y<span style="color:#008800;">&#40;</span><span style="color: #cc66cc;">2</span><span style="color:#008800;">&#41;</span> = Triangle<span style="color:#008800;">&#40;</span>i<span style="color:#008800;">&#41;</span><span style="color:#008800;">&#40;</span><span style="color: #cc66cc;">3</span><span style="color:#008800;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; x<span style="color:#008800;">&#40;</span><span style="color: #cc66cc;">3</span><span style="color:#008800;">&#41;</span> = Triangle<span style="color:#008800;">&#40;</span>i<span style="color:#008800;">&#41;</span><span style="color:#008800;">&#40;</span><span style="color: #cc66cc;">4</span><span style="color:#008800;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; Y<span style="color:#008800;">&#40;</span><span style="color: #cc66cc;">3</span><span style="color:#008800;">&#41;</span> = Triangle<span style="color:#008800;">&#40;</span>i<span style="color:#008800;">&#41;</span><span style="color:#008800;">&#40;</span><span style="color: #cc66cc;">5</span><span style="color:#008800;">&#41;</span><br />
&nbsp;<br />
&nbsp; &nbsp;<span style="color: #007F00;">'For Triangles all above or all below the X-axis</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #0000DD;">If</span> Y<span style="color:#008800;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color:#008800;">&#41;</span>&amp;gt; <span style="color: #cc66cc;">0</span> <span style="color: #0000DD;">And</span> Y<span style="color:#008800;">&#40;</span><span style="color: #cc66cc;">2</span><span style="color:#008800;">&#41;</span>&amp;gt; <span style="color: #cc66cc;">0</span> <span style="color: #0000DD;">And</span> Y<span style="color:#008800;">&#40;</span><span style="color: #cc66cc;">3</span><span style="color:#008800;">&#41;</span>&amp;gt; <span style="color: #cc66cc;">0</span> <span style="color: #0000DD;">Then</span> Impossible = True<br />
&nbsp; &nbsp; &nbsp; <span style="color: #0000DD;">If</span> Y<span style="color:#008800;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color:#008800;">&#41;</span> &amp;lt;<span style="color: #cc66cc;">0</span> <span style="color: #0000DD;">And</span> Y<span style="color:#008800;">&#40;</span><span style="color: #cc66cc;">2</span><span style="color:#008800;">&#41;</span> &amp;lt;<span style="color: #cc66cc;">0</span> <span style="color: #0000DD;">And</span> Y<span style="color:#008800;">&#40;</span><span style="color: #cc66cc;">3</span><span style="color:#008800;">&#41;</span> &amp;lt;<span style="color: #cc66cc;">0</span> <span style="color: #0000DD;">Then</span> Impossible = True<br />
&nbsp; &nbsp;<span style="color: #007F00;">'For Triangles all to left of or all to right of the Y-axis</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #0000DD;">If</span> <span style="color: #0000DD;">Not</span> Impossible <span style="color: #0000DD;">Then</span> <span style="color: #007F00;">'yet</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #0000DD;">If</span> x<span style="color:#008800;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color:#008800;">&#41;</span>&amp;gt; <span style="color: #cc66cc;">0</span> <span style="color: #0000DD;">And</span> x<span style="color:#008800;">&#40;</span><span style="color: #cc66cc;">2</span><span style="color:#008800;">&#41;</span>&amp;gt; <span style="color: #cc66cc;">0</span> <span style="color: #0000DD;">And</span> x<span style="color:#008800;">&#40;</span><span style="color: #cc66cc;">3</span><span style="color:#008800;">&#41;</span>&amp;gt; <span style="color: #cc66cc;">0</span> <span style="color: #0000DD;">Then</span> Impossible = True<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #0000DD;">If</span> x<span style="color:#008800;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color:#008800;">&#41;</span> &amp;lt;<span style="color: #cc66cc;">0</span> <span style="color: #0000DD;">And</span> x<span style="color:#008800;">&#40;</span><span style="color: #cc66cc;">2</span><span style="color:#008800;">&#41;</span> &amp;lt;<span style="color: #cc66cc;">0</span> <span style="color: #0000DD;">And</span> x<span style="color:#008800;">&#40;</span><span style="color: #cc66cc;">3</span><span style="color:#008800;">&#41;</span> &amp;lt;<span style="color: #cc66cc;">0</span> <span style="color: #0000DD;">Then</span> Impossible = True<br />
&nbsp; &nbsp; &nbsp; <span style="color: #0000DD;">End</span> <span style="color: #0000DD;">If</span><br />
&nbsp;<br />
&nbsp; &nbsp; &nbsp; <span style="color: #0000DD;">If</span> Impossible <span style="color: #0000DD;">Then</span> <span style="color: #0000DD;">GoTo</span> Next_i<br />
&nbsp;<br />
&nbsp; &nbsp; &nbsp; d<span style="color:#008800;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color:#008800;">&#41;</span> = TriSides<span style="color:#008800;">&#40;</span><span style="color: #0000DD;">CDbl</span><span style="color:#008800;">&#40;</span>x<span style="color:#008800;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color:#008800;">&#41;</span> - x<span style="color:#008800;">&#40;</span><span style="color: #cc66cc;">2</span><span style="color:#008800;">&#41;</span><span style="color:#008800;">&#41;</span>, <span style="color: #0000DD;">CDbl</span><span style="color:#008800;">&#40;</span>Y<span style="color:#008800;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color:#008800;">&#41;</span> - Y<span style="color:#008800;">&#40;</span><span style="color: #cc66cc;">2</span><span style="color:#008800;">&#41;</span><span style="color:#008800;">&#41;</span><span style="color:#008800;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; d<span style="color:#008800;">&#40;</span><span style="color: #cc66cc;">2</span><span style="color:#008800;">&#41;</span> = TriSides<span style="color:#008800;">&#40;</span><span style="color: #0000DD;">CDbl</span><span style="color:#008800;">&#40;</span>x<span style="color:#008800;">&#40;</span><span style="color: #cc66cc;">2</span><span style="color:#008800;">&#41;</span> - x<span style="color:#008800;">&#40;</span><span style="color: #cc66cc;">3</span><span style="color:#008800;">&#41;</span><span style="color:#008800;">&#41;</span>, <span style="color: #0000DD;">CDbl</span><span style="color:#008800;">&#40;</span>Y<span style="color:#008800;">&#40;</span><span style="color: #cc66cc;">2</span><span style="color:#008800;">&#41;</span> - Y<span style="color:#008800;">&#40;</span><span style="color: #cc66cc;">3</span><span style="color:#008800;">&#41;</span><span style="color:#008800;">&#41;</span><span style="color:#008800;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; d<span style="color:#008800;">&#40;</span><span style="color: #cc66cc;">3</span><span style="color:#008800;">&#41;</span> = TriSides<span style="color:#008800;">&#40;</span><span style="color: #0000DD;">CDbl</span><span style="color:#008800;">&#40;</span>x<span style="color:#008800;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color:#008800;">&#41;</span> - x<span style="color:#008800;">&#40;</span><span style="color: #cc66cc;">3</span><span style="color:#008800;">&#41;</span><span style="color:#008800;">&#41;</span>, <span style="color: #0000DD;">CDbl</span><span style="color:#008800;">&#40;</span>Y<span style="color:#008800;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color:#008800;">&#41;</span> - Y<span style="color:#008800;">&#40;</span><span style="color: #cc66cc;">3</span><span style="color:#008800;">&#41;</span><span style="color:#008800;">&#41;</span><span style="color:#008800;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; Area = Heron<span style="color:#008800;">&#40;</span>d<span style="color:#008800;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color:#008800;">&#41;</span>, d<span style="color:#008800;">&#40;</span><span style="color: #cc66cc;">2</span><span style="color:#008800;">&#41;</span>, d<span style="color:#008800;">&#40;</span><span style="color: #cc66cc;">3</span><span style="color:#008800;">&#41;</span><span style="color:#008800;">&#41;</span><br />
&nbsp;<br />
&nbsp; &nbsp; &nbsp; O<span style="color:#008800;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color:#008800;">&#41;</span> = TriSides<span style="color:#008800;">&#40;</span><span style="color: #0000DD;">CDbl</span><span style="color:#008800;">&#40;</span>x<span style="color:#008800;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color:#008800;">&#41;</span><span style="color:#008800;">&#41;</span>, <span style="color: #0000DD;">CDbl</span><span style="color:#008800;">&#40;</span>Y<span style="color:#008800;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color:#008800;">&#41;</span><span style="color:#008800;">&#41;</span><span style="color:#008800;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; O<span style="color:#008800;">&#40;</span><span style="color: #cc66cc;">2</span><span style="color:#008800;">&#41;</span> = TriSides<span style="color:#008800;">&#40;</span><span style="color: #0000DD;">CDbl</span><span style="color:#008800;">&#40;</span>x<span style="color:#008800;">&#40;</span><span style="color: #cc66cc;">2</span><span style="color:#008800;">&#41;</span><span style="color:#008800;">&#41;</span>, <span style="color: #0000DD;">CDbl</span><span style="color:#008800;">&#40;</span>Y<span style="color:#008800;">&#40;</span><span style="color: #cc66cc;">2</span><span style="color:#008800;">&#41;</span><span style="color:#008800;">&#41;</span><span style="color:#008800;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; O<span style="color:#008800;">&#40;</span><span style="color: #cc66cc;">3</span><span style="color:#008800;">&#41;</span> = TriSides<span style="color:#008800;">&#40;</span><span style="color: #0000DD;">CDbl</span><span style="color:#008800;">&#40;</span>x<span style="color:#008800;">&#40;</span><span style="color: #cc66cc;">3</span><span style="color:#008800;">&#41;</span><span style="color:#008800;">&#41;</span>, <span style="color: #0000DD;">CDbl</span><span style="color:#008800;">&#40;</span>Y<span style="color:#008800;">&#40;</span><span style="color: #cc66cc;">3</span><span style="color:#008800;">&#41;</span><span style="color:#008800;">&#41;</span><span style="color:#008800;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; a<span style="color:#008800;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color:#008800;">&#41;</span> = Heron<span style="color:#008800;">&#40;</span>d<span style="color:#008800;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color:#008800;">&#41;</span>, O<span style="color:#008800;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color:#008800;">&#41;</span>, O<span style="color:#008800;">&#40;</span><span style="color: #cc66cc;">2</span><span style="color:#008800;">&#41;</span><span style="color:#008800;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; a<span style="color:#008800;">&#40;</span><span style="color: #cc66cc;">2</span><span style="color:#008800;">&#41;</span> = Heron<span style="color:#008800;">&#40;</span>d<span style="color:#008800;">&#40;</span><span style="color: #cc66cc;">2</span><span style="color:#008800;">&#41;</span>, O<span style="color:#008800;">&#40;</span><span style="color: #cc66cc;">2</span><span style="color:#008800;">&#41;</span>, O<span style="color:#008800;">&#40;</span><span style="color: #cc66cc;">3</span><span style="color:#008800;">&#41;</span><span style="color:#008800;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; a<span style="color:#008800;">&#40;</span><span style="color: #cc66cc;">3</span><span style="color:#008800;">&#41;</span> = Heron<span style="color:#008800;">&#40;</span>d<span style="color:#008800;">&#40;</span><span style="color: #cc66cc;">3</span><span style="color:#008800;">&#41;</span>, O<span style="color:#008800;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color:#008800;">&#41;</span>, O<span style="color:#008800;">&#40;</span><span style="color: #cc66cc;">3</span><span style="color:#008800;">&#41;</span><span style="color:#008800;">&#41;</span><br />
&nbsp;<br />
&nbsp; &nbsp; &nbsp; <span style="color: #0000DD;">If</span> <span style="color: #0000DD;">CSng</span><span style="color:#008800;">&#40;</span>Area<span style="color:#008800;">&#41;</span> = <span style="color: #0000DD;">CSng</span><span style="color:#008800;">&#40;</span>a<span style="color:#008800;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color:#008800;">&#41;</span> + a<span style="color:#008800;">&#40;</span><span style="color: #cc66cc;">2</span><span style="color:#008800;">&#41;</span> + a<span style="color:#008800;">&#40;</span><span style="color: #cc66cc;">3</span><span style="color:#008800;">&#41;</span><span style="color:#008800;">&#41;</span> <span style="color: #0000DD;">Then</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Answer = Answer + <span style="color: #cc66cc;">1</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #0000DD;">End</span> <span style="color: #0000DD;">If</span><br />
&nbsp;<br />
Next_i:<br />
&nbsp; &nbsp;<span style="color: #0000DD;">Next</span> i<br />
&nbsp;<br />
&nbsp; &nbsp;<span style="color: #0000DD;">Debug</span>.<span style="color: #0000DD;">Print</span> Answer; <span style="color: #ff0000;">"&nbsp; Time:"</span>; <span style="color: #0000DD;">Timer</span> - T<br />
<span style="color: #0000DD;">End</span> <span style="color: #0000DD;">Sub</span></div>
</div>
</div>
<p></p>
<p>Those are the escape code for &gt; and &lt; .  Can't figure out how to get it right inside the vb blocks.  We can escape it outside, but we truncate if we use the angle brackets, and don't render the brackets right if we escape.  It's been a conundrum for a while.</p>
<p>I used two functions, TriSides(), which returns the square root of the sum or difference of two squares, so I could do Pythagorean math, and Heron(), which implements Heron's law:</p>
<div class="syntax_hilite">
<div id="vb-8">
<div class="vb"><span style="color: #0000DD;">Function</span> TriSides<span style="color:#008800;">&#40;</span>a <span style="color: #0000DD;">As</span> <span style="color: #0000DD;">Double</span>, b <span style="color: #0000DD;">As</span> <span style="color: #0000DD;">Double</span>, <span style="color: #0000DD;">Optional</span> <span style="color: #0000DD;">Sum</span><span style="color:#008800;">&#41;</span><br />
&nbsp; &nbsp;<span style="color: #0000DD;">If</span> <span style="color: #0000DD;">IsMissing</span><span style="color:#008800;">&#40;</span><span style="color: #0000DD;">Sum</span><span style="color:#008800;">&#41;</span> <span style="color: #0000DD;">Then</span> <span style="color: #0000DD;">Sum</span> = True<br />
&nbsp; &nbsp;<span style="color: #0000DD;">If</span> <span style="color: #0000DD;">Sum</span> <span style="color: #0000DD;">Then</span><br />
&nbsp; &nbsp; &nbsp; TriSides = <span style="color: #0000DD;">Sqr</span><span style="color:#008800;">&#40;</span>a ^ <span style="color: #cc66cc;">2</span> + b ^ <span style="color: #cc66cc;">2</span><span style="color:#008800;">&#41;</span><br />
&nbsp; &nbsp;<span style="color: #0000DD;">Else</span><br />
&nbsp; &nbsp; &nbsp; TriSides = <span style="color: #0000DD;">Sqr</span><span style="color:#008800;">&#40;</span><span style="color: #0000DD;">Abs</span><span style="color:#008800;">&#40;</span>a ^ <span style="color: #cc66cc;">2</span> - b ^ <span style="color: #cc66cc;">2</span><span style="color:#008800;">&#41;</span><span style="color:#008800;">&#41;</span> <span style="color: #007F00;">' order doesn't matter</span><br />
&nbsp; &nbsp;<span style="color: #0000DD;">End</span> <span style="color: #0000DD;">If</span><br />
<span style="color: #0000DD;">End</span> <span style="color: #0000DD;">Function</span><br />
&nbsp;<br />
<span style="color: #0000DD;">Function</span> Heron<span style="color:#008800;">&#40;</span>a <span style="color: #0000DD;">As</span> <span style="color: #0000DD;">Double</span>, b <span style="color: #0000DD;">As</span> <span style="color: #0000DD;">Double</span>, C <span style="color: #0000DD;">As</span> <span style="color: #0000DD;">Double</span><span style="color:#008800;">&#41;</span> <span style="color: #0000DD;">As</span> <span style="color: #0000DD;">Double</span><br />
<span style="color: #007F00;">'Use Heron 's formula for the area of a triangle</span><br />
<span style="color: #007F00;">'given the lengths a,b,c of the sides</span><br />
<span style="color: #007F00;">'A = sqrt s*(s-a)*(s-b)*(s-c)</span><br />
<span style="color: #007F00;">'where s is the semiperimeter 0.5*(a+b+c).</span><br />
&nbsp;<br />
&nbsp; &nbsp;<span style="color: #0000DD;">Dim</span> s&nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #0000DD;">As</span> <span style="color: #0000DD;">Double</span><br />
&nbsp; &nbsp;s = <span style="color: #cc66cc;">0</span>.<span style="color: #cc66cc;">5</span> * <span style="color:#008800;">&#40;</span>a + b + C<span style="color:#008800;">&#41;</span><br />
&nbsp; &nbsp;Heron = <span style="color: #0000DD;">Sqr</span><span style="color:#008800;">&#40;</span>s * <span style="color:#008800;">&#40;</span>s - a<span style="color:#008800;">&#41;</span> * <span style="color:#008800;">&#40;</span>s - b<span style="color:#008800;">&#41;</span> * <span style="color:#008800;">&#40;</span>s - C<span style="color:#008800;">&#41;</span><span style="color:#008800;">&#41;</span><br />
<span style="color: #0000DD;">End</span> <span style="color: #0000DD;">Function</span></div>
</div>
</div>
<p></p>
<p>I admire those who saw the application of Heron going in.  One thing that I don't understand is why I had to convert doubles to singles at the end for the areas to total per Heron.  I presume is has to do with the square root routine, but I invite comment.  Code ran in one-tenth the time of 102A, at about .01 seconds.</p>
<p>...mrt</p>
]]></content:encoded>
			<wfw:commentRss>http://www.dailydoseofexcel.com/archives/2009/01/04/euler-problem-102/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Recursion as a performance boost!</title>
		<link>http://www.dailydoseofexcel.com/archives/2009/01/02/recursion-as-a-performance-boost/</link>
		<comments>http://www.dailydoseofexcel.com/archives/2009/01/02/recursion-as-a-performance-boost/#comments</comments>
		<pubDate>Sat, 03 Jan 2009 05:58:46 +0000</pubDate>
		<dc:creator>Tushar Mehta</dc:creator>
		
		<category><![CDATA[General]]></category>

		<guid isPermaLink="false">http://www.dailydoseofexcel.com/archives/2009/01/02/recursion-as-a-performance-boost/</guid>
		<description><![CDATA[A common misconception some (many?) have about recursive solutions is that they are not fast.  There are many reasons to use recursion, both in code and in data, mainly that solutions based on recursion are easy to implement, understand, and maintain.  For an introduction see Recursion (http://www.tushar-mehta.com/publish_train/book_vba/07_recursion.htm).
What is interesting is that recursive solutions [...]]]></description>
			<content:encoded><![CDATA[<p>A common misconception some (many?) have about recursive solutions is that they are not fast.  There are many reasons to use recursion, both in code and in data, mainly that solutions based on recursion are easy to implement, understand, and maintain.  For an introduction see Recursion (<a href="http://www.tushar-mehta.com/publish_train/book_vba/07_recursion.htm" target="_blank">http://www.tushar-mehta.com/publish_train/book_vba/07_recursion.htm</a>).</p>
<p>What is interesting is that recursive solutions can also provide an improvement over a non-recursive solution.  This happened recently when I finally decided to tackle Project Euler problem 14 (<a href="http://projecteuler.net/index.php?section=problems&amp;id=14" target="_blank">http://projecteuler.net/index.php?section=problems&amp;id=14</a>).  In the problem, one had to find the number under 1,000,000 that had the longest Collatz chain.</p>
<p>I had postponed addressing the problem because until earlier today I could think of only a "brute force" approach<sup>1</sup>.  But, then, I realized something.  If one started from 1 and worked their way up to 999,999, one could build a database of answers for all the numbers encountered in earlier calculations.  Then, whenever one encountered a number already in the database, a simple look up of the associated would short circuit the need for any further computations.</p>
<p>For the recursive implementation as well as the intuitive approach see Project Euler - Problem 14 <a href="http://www.tushar-mehta.com/misc_tutorials/project_euler/euler014.html" target="_blank">(http://www.tushar-mehta.com/misc_tutorials/project_euler/euler014.html</a>)</p>
<p><sup>1</sup> A approach that should work but that I consider as somewhat unethical is to assume that the solution is a high number.  So, work backwards from 999,999 to 900,000.  Check this solution with the Project Euler system.  If it rejects your answer, try the range 899,999 to 800,000.  If that isn't OK, try the next range down.  Sooner or later you will find the correct answer.  Just keep in mind that the PE website has a 20 minute wait before one can resubmit an answer.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.dailydoseofexcel.com/archives/2009/01/02/recursion-as-a-performance-boost/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Euler Problem 22</title>
		<link>http://www.dailydoseofexcel.com/archives/2009/01/02/euler-problem-22/</link>
		<comments>http://www.dailydoseofexcel.com/archives/2009/01/02/euler-problem-22/#comments</comments>
		<pubDate>Fri, 02 Jan 2009 23:30:08 +0000</pubDate>
		<dc:creator>Michael</dc:creator>
		
		<category><![CDATA[General]]></category>

		<guid isPermaLink="false">http://www.dailydoseofexcel.com/archives/2009/01/02/euler-problem-22/</guid>
		<description><![CDATA[Euler Problem 22 asks:


'Using names.txt (right click and 'Save Link/Target As...'), a 46K text file containing over
'five-thousand first names, begin by sorting it into alphabetical order. Then working out the
'alphabetical value for each name, multiply this value by its alphabetical position in the list
'to obtain a name score.
&#160;
'For example, when the list is sorted into [...]]]></description>
			<content:encoded><![CDATA[<p>Euler Problem 22 asks:</p>
<div class="syntax_hilite">
<div id="vb-12">
<div class="vb"><span style="color: #007F00;">'Using names.txt (right click and 'Save Link/Target As...'), a 46K text file containing over</span><br />
<span style="color: #007F00;">'five-thousand first names, begin by sorting it into alphabetical order. Then working out the</span><br />
<span style="color: #007F00;">'alphabetical value for each name, multiply this value by its alphabetical position in the list</span><br />
<span style="color: #007F00;">'to obtain a name score.</span><br />
&nbsp;<br />
<span style="color: #007F00;">'For example, when the list is sorted into alphabetical order, COLIN, which is worth</span><br />
<span style="color: #007F00;">'3 + 15 + 12 + 9 + 14 = 53, is the 938th name in the list. So, COLIN would obtain a score of</span><br />
<span style="color: #007F00;">'938 * 53 = 49714.</span><br />
&nbsp;<br />
<span style="color: #007F00;">'What is the total of all the name scores in the file? </span></div>
</div>
</div>
<p></p>
<p>The general task is to time the calculation.<br />
The specific tasks are:</p>
<ol>
<li>Open the file</li>
<li>Clean it up (it's one long line of data, with names wrapped in quotes, and comma-delimited, as in ...,"COLIN",...)</li>
<li>Sort the names</li>
<li>Determine each name's alphabetical value<code></code></li>
<li>Multiply the position by the value</li>
<li>Sum the scores</li>
</ol>
<p>Here is my code:</p>
<div class="syntax_hilite">
<div id="vb-13">
<div class="vb"><span style="color: #0000DD;">Option</span> <span style="color: #0000DD;">Explicit</span><br />
<span style="color: #0000DD;">Sub</span> Problem_022<span style="color:#008800;">&#40;</span><span style="color:#008800;">&#41;</span><br />
<span style="color: #0000DD;">Dim</span> NameArray <span style="color: #0000DD;">As</span> <span style="color: #0000DD;">Variant</span><br />
&nbsp; &nbsp;<span style="color: #0000DD;">Dim</span> TEMP&nbsp; &nbsp; <span style="color: #0000DD;">As</span> <span style="color: #0000DD;">String</span><br />
&nbsp; &nbsp;<span style="color: #0000DD;">Dim</span> T&nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #0000DD;">As</span> <span style="color: #0000DD;">Single</span><br />
&nbsp; &nbsp;<span style="color: #0000DD;">Dim</span> i&nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #0000DD;">As</span> <span style="color: #0000DD;">Long</span><br />
&nbsp; &nbsp;<span style="color: #0000DD;">Dim</span> j&nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #0000DD;">As</span> <span style="color: #0000DD;">Long</span><br />
&nbsp; &nbsp;<span style="color: #0000DD;">Dim</span> Score&nbsp; &nbsp;<span style="color: #0000DD;">As</span> <span style="color: #0000DD;">Long</span><br />
&nbsp; &nbsp;<span style="color: #0000DD;">Dim</span> Answer&nbsp; <span style="color: #0000DD;">As</span> <span style="color: #0000DD;">Long</span><br />
&nbsp; &nbsp;<span style="color: #0000DD;">Const</span> namestext <span style="color: #0000DD;">As</span> <span style="color: #0000DD;">String</span> = <span style="color: #ff0000;">"D:\Downloads\Euler\names.txt"</span><br />
&nbsp;<br />
&nbsp; &nbsp;T = <span style="color: #0000DD;">Timer</span> <span style="color: #007F00;">'start timing</span><br />
&nbsp; &nbsp;<span style="color: #0000DD;">Open</span> namestext <span style="color: #0000DD;">For</span> <span style="color: #0000DD;">Input</span> <span style="color: #0000DD;">As</span> #1 <span style="color: #007F00;">' open the file</span><br />
&nbsp; &nbsp;<span style="color: #0000DD;">Do</span> <span style="color: #0000DD;">While</span> <span style="color: #0000DD;">Not</span> <span style="color: #0000DD;">EOF</span><span style="color:#008800;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color:#008800;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #0000DD;">Line</span> <span style="color: #0000DD;">Input</span> #1, TEMP<br />
&nbsp; &nbsp;<span style="color: #0000DD;">Loop</span><br />
&nbsp; &nbsp;<span style="color: #0000DD;">Close</span> #1<br />
&nbsp; &nbsp;TEMP = VBA.Replace<span style="color:#008800;">&#40;</span>TEMP, <span style="color: #0000DD;">Chr</span><span style="color:#008800;">&#40;</span><span style="color: #cc66cc;">34</span><span style="color:#008800;">&#41;</span>, <span style="color: #0000DD;">vbNullString</span><span style="color:#008800;">&#41;</span> <span style="color: #007F00;">'strip quotes -- chr(34)</span><br />
&nbsp;<br />
&nbsp; &nbsp;NameArray = <span style="color: #0000DD;">Split</span><span style="color:#008800;">&#40;</span>TEMP, <span style="color: #ff0000;">","</span><span style="color:#008800;">&#41;</span>&nbsp; &nbsp;<span style="color: #007F00;">'TEMP a comma delimited file, split on the comma</span><br />
&nbsp; &nbsp;<span style="color: #007F00;">'creating an array to sort</span><br />
&nbsp; &nbsp;<span style="color: #007F00;">'BubbleSort</span><br />
&nbsp; &nbsp;<span style="color: #0000DD;">For</span> i = <span style="color: #0000DD;">LBound</span><span style="color:#008800;">&#40;</span>NameArray<span style="color:#008800;">&#41;</span> <span style="color: #0000DD;">To</span> <span style="color: #0000DD;">UBound</span><span style="color:#008800;">&#40;</span>NameArray<span style="color:#008800;">&#41;</span> - <span style="color: #cc66cc;">1</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #0000DD;">For</span> j = i <span style="color: #0000DD;">To</span> <span style="color: #0000DD;">UBound</span><span style="color:#008800;">&#40;</span>NameArray<span style="color:#008800;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #0000DD;">If</span> NameArray<span style="color:#008800;">&#40;</span>i<span style="color:#008800;">&#41;</span>&amp;gt; NameArray<span style="color:#008800;">&#40;</span>j<span style="color:#008800;">&#41;</span> <span style="color: #0000DD;">Then</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; TEMP = NameArray<span style="color:#008800;">&#40;</span>j<span style="color:#008800;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; NameArray<span style="color:#008800;">&#40;</span>j<span style="color:#008800;">&#41;</span> = NameArray<span style="color:#008800;">&#40;</span>i<span style="color:#008800;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; NameArray<span style="color:#008800;">&#40;</span>i<span style="color:#008800;">&#41;</span> = TEMP<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #0000DD;">End</span> <span style="color: #0000DD;">If</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #0000DD;">Next</span> j<br />
&nbsp; &nbsp;<span style="color: #0000DD;">Next</span> i<br />
&nbsp;<br />
&nbsp; &nbsp;<span style="color: #0000DD;">For</span> i = <span style="color: #0000DD;">LBound</span><span style="color:#008800;">&#40;</span>NameArray<span style="color:#008800;">&#41;</span> <span style="color: #0000DD;">To</span> <span style="color: #0000DD;">UBound</span><span style="color:#008800;">&#40;</span>NameArray<span style="color:#008800;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; Score = LexValue<span style="color:#008800;">&#40;</span><span style="color: #0000DD;">CStr</span><span style="color:#008800;">&#40;</span>NameArray<span style="color:#008800;">&#40;</span>i<span style="color:#008800;">&#41;</span><span style="color:#008800;">&#41;</span><span style="color:#008800;">&#41;</span> <span style="color: #007F00;">'computes the alphabetic value</span><br />
&nbsp; &nbsp; &nbsp; Answer = Answer + <span style="color:#008800;">&#40;</span>Score * <span style="color:#008800;">&#40;</span>i + <span style="color: #cc66cc;">1</span><span style="color:#008800;">&#41;</span><span style="color:#008800;">&#41;</span>&nbsp; &nbsp;<span style="color: #007F00;">' NameArray is zero-based </span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #007F00;">'multiplies and sums</span><br />
&nbsp; &nbsp; &nbsp; Score = <span style="color: #cc66cc;">0</span><br />
&nbsp; &nbsp;<span style="color: #0000DD;">Next</span> i<br />
&nbsp;<br />
&nbsp; &nbsp;<span style="color: #0000DD;">Debug</span>.<span style="color: #0000DD;">Print</span> Answer; <span style="color: #ff0000;">"&nbsp; Time:"</span>; <span style="color: #0000DD;">Timer</span> - T<br />
&nbsp;<br />
<span style="color: #0000DD;">End</span> <span style="color: #0000DD;">Sub</span></div>
</div>
</div>
<p></p>
<p>NameArray is zero-based.  Euler's names aren't.  The first name has position 1.  We need to offset by 1.<br />
The alphabetic value is just the sum of the ascii codes (offset by 64, so "A" gets 1) for each letter.  This little function does that.  It'll be used in other Euler problems.</p>
<div class="syntax_hilite">
<div id="vb-14">
<div class="vb"><span style="color: #0000DD;">Function</span> LexValue<span style="color:#008800;">&#40;</span>Word <span style="color: #0000DD;">As</span> <span style="color: #0000DD;">String</span><span style="color:#008800;">&#41;</span> <span style="color: #0000DD;">As</span> <span style="color: #0000DD;">Long</span><br />
&nbsp; &nbsp;<span style="color: #0000DD;">Dim</span> i&nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #0000DD;">As</span> <span style="color: #0000DD;">Long</span><br />
&nbsp; &nbsp;<span style="color: #0000DD;">For</span> i = <span style="color: #cc66cc;">1</span> <span style="color: #0000DD;">To</span> <span style="color: #0000DD;">Len</span><span style="color:#008800;">&#40;</span>Word<span style="color:#008800;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; LexValue = LexValue + <span style="color:#008800;">&#40;</span><span style="color: #0000DD;">Asc</span><span style="color:#008800;">&#40;</span><span style="color: #0000DD;">Mid</span><span style="color:#008800;">&#40;</span>Word, i, <span style="color: #cc66cc;">1</span><span style="color:#008800;">&#41;</span><span style="color:#008800;">&#41;</span> - <span style="color: #cc66cc;">64</span><span style="color:#008800;">&#41;</span><br />
&nbsp; &nbsp;<span style="color: #0000DD;">Next</span> i<br />
<span style="color: #0000DD;">End</span> <span style="color: #0000DD;">Function</span></div>
</div>
</div>
<p></p>
<p>This runs in 15 seconds<br />
...mrt</p>
]]></content:encoded>
			<wfw:commentRss>http://www.dailydoseofexcel.com/archives/2009/01/02/euler-problem-22/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Bubble Sorts</title>
		<link>http://www.dailydoseofexcel.com/archives/2009/01/02/bubble-sorts/</link>
		<comments>http://www.dailydoseofexcel.com/archives/2009/01/02/bubble-sorts/#comments</comments>
		<pubDate>Fri, 02 Jan 2009 23:01:44 +0000</pubDate>
		<dc:creator>Michael</dc:creator>
		
		<category><![CDATA[General]]></category>

		<guid isPermaLink="false">http://www.dailydoseofexcel.com/archives/2009/01/02/bubble-sorts/</guid>
		<description><![CDATA[Two problems so far, Eulers 22 and 29, have required sorts, at least for my implementations.  Euler 22 sorts over 5000 name strings, and Euler 29 sorts nearly 10,000 numerics.  In both cases I used a bubble sort.  Bubble sorts get their name from the image of the greater-valued item "bubbling up" [...]]]></description>
			<content:encoded><![CDATA[<p>Two problems so far, Eulers 22 and 29, have required sorts, at least for my implementations.  Euler 22 sorts over 5000 name strings, and Euler 29 sorts nearly 10,000 numerics.  In both cases I used a bubble sort.  Bubble sorts get their name from the image of the greater-valued item "bubbling up" to its place in line.</p>
<p>Bubble sorts have some advantages and disadvantages.  The BIG disadvantage is that no matter how nearly-sorted the list is at start, you will still go through it (n-1)^2 times, n being the number of items.  The advantages of bubble sorts are:</p>
<ol>
<li>They're easy to code.  Typically just nine lines. And	</li>
<li>To make a descending sort, you reverse just one inequality</li>
</ol>
<p>To do a bubble sort, you need three things:</p>
<ol>
<li>An indexed list or array with a sortable value or property</li>
<li>Explicit or implicit knowledge of the count or quantity of items to sort.  You may know the count (n) because you set it, or the computer knows it via Item.count or UBound(Item), for example</li>
<li>A TEMP variable of the same type as being sorted, often also called SWAP</li>
</ol>
<p>If you think of sorting a deck of cards, the outer loop sorts cards from 1 to 51, and the inner loop compares those values with cards from 2 to 52.  With fast computers, bubble sorts are probably "fast enough."  Both problems for me took less than 20 seconds.</p>
<p>This is my implementation of a bubble sort.  You'll see it used in the next post, on Euler 22.</p>
<div class="syntax_hilite">
<div id="vb-16">
<div class="vb"><span style="color: #0000DD;">Sub</span> BubbleItUp<span style="color:#008800;">&#40;</span><span style="color:#008800;">&#41;</span>&nbsp; &nbsp;<span style="color: #007F00;">'an ascending sort</span><br />
&nbsp;<br />
&nbsp; &nbsp;<span style="color: #0000DD;">Const</span> n&nbsp; &nbsp; &nbsp;<span style="color: #0000DD;">As</span> <span style="color: #0000DD;">Long</span> = <span style="color: #cc66cc;">5</span><br />
&nbsp; &nbsp;<span style="color: #0000DD;">Dim</span> i&nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #0000DD;">As</span> <span style="color: #0000DD;">Long</span><br />
&nbsp; &nbsp;<span style="color: #0000DD;">Dim</span> j&nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #0000DD;">As</span> <span style="color: #0000DD;">Long</span><br />
&nbsp; &nbsp;<span style="color: #0000DD;">Dim</span> Char<span style="color:#008800;">&#40;</span>n<span style="color:#008800;">&#41;</span> <span style="color: #0000DD;">As</span> <span style="color: #0000DD;">String</span> * <span style="color: #cc66cc;">1</span><br />
&nbsp; &nbsp;<span style="color: #0000DD;">Dim</span> TEMP&nbsp; &nbsp; <span style="color: #0000DD;">As</span> <span style="color: #0000DD;">String</span> * <span style="color: #cc66cc;">1</span><br />
&nbsp;<br />
&nbsp; &nbsp;<span style="color: #0000DD;">For</span> i = <span style="color: #cc66cc;">1</span> <span style="color: #0000DD;">To</span> n<br />
&nbsp; &nbsp; &nbsp; Char<span style="color:#008800;">&#40;</span>i<span style="color:#008800;">&#41;</span> = <span style="color: #0000DD;">CStr</span><span style="color:#008800;">&#40;</span>n + <span style="color: #cc66cc;">1</span> - i<span style="color:#008800;">&#41;</span><br />
&nbsp; &nbsp;<span style="color: #0000DD;">Next</span> i<br />
&nbsp;<br />
&nbsp; &nbsp;<span style="color: #0000DD;">Debug</span>.<span style="color: #0000DD;">Print</span> Char<span style="color:#008800;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color:#008800;">&#41;</span>; Char<span style="color:#008800;">&#40;</span><span style="color: #cc66cc;">2</span><span style="color:#008800;">&#41;</span>; Char<span style="color:#008800;">&#40;</span><span style="color: #cc66cc;">3</span><span style="color:#008800;">&#41;</span>; Char<span style="color:#008800;">&#40;</span><span style="color: #cc66cc;">4</span><span style="color:#008800;">&#41;</span>; Char<span style="color:#008800;">&#40;</span><span style="color: #cc66cc;">5</span><span style="color:#008800;">&#41;</span><br />
&nbsp; &nbsp;<span style="color: #0000DD;">For</span> i = <span style="color: #cc66cc;">1</span> <span style="color: #0000DD;">To</span> n - <span style="color: #cc66cc;">1</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #0000DD;">For</span> j = i + <span style="color: #cc66cc;">1</span> <span style="color: #0000DD;">To</span> n<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #0000DD;">If</span> Char<span style="color:#008800;">&#40;</span>i<span style="color:#008800;">&#41;</span>&amp;gt; Char<span style="color:#008800;">&#40;</span>j<span style="color:#008800;">&#41;</span> <span style="color: #0000DD;">Then</span>&nbsp; &nbsp;<span style="color: #007F00;">'flip the inequality for a descending sort</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; TEMP = Char<span style="color:#008800;">&#40;</span>j<span style="color:#008800;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Char<span style="color:#008800;">&#40;</span>j<span style="color:#008800;">&#41;</span> = Char<span style="color:#008800;">&#40;</span>i<span style="color:#008800;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Char<span style="color:#008800;">&#40;</span>i<span style="color:#008800;">&#41;</span> = TEMP<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #0000DD;">End</span> <span style="color: #0000DD;">If</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #0000DD;">Next</span> j<br />
&nbsp; &nbsp; &nbsp; <span style="color: #0000DD;">Debug</span>.<span style="color: #0000DD;">Print</span> Char<span style="color:#008800;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color:#008800;">&#41;</span>; Char<span style="color:#008800;">&#40;</span><span style="color: #cc66cc;">2</span><span style="color:#008800;">&#41;</span>; Char<span style="color:#008800;">&#40;</span><span style="color: #cc66cc;">3</span><span style="color:#008800;">&#41;</span>; Char<span style="color:#008800;">&#40;</span><span style="color: #cc66cc;">4</span><span style="color:#008800;">&#41;</span>; Char<span style="color:#008800;">&#40;</span><span style="color: #cc66cc;">5</span><span style="color:#008800;">&#41;</span><br />
&nbsp; &nbsp;<span style="color: #0000DD;">Next</span> i<br />
&nbsp;<br />
<span style="color: #0000DD;">End</span> <span style="color: #0000DD;">Sub</span></div>
</div>
</div>
<p></p>
<p>...mrt</p>
]]></content:encoded>
			<wfw:commentRss>http://www.dailydoseofexcel.com/archives/2009/01/02/bubble-sorts/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Excel Sample Data</title>
		<link>http://www.dailydoseofexcel.com/archives/2009/01/01/excel-sample-data/</link>
		<comments>http://www.dailydoseofexcel.com/archives/2009/01/01/excel-sample-data/#comments</comments>
		<pubDate>Thu, 01 Jan 2009 16:26:48 +0000</pubDate>
		<dc:creator>Dick Kusleika</dc:creator>
		
		<category><![CDATA[Downloads]]></category>

		<guid isPermaLink="false">http://www.dailydoseofexcel.com/archives/2009/01/01/excel-sample-data/</guid>
		<description><![CDATA[I love finding big Excel tables, mostly because I hate manually creating sample data for testing.  I've written about Contextures Sample Data.  Then there's the IRS Tax Statistics page that has many downloadable Excel files.  The IRS tables aren't always clean tables.  Sometimes they are over-formatted, but they still work.
My latest [...]]]></description>
			<content:encoded><![CDATA[<p>I love finding big Excel tables, mostly because I hate manually creating sample data for testing.  I've written about <a href="http://www.contextures.com/xlsampledata01.html">Contextures Sample Data</a>.  Then there's the <a href="http://www.irs.gov/taxstats/index.html">IRS Tax Statistics</a> page that has many downloadable Excel files.  The IRS tables aren't always clean tables.  Sometimes they are over-formatted, but they still work.</p>
<p>My latest find was a couple of tables used in the book <a href="http://www.irrationalexuberance.com/">Irrational Exuberance</a>.  Robert Shiller says:</p>
<blockquote><p># One can access an Excel file with the data set (used and described in the book) on stock prices, earnings, dividends and interest rates since 1871, updated.<br />
# One can access an Excel file with the data set (used and described in the book) on home prices, building costs, population and interest rates since 1890, updated.</p></blockquote>
<p>I haven't read the book, but it sounds interesting.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.dailydoseofexcel.com/archives/2009/01/01/excel-sample-data/feed/</wfw:commentRss>
		</item>
		<item>
		<title>I Resolve</title>
		<link>http://www.dailydoseofexcel.com/archives/2008/12/31/i-resolve/</link>
		<comments>http://www.dailydoseofexcel.com/archives/2008/12/31/i-resolve/#comments</comments>
		<pubDate>Wed, 31 Dec 2008 19:31:50 +0000</pubDate>
		<dc:creator>Dick Kusleika</dc:creator>
		
		<category><![CDATA[General]]></category>

		<guid isPermaLink="false">http://www.dailydoseofexcel.com/archives/2008/12/31/i-resolve/</guid>
		<description><![CDATA[For 2009, I resolve to stop keeping detailed track of my time at work.  It started as a small experiment to see where I was spending my time.  There weren't any real surprises in the data.  I guess one surprise was how easy it was to use the tool I built to [...]]]></description>
			<content:encoded><![CDATA[<p>For 2009, I resolve to stop keeping detailed track of my time at work.  It started as a small experiment to see where I was spending my time.  There weren't any real surprises in the data.  I guess one surprise was how easy it was to use <a href="http://www.dailydoseofexcel.com/archives/2008/09/02/task-recorder-version1/">the tool I built</a> to keep track.  So easy, in fact, that I just kept on recording my time.  Until today, that is.  Here's how I've spent the last four months.</p>
<p><img src="http://www.dailydoseofexcel.com/blogpix/taskit123108.gif" height="449" width="597" alt="" /></p>
<p>I further resolve to make this tool a proper add-in.  I'll be taking J-Walk's advice and storing the data in a csv file and some other suggestions I got about it.  I'll add some simple reporting options for pulling the data into Excel.  And menus, ribbons, what-have-you.  Then sell it.  I'm thinking free for personal use and $20 for commercial use.  Do you think anyone would buy it?</p>
]]></content:encoded>
			<wfw:commentRss>http://www.dailydoseofexcel.com/archives/2008/12/31/i-resolve/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Euler Problem 19</title>
		<link>http://www.dailydoseofexcel.com/archives/2008/12/30/euler-problem-19/</link>
		<comments>http://www.dailydoseofexcel.com/archives/2008/12/30/euler-problem-19/#comments</comments>
		<pubDate>Wed, 31 Dec 2008 03:06:37 +0000</pubDate>
		<dc:creator>Michael</dc:creator>
		
		<category><![CDATA[General]]></category>

		<guid isPermaLink="false">http://www.dailydoseofexcel.com/archives/2008/12/30/euler-problem-19/</guid>
		<description><![CDATA[Euler Problem 19 asks:


'You are given the following information, but you may prefer to do some 
'research for yourself.
'
'&#160; &#160; * 1 Jan 1900 was a Monday.
'&#160; &#160; * Thirty days has September,
'&#160; &#160; &#160; April, June and November.
'&#160; &#160; &#160; All the rest have thirty-one,
'&#160; &#160; &#160; Saving February alone,
'&#160; &#160; &#160; Which has [...]]]></description>
			<content:encoded><![CDATA[<p>Euler Problem 19 asks:</p>
<div class="syntax_hilite">
<div id="vb-19">
<div class="vb"><span style="color: #007F00;">'You are given the following information, but you may prefer to do some </span><br />
<span style="color: #007F00;">'research for yourself.</span><br />
<span style="color: #007F00;">'</span><br />
<span style="color: #007F00;">'&nbsp; &nbsp; * 1 Jan 1900 was a Monday.</span><br />
<span style="color: #007F00;">'&nbsp; &nbsp; * Thirty days has September,</span><br />
<span style="color: #007F00;">'&nbsp; &nbsp; &nbsp; April, June and November.</span><br />
<span style="color: #007F00;">'&nbsp; &nbsp; &nbsp; All the rest have thirty-one,</span><br />
<span style="color: #007F00;">'&nbsp; &nbsp; &nbsp; Saving February alone,</span><br />
<span style="color: #007F00;">'&nbsp; &nbsp; &nbsp; Which has twenty-eight, rain or shine.</span><br />
<span style="color: #007F00;">'&nbsp; &nbsp; &nbsp; And on leap years, twenty-nine.</span><br />
<span style="color: #007F00;">'&nbsp; &nbsp; * A leap year occurs on any year evenly divisible by 4, but not on a </span><br />
<span style="color: #007F00;">'century unless it is divisible by 400.</span><br />
<span style="color: #007F00;">'</span><br />
<span style="color: #007F00;">'How many Sundays fell on the first of the month during the twentieth </span><br />
<span style="color: #007F00;">'century (1 Jan 1901 to 31 Dec 2000)? </span></div>
</div>
</div>
<p></p>
<p>Wow.  First thought:  Euler actually got the century right.  Math-minded indeed.  Second thought:  I need a day counter, a week counter, a month counter, a leap year checker.  That's a lot of conditionals.  No wonder this is here.  Third thought:  I'm doing this in Excel.  Piece of cake.  This may be the only one aimed right at us, if not intentionally.  Here's my code. Ran in under a second.</p>
<div class="syntax_hilite">
<div id="vb-20">
<div class="vb"><span style="color: #0000DD;">Sub</span> Problem_019<span style="color:#008800;">&#40;</span><span style="color:#008800;">&#41;</span>&nbsp; &nbsp;<br />
&nbsp; &nbsp;<span style="color: #0000DD;">Dim</span> Start&nbsp; &nbsp;<span style="color: #0000DD;">As</span> <span style="color: #0000DD;">Date</span><br />
&nbsp; &nbsp;<span style="color: #0000DD;">Dim</span> Answer&nbsp; <span style="color: #0000DD;">As</span> <span style="color: #0000DD;">Long</span><br />
&nbsp; &nbsp;<span style="color: #0000DD;">Dim</span> T&nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #0000DD;">As</span> <span style="color: #0000DD;">Single</span><br />
&nbsp;<br />
&nbsp; &nbsp;T = <span style="color: #0000DD;">Timer</span><br />
&nbsp; &nbsp;Start = <span style="color: #0000DD;">DateSerial</span><span style="color:#008800;">&#40;</span><span style="color: #cc66cc;">1901</span>, <span style="color: #cc66cc;">1</span>, <span style="color: #cc66cc;">1</span><span style="color:#008800;">&#41;</span><br />
&nbsp;<br />
&nbsp; &nbsp;<span style="color: #0000DD;">Do</span> <span style="color: #0000DD;">While</span> Start &amp;lt; <span style="color: #0000DD;">DateSerial</span><span style="color:#008800;">&#40;</span><span style="color: #cc66cc;">2001</span>, <span style="color: #cc66cc;">1</span>, <span style="color: #cc66cc;">1</span><span style="color:#008800;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #0000DD;">If</span> <span style="color: #0000DD;">Weekday</span><span style="color:#008800;">&#40;</span>Start<span style="color:#008800;">&#41;</span> = <span style="color: #0000DD;">vbSunday</span> <span style="color: #0000DD;">And</span> <span style="color: #0000DD;">Day</span><span style="color:#008800;">&#40;</span>Start<span style="color:#008800;">&#41;</span> = <span style="color: #0000DD;">vbSunday</span> <span style="color: #0000DD;">Then</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Answer = Answer + <span style="color: #cc66cc;">1</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #0000DD;">End</span> <span style="color: #0000DD;">If</span><br />
&nbsp; &nbsp; &nbsp; Start = Start + <span style="color: #cc66cc;">1</span><br />
&nbsp; &nbsp;<span style="color: #0000DD;">Loop</span><br />
&nbsp;<br />
&nbsp; &nbsp;<span style="color: #0000DD;">Debug</span>.<span style="color: #0000DD;">Print</span> Answer; <span style="color: #ff0000;">"&nbsp; Time:"</span>, <span style="color: #0000DD;">Timer</span> - T<br />
&nbsp;<br />
<span style="color: #0000DD;">End</span> <span style="color: #0000DD;">Sub</span></div>
</div>
</div>
<p>  </p>
<p>Coded it up.  It ran the first time, and I checked in with the right answer.  I was feeling so good until I saw the pencil and paper approach of those who'd solved it ...100 years with 12 months per year over 7 days</p>
<p>...mrt</p>
]]></content:encoded>
			<wfw:commentRss>http://www.dailydoseofexcel.com/archives/2008/12/30/euler-problem-19/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Euler Problem 55</title>
		<link>http://www.dailydoseofexcel.com/archives/2008/12/30/euler-problem-55/</link>
		<comments>http://www.dailydoseofexcel.com/archives/2008/12/30/euler-problem-55/#comments</comments>
		<pubDate>Wed, 31 Dec 2008 01:34:10 +0000</pubDate>
		<dc:creator>Michael</dc:creator>
		
		<category><![CDATA[General]]></category>

		<guid isPermaLink="false">http://www.dailydoseofexcel.com/archives/2008/12/30/euler-problem-55/</guid>
		<description><![CDATA[Problem 55 asks:


'If we take 47, reverse and add, 47 + 74 = 121, which is palindromic.
'
'Not all numbers produce palindromes so quickly. For example,
'
'349 + 943 = 1292,
'1292 + 2921 = 4213
'4213 + 3124 = 7337
'
'That is, 349 took three iterations to arrive at a palindrome.
'
'Although no one has proved it yet, it is [...]]]></description>
			<content:encoded><![CDATA[<p>Problem 55 asks:</p>
<div class="syntax_hilite">
<div id="vb-23">
<div class="vb"><span style="color: #007F00;">'If we take 47, reverse and add, 47 + 74 = 121, which is palindromic.</span><br />
<span style="color: #007F00;">'</span><br />
<span style="color: #007F00;">'Not all numbers produce palindromes so quickly. For example,</span><br />
<span style="color: #007F00;">'</span><br />
<span style="color: #007F00;">'349 + 943 = 1292,</span><br />
<span style="color: #007F00;">'1292 + 2921 = 4213</span><br />
<span style="color: #007F00;">'4213 + 3124 = 7337</span><br />
<span style="color: #007F00;">'</span><br />
<span style="color: #007F00;">'That is, 349 took three iterations to arrive at a palindrome.</span><br />
<span style="color: #007F00;">'</span><br />
<span style="color: #007F00;">'Although no one has proved it yet, it is thought that some numbers, like </span><br />
<span style="color: #007F00;">'196, never produce a palindrome. A number that never forms a palindrome </span><br />
<span style="color: #007F00;">'through the reverse and add process is called a Lychrel number. Due to the </span><br />
<span style="color: #007F00;">'theoretical nature of these numbers, and for the purpose of this problem, </span><br />
<span style="color: #007F00;">'we shall assume that a number is Lychrel until proven otherwise. In addition </span><br />
<span style="color: #007F00;">'you are given that for every number below ten-thousand, it will either </span><br />
<span style="color: #007F00;">'(i) become a palindrome in less than fifty iterations, or, (ii) no one, with </span><br />
<span style="color: #007F00;">'all the computing power that exists, has managed so far to map it to a </span><br />
<span style="color: #007F00;">'palindrome. In fact, 10677 is the first number to be shown to require over </span><br />
<span style="color: #007F00;">'fifty iterations before producing a palindrome: </span><br />
<span style="color: #007F00;">'4668731596684224866951378664 (53 iterations, 28-digits).</span><br />
<span style="color: #007F00;">'</span><br />
<span style="color: #007F00;">'Surprisingly, there are palindromic numbers that are themselves Lychrel </span><br />
<span style="color: #007F00;">'numbers; the first example is 4994.</span><br />
<span style="color: #007F00;">'</span><br />
<span style="color: #007F00;">'How many Lychrel numbers are there below ten-thousand?</span><br />
<span style="color: #007F00;">'</span><br />
<span style="color: #007F00;">'NOTE: Wording was modified slightly on 24 April 2007 to emphasise </span><br />
<span style="color: #007F00;">'the theoretical nature of Lychrel numbers. </span></div>
</div>
</div>
<p></p>
<p>Euler problems should calculate under a minute.  This one takes about 1.3 seconds.<br />
Here is my code:</p>
<div class="syntax_hilite">
<div id="vb-24">
<div class="vb"><span style="color: #0000DD;">Option</span> <span style="color: #0000DD;">Explicit</span><br />
<span style="color: #0000DD;">Option</span> <span style="color: #0000DD;">Base</span> <span style="color: #cc66cc;">1</span><br />
<span style="color: #0000DD;">Sub</span> Problem_055<span style="color:#008800;">&#40;</span><span style="color:#008800;">&#41;</span><br />
&nbsp;<br />
&nbsp; &nbsp;<span style="color: #0000DD;">Dim</span> i&nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #0000DD;">As</span> <span style="color: #0000DD;">Long</span><br />
&nbsp; &nbsp;<span style="color: #0000DD;">Dim</span> j&nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #0000DD;">As</span> <span style="color: #0000DD;">Long</span><br />
&nbsp; &nbsp;<span style="color: #0000DD;">Dim</span> T&nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #0000DD;">As</span> <span style="color: #0000DD;">Single</span><br />
&nbsp; &nbsp;<span style="color: #0000DD;">Dim</span> n&nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #0000DD;">As</span> <span style="color: #0000DD;">String</span><br />
&nbsp; &nbsp;<span style="color: #0000DD;">Dim</span> n_rev&nbsp; &nbsp;<span style="color: #0000DD;">As</span> <span style="color: #0000DD;">String</span><br />
&nbsp; &nbsp;<span style="color: #0000DD;">Dim</span> num&nbsp; &nbsp; &nbsp;<span style="color: #0000DD;">As</span> <span style="color: #0000DD;">String</span><br />
&nbsp; &nbsp;<span style="color: #0000DD;">Dim</span> Answer&nbsp; <span style="color: #0000DD;">As</span> <span style="color: #0000DD;">Long</span><br />
&nbsp; &nbsp;<span style="color: #0000DD;">Dim</span> <span style="color: #0000DD;">Max</span>&nbsp; &nbsp; &nbsp;<span style="color: #0000DD;">As</span> <span style="color: #0000DD;">Long</span><br />
&nbsp; &nbsp;<span style="color: #0000DD;">Dim</span> Last&nbsp; &nbsp; <span style="color: #0000DD;">As</span> <span style="color: #0000DD;">Long</span><br />
&nbsp; &nbsp;<span style="color: #0000DD;">Dim</span> IsTest&nbsp; <span style="color: #0000DD;">As</span> <span style="color: #0000DD;">Boolean</span><br />
&nbsp; &nbsp;<span style="color: #0000DD;">Dim</span> Series<span style="color:#008800;">&#40;</span><span style="color: #cc66cc;">5</span><span style="color:#008800;">&#41;</span> <span style="color: #0000DD;">As</span> <span style="color: #0000DD;">String</span><br />
&nbsp;<br />
&nbsp; &nbsp;T = <span style="color: #0000DD;">Timer</span> <span style="color: #007F00;">'start timing</span><br />
&nbsp; &nbsp;IsTest = True<br />
&nbsp; &nbsp;<span style="color: #0000DD;">If</span> IsTest <span style="color: #0000DD;">Then</span> <span style="color: #007F00;">'to test the example cases</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #0000DD;">Max</span> = <span style="color: #cc66cc;">5</span><br />
&nbsp; &nbsp; &nbsp; Last = <span style="color: #cc66cc;">53</span><br />
&nbsp; &nbsp; &nbsp; Series<span style="color:#008800;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color:#008800;">&#41;</span> = <span style="color: #ff0000;">"47"</span><br />
&nbsp; &nbsp; &nbsp; Series<span style="color:#008800;">&#40;</span><span style="color: #cc66cc;">2</span><span style="color:#008800;">&#41;</span> = <span style="color: #ff0000;">"196"</span>&nbsp; &nbsp;<span style="color: #007F00;">'Lychrel</span><br />
&nbsp; &nbsp; &nbsp; Series<span style="color:#008800;">&#40;</span><span style="color: #cc66cc;">3</span><span style="color:#008800;">&#41;</span> = <span style="color: #ff0000;">"349"</span><br />
&nbsp; &nbsp; &nbsp; Series<span style="color:#008800;">&#40;</span><span style="color: #cc66cc;">4</span><span style="color:#008800;">&#41;</span> = <span style="color: #ff0000;">"4994"</span>&nbsp; &nbsp;<span style="color: #007F00;">'Lychrel</span><br />
&nbsp; &nbsp; &nbsp; Series<span style="color:#008800;">&#40;</span><span style="color: #cc66cc;">5</span><span style="color:#008800;">&#41;</span> = <span style="color: #ff0000;">"10677"</span><br />
&nbsp; &nbsp;<span style="color: #0000DD;">Else</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #0000DD;">Max</span> = <span style="color: #cc66cc;">9999</span>&nbsp; &nbsp; <span style="color: #007F00;">' less than 10,000</span><br />
&nbsp; &nbsp; &nbsp; Last = <span style="color: #cc66cc;">50</span><br />
&nbsp; <span style="color: #0000DD;">end</span> <span style="color: #0000DD;">if</span><br />
&nbsp;<br />
&nbsp;<span style="color: #0000DD;">For</span> j = <span style="color: #cc66cc;">1</span> <span style="color: #0000DD;">To</span> <span style="color: #0000DD;">Max</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #0000DD;">If</span> IsTest <span style="color: #0000DD;">Then</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;n = Series<span style="color:#008800;">&#40;</span>j<span style="color:#008800;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #0000DD;">Else</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;n = <span style="color: #0000DD;">CStr</span><span style="color:#008800;">&#40;</span>j<span style="color:#008800;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #0000DD;">End</span> <span style="color: #0000DD;">If</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #0000DD;">For</span> i = <span style="color: #cc66cc;">1</span> <span style="color: #0000DD;">To</span> last <span style="color: #007F00;">'to test 10677</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;n_rev = StrReverse<span style="color:#008800;">&#40;</span>n<span style="color:#008800;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;num = AddAsStrings<span style="color:#008800;">&#40;</span>n, n_rev<span style="color:#008800;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #0000DD;">If</span> num = StrReverse<span style="color:#008800;">&#40;</span>num<span style="color:#008800;">&#41;</span> <span style="color: #0000DD;">Then</span> <span style="color: #007F00;">'not a Lychrel number</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000DD;">Exit</span> <span style="color: #0000DD;">For</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #0000DD;">End</span> <span style="color: #0000DD;">If</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;n = num<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #0000DD;">If</span> i = last <span style="color: #0000DD;">Then</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Answer = Answer + <span style="color: #cc66cc;">1</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #0000DD;">End</span> <span style="color: #0000DD;">If</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #0000DD;">Next</span> i<br />
&nbsp; <span style="color: #0000DD;">Next</span> j<br />
&nbsp;<br />
&nbsp; &nbsp;<span style="color: #0000DD;">Debug</span>.<span style="color: #0000DD;">Print</span> Answer; <span style="color: #ff0000;">"&nbsp; Time:"</span>; <span style="color: #0000DD;">Timer</span> - T<br />
&nbsp;<br />
<span style="color: #0000DD;">End</span> <span style="color: #0000DD;">Sub</span></div>
</div>
</div>
<p></p>
<p>It uses the AddAsStrings() function from Problem 16.  It exits the loop if the addition is equal to its reverse.</p>
<p>Of course, the real question, is why anybody cares about Lychrel numbers, and who would make them their life's work <img src='http://www.dailydoseofexcel.com/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> </p>
<p>...mrt</p>
]]></content:encoded>
			<wfw:commentRss>http://www.dailydoseofexcel.com/archives/2008/12/30/euler-problem-55/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Euler Problem 31</title>
		<link>http://www.dailydoseofexcel.com/archives/2008/12/28/euler-problem-31/</link>
		<comments>http://www.dailydoseofexcel.com/archives/2008/12/28/euler-problem-31/#comments</comments>
		<pubDate>Sun, 28 Dec 2008 23:49:24 +0000</pubDate>
		<dc:creator>Michael</dc:creator>
		
		<category><![CDATA[General]]></category>

		<guid isPermaLink="false">http://www.dailydoseofexcel.com/archives/2008/12/28/euler-problem-31/</guid>
		<description><![CDATA[Euler Problem 31 states:


'In England the currency is made up of pound, £, and pence, p, and there are 
'eight coins in general circulation:
'
'&#160; &#160; 1p, 2p, 5p, 10p, 20p, 50p, £1 (100p) and £2 (200p).
'
'It is possible to make £2 in the following way:
'
'&#160; &#160; 1×£1 + 1×50p + 2×20p + 1×5p + 1×2p [...]]]></description>
			<content:encoded><![CDATA[<p>Euler Problem 31 states:</p>
<div class="syntax_hilite">
<div id="vb-28">
<div class="vb"><span style="color: #007F00;">'In England the currency is made up of pound, £, and pence, p, and there are </span><br />
<span style="color: #007F00;">'eight coins in general circulation:</span><br />
<span style="color: #007F00;">'</span><br />
<span style="color: #007F00;">'&nbsp; &nbsp; 1p, 2p, 5p, 10p, 20p, 50p, £1 (100p) and £2 (200p).</span><br />
<span style="color: #007F00;">'</span><br />
<span style="color: #007F00;">'It is possible to make £2 in the following way:</span><br />
<span style="color: #007F00;">'</span><br />
<span style="color: #007F00;">'&nbsp; &nbsp; 1×£1 + 1×50p + 2×20p + 1×5p + 1×2p + 3×1p</span><br />
<span style="color: #007F00;">'</span><br />
<span style="color: #007F00;">'How many different ways can £2 be made using any number of coins? </span></div>
</div>
</div>
<p></p>
<p>Over in the Euler Problem 16 thread, dbb provided his answer.  This is dbb's code, copied from there, with 8 loops for eight coins:</p>
<div class="syntax_hilite">
<div id="vb-29">
<div class="vb"><span style="color: #0000DD;">Sub</span> P31<span style="color:#008800;">&#40;</span><span style="color:#008800;">&#41;</span><br />
&nbsp;<br />
<span style="color: #0000DD;">Dim</span> P1 <span style="color: #0000DD;">As</span> <span style="color: #0000DD;">Long</span>, P2 <span style="color: #0000DD;">As</span> <span style="color: #0000DD;">Long</span>, P5 <span style="color: #0000DD;">As</span> <span style="color: #0000DD;">Long</span>, P10 <span style="color: #0000DD;">As</span> <span style="color: #0000DD;">Long</span>, P20 <span style="color: #0000DD;">As</span> <span style="color: #0000DD;">Long</span><br />
<span style="color: #0000DD;">Dim</span> P50 <span style="color: #0000DD;">As</span> <span style="color: #0000DD;">Long</span>, P100 <span style="color: #0000DD;">As</span> <span style="color: #0000DD;">Long</span>, P200 <span style="color: #0000DD;">As</span> <span style="color: #0000DD;">Long</span><br />
<span style="color: #0000DD;">Dim</span> n1 <span style="color: #0000DD;">As</span> <span style="color: #0000DD;">Long</span>, n2 <span style="color: #0000DD;">As</span> <span style="color: #0000DD;">Long</span>, n5 <span style="color: #0000DD;">As</span> <span style="color: #0000DD;">Long</span>, n10 <span style="color: #0000DD;">As</span> <span style="color: #0000DD;">Long</span>, n20 <span style="color: #0000DD;">As</span> <span style="color: #0000DD;">Long</span><br />
<span style="color: #0000DD;">Dim</span> n50 <span style="color: #0000DD;">As</span> <span style="color: #0000DD;">Long</span>, n100 <span style="color: #0000DD;">As</span> <span style="color: #0000DD;">Long</span>, n200 <span style="color: #0000DD;">As</span> <span style="color: #0000DD;">Long</span><br />
<span style="color: #0000DD;">Dim</span> n <span style="color: #0000DD;">As</span> <span style="color: #0000DD;">Long</span><br />
&nbsp;<br />
<span style="color: #0000DD;">For</span> P1 = <span style="color: #cc66cc;">0</span> <span style="color: #0000DD;">To</span> <span style="color: #cc66cc;">200</span> <span style="color: #0000DD;">Step</span> <span style="color: #cc66cc;">1</span><br />
&nbsp; &nbsp; n1 = P1<br />
&nbsp; &nbsp; <span style="color: #0000DD;">For</span> P2 = <span style="color: #cc66cc;">0</span> <span style="color: #0000DD;">To</span> <span style="color: #cc66cc;">200</span> - n1 <span style="color: #0000DD;">Step</span> <span style="color: #cc66cc;">2</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; n2 = n1 + P2<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000DD;">For</span> P5 = <span style="color: #cc66cc;">0</span> <span style="color: #0000DD;">To</span> <span style="color: #cc66cc;">200</span> - n2 <span style="color: #0000DD;">Step</span> <span style="color: #cc66cc;">5</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; n5 = n2 + P5<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000DD;">For</span> P10 = <span style="color: #cc66cc;">0</span> <span style="color: #0000DD;">To</span> <span style="color: #cc66cc;">200</span> - n5 <span style="color: #0000DD;">Step</span> <span style="color: #cc66cc;">10</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; n10 = n5 + P10<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000DD;">For</span> P20 = <span style="color: #cc66cc;">0</span> <span style="color: #0000DD;">To</span> <span style="color: #cc66cc;">200</span> - n10 <span style="color: #0000DD;">Step</span> <span style="color: #cc66cc;">20</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; n20 = n10 + P20<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000DD;">For</span> P50 = <span style="color: #cc66cc;">0</span> <span style="color: #0000DD;">To</span> <span style="color: #cc66cc;">200</span> - n20 <span style="color: #0000DD;">Step</span> <span style="color: #cc66cc;">50</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; n50 = n20 + P50<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000DD;">For</span> P100 = <span style="color: #cc66cc;">0</span> <span style="color: #0000DD;">To</span> <span style="color: #cc66cc;">200</span> - n50 <span style="color: #0000DD;">Step</span> <span style="color: #cc66cc;">100</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; n100 = n50 + P100<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000DD;">For</span> P200 = <span style="color: #cc66cc;">0</span> <span style="color: #0000DD;">To</span> <span style="color: #cc66cc;">200</span> - n100 <span style="color: #0000DD;">Step</span> <span style="color: #cc66cc;">200</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000DD;">If</span> n100 + P200 = <span style="color: #cc66cc;">200</span> <span style="color: #0000DD;">Then</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;n = n + <span style="color: #cc66cc;">1</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000DD;">End</span> <span style="color: #0000DD;">If</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000DD;">Next</span> P200<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000DD;">Next</span> P100<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000DD;">Next</span> P50<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000DD;">Next</span> P20<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000DD;">Next</span> P10<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000DD;">Next</span> P5<br />
&nbsp; &nbsp; <span style="color: #0000DD;">Next</span> P2<br />
<span style="color: #0000DD;">Next</span> P1<br />
<span style="color: #0000DD;">Debug</span>.<span style="color: #0000DD;">Print</span> n<br />
&nbsp;<br />
<span style="color: #0000DD;">End</span> <span style="color: #0000DD;">Sub</span></div>
</div>
</div>
<p></p>
<p>It runs in a second and a half on my machine.  Problem 76 looks very similar.</p>
<div class="syntax_hilite">
<div id="vb-30">
<div class="vb"><span style="color: #007F00;">'It is possible to write five as a sum in exactly six different ways:</span><br />
<span style="color: #007F00;">'</span><br />
<span style="color: #007F00;">'4 + 1</span><br />
<span style="color: #007F00;">'3 + 2</span><br />
<span style="color: #007F00;">'3 + 1 + 1</span><br />
<span style="color: #007F00;">'2 + 2 + 1</span><br />
<span style="color: #007F00;">'2 + 1 + 1 + 1</span><br />
<span style="color: #007F00;">'1 + 1 + 1 + 1 + 1</span><br />
<span style="color: #007F00;">'</span><br />
<span style="color: #007F00;">'How many different ways can one hundred be written as a sum of at least </span><br />
<span style="color: #007F00;">'two positive integers? </span></div>
</div>
</div>
<p></p>
<p>Does that mean 100 loops are required?</p>
<p>...mrt</p>
]]></content:encoded>
			<wfw:commentRss>http://www.dailydoseofexcel.com/archives/2008/12/28/euler-problem-31/feed/</wfw:commentRss>
		</item>
		<item>
		<title>UDFs and Moving Add-in Files</title>
		<link>http://www.dailydoseofexcel.com/archives/2008/12/23/udfs-and-moving-add-in-files/</link>
		<comments>http://www.dailydoseofexcel.com/archives/2008/12/23/udfs-and-moving-add-in-files/#comments</comments>
		<pubDate>Tue, 23 Dec 2008 20:51:01 +0000</pubDate>
		<dc:creator>Dick Kusleika</dc:creator>
		
		<category><![CDATA[User Defined Functions]]></category>

		<category><![CDATA[Add-ins]]></category>

		<guid isPermaLink="false">http://www.dailydoseofexcel.com/archives/2008/12/23/udfs-and-moving-add-in-files/</guid>
		<description><![CDATA[I don't use user defined functions in add-ins all that often, but I happen to have a particular add-in with one UDF.  And I happened to have recently moved that add-in.  And all my links happen to be broken.
Fortunately, Jan Karel has an exhaustive write-up on how to fix and prevent this problem. [...]]]></description>
			<content:encoded><![CDATA[<p>I don't use user defined functions in add-ins all that often, but I happen to have a particular add-in with one UDF.  And I happened to have recently moved that add-in.  And all my links happen to be broken.</p>
<p>Fortunately, Jan Karel has an exhaustive write-up on how to fix and prevent this problem.  <a href="http://www.jkp-ads.com/Articles/FixLinks2UDF.asp">Go to FixLinks2UDF.</a></p>
<p>John Walkenbach, in <a href="http://spreadsheetpage.com/index.php/pupv7/home">Power Utility Pak</a>, copies the UDF to the workbook in which it lives.  I think that's perfect for a general purpose utility, but it goes against my rule of keeping code and layout separate.  If I change the UDF, it won't be changed everywhere.  I could make the argument that it shouldn't change for previously created reports, but I just don't know.</p>
<p>In this add-in, I already capture the opening of reports, so I suppose I'll just update the links as they're opened.  In any event, I hope this link love kicks JKP's article higher on Google so I don't have to search so hard for it next time.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.dailydoseofexcel.com/archives/2008/12/23/udfs-and-moving-add-in-files/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Euler Problem 16</title>
		<link>http://www.dailydoseofexcel.com/archives/2008/12/22/euler-problem-16/</link>
		<comments>http://www.dailydoseofexcel.com/archives/2008/12/22/euler-problem-16/#comments</comments>
		<pubDate>Mon, 22 Dec 2008 13:47:42 +0000</pubDate>
		<dc:creator>Michael</dc:creator>
		
		<category><![CDATA[General]]></category>

		<guid isPermaLink="false">http://www.dailydoseofexcel.com/archives/2008/12/22/euler-problem-16/</guid>
		<description><![CDATA[Hello All -
While Dick and company do the heavy lifting around here writing about VBA Frameworks, I asked if I could contribute about lighter fare, specifically the Project Euler Challenges.  I am a systems engineer by trade, and use Excel as a tool to manage requirements.  I confessed to Dick I have probably [...]]]></description>
			<content:encoded><![CDATA[<p>Hello All -</p>
<p>While Dick and company do the heavy lifting around here writing about VBA Frameworks, I asked if I could contribute about lighter fare, specifically the Project Euler Challenges.  I am a systems engineer by trade, and use Excel as a tool to manage requirements.  I confessed to Dick I have probably never used an accounting-specific Excel function, though I've been using Excel since v1.5 (yep...that old).</p>
<p>Project Euler indicates that all the challenges can be computed in less than one minute of computer time.  Once you find a right answer, it's like a password to review the thoughts, code, and  comments of others who solved the problem before you.  It's disconcerting to read from a 14-year-old coder who solved the problem in just a few lines of Haskell (what's that?).  Nobody seems to be doing the problems in VBA, so I asked Dick if I could start conversations about how one might.  One thing I won't post is the answers--that's a password you'll at least have to have Excel to get.  And there are more than a few that I've attempted that I'm stuck on, and then there are the ones that I don't know how to start coding, and still others that I don't understand the mathematics.  Never-the-less...</p>
<p>Did you know that Excel can compute 2^1000 in four tenths of a second?<br />
I didn't either until I attempted Project Euler Problem 16 which states:</p>
<p>2^15 = 32768 and the sum of its digits is 3 + 2 + 7 + 6 + 8 = 26.</p>
<p>What is the sum of the digits of the number 2^1000?</p>
<p>There are two general tasks:
<ol>
<li>Time the calculation</li>
<li>Reproduce the example</li>
</ol>
<p>and two specific tasks:
<ol>
<li>Compute 2 to the 1000</li>
<li>Calculate the sum of the digits</li>
</ol>
<p>Here is my code:</p>
<div class="syntax_hilite">
<div id="vb-33">
<div class="vb"><span style="color: #0000DD;">Option</span> <span style="color: #0000DD;">Explicit</span><br />
<span style="color: #0000DD;">Option</span> <span style="color: #0000DD;">Base</span> <span style="color: #cc66cc;">1</span><br />
<span style="color: #0000DD;">Sub</span> Problem_016<span style="color:#008800;">&#40;</span><span style="color:#008800;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #0000DD;">Dim</span> <span style="color: #0000DD;">exp</span>&nbsp; &nbsp; &nbsp;<span style="color: #0000DD;">As</span> <span style="color: #0000DD;">Long</span><br />
&nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #0000DD;">Dim</span> i&nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #0000DD;">As</span> <span style="color: #0000DD;">Long</span><br />
&nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #0000DD;">Dim</span> j&nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #0000DD;">As</span> <span style="color: #0000DD;">Long</span><br />
&nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #0000DD;">Dim</span> Answer&nbsp; <span style="color: #0000DD;">As</span> <span style="color: #0000DD;">Long</span><br />
&nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #0000DD;">Dim</span> M1&nbsp; &nbsp; &nbsp; <span style="color: #0000DD;">As</span> <span style="color: #0000DD;">String</span><br />
&nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #0000DD;">Dim</span> M2&nbsp; &nbsp; &nbsp; <span style="color: #0000DD;">As</span> <span style="color: #0000DD;">String</span><br />
&nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #0000DD;">Dim</span> T&nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #0000DD;">As</span> <span style="color: #0000DD;">Single</span><br />
&nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #0000DD;">Dim</span> IsTest&nbsp; <span style="color: #0000DD;">As</span> <span style="color: #0000DD;">Boolean</span><br />
&nbsp;<br />
&nbsp; &nbsp; &nbsp; &nbsp;T = <span style="color: #0000DD;">Timer</span>&nbsp; &nbsp;<span style="color: #007F00;">'starts timing&nbsp; &nbsp; &nbsp;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp;IsTest = False<br />
&nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #0000DD;">If</span> IsTest <span style="color: #0000DD;">Then</span>&nbsp; <span style="color: #007F00;">'to reproduce the test case</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #0000DD;">exp</span> = <span style="color: #cc66cc;">15</span><br />
&nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #0000DD;">Else</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #0000DD;">exp</span> = <span style="color: #cc66cc;">1000</span><br />
&nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #0000DD;">End</span> <span style="color: #0000DD;">If</span><br />
&nbsp;<br />
&nbsp; &nbsp; &nbsp; &nbsp;M1 = <span style="color: #ff0000;">"2"</span><br />
&nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #0000DD;">For</span> i = <span style="color: #cc66cc;">2</span> <span style="color: #0000DD;">To</span> <span style="color: #0000DD;">exp</span> <span style="color: #007F00;">'calculates 2^exp</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; M2 = AddAsStrings<span style="color:#008800;">&#40;</span>M1, M1<span style="color:#008800;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; M1 = M2<br />
&nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #0000DD;">Next</span> i<br />
&nbsp;<br />
&nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #0000DD;">For</span> i = <span style="color: #cc66cc;">1</span> <span style="color: #0000DD;">To</span> <span style="color: #0000DD;">Len</span><span style="color:#008800;">&#40;</span>M2<span style="color:#008800;">&#41;</span> <span style="color: #007F00;">'loops the length of 2^exp to sum digits</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Answer = Answer + <span style="color: #0000DD;">CLng</span><span style="color:#008800;">&#40;</span><span style="color: #0000DD;">Mid</span><span style="color:#008800;">&#40;</span>M2, i, <span style="color: #cc66cc;">1</span><span style="color:#008800;">&#41;</span><span style="color:#008800;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #0000DD;">Next</span> i<br />
&nbsp;<br />
&nbsp; &nbsp; &nbsp; <span style="color: #0000DD;">Debug</span>.<span style="color: #0000DD;">Print</span> Answer; <span style="color: #ff0000;">"&nbsp; Time:"</span>; <span style="color: #0000DD;">Timer</span> - T; M2<br />
&nbsp;<br />
<span style="color: #0000DD;">End</span> <span style="color: #0000DD;">Sub</span></div>
</div>
</div>
<p></p>
<p>And by the way, 2^1000 is precisely:<br />
10715086071862673209484250490600018105614048117055336074437503883703510<br />
51124936122493198378815695858127594672917553146825187145285692314043598<br />
45775746985748039345677748242309854210746050623711418779541821530464749<br />
83581941267398767559165543946077062914571196477686542167660429831652624<br />
386837205668069376</p>
<p>The key part is the AddAsStrings() function.  It does addition the way you learned it--starting from the right and carrying to columns on the left.  </p>
<div class="syntax_hilite">
<div id="vb-34">
<div class="vb"><span style="color: #0000DD;">Function</span> AddAsStrings<span style="color:#008800;">&#40;</span>Adder1 <span style="color: #0000DD;">As</span> <span style="color: #0000DD;">String</span>, Adder2 <span style="color: #0000DD;">As</span> <span style="color: #0000DD;">String</span><span style="color:#008800;">&#41;</span> <span style="color: #0000DD;">As</span> <span style="color: #0000DD;">String</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br />
&nbsp; &nbsp; <span style="color: #0000DD;">Dim</span> <span style="color: #0000DD;">Sum</span>&nbsp; &nbsp; &nbsp;<span style="color: #0000DD;">As</span> <span style="color: #0000DD;">Long</span><br />
&nbsp; &nbsp; <span style="color: #0000DD;">Dim</span> Carry&nbsp; &nbsp;<span style="color: #0000DD;">As</span> <span style="color: #0000DD;">Long</span><br />
&nbsp; &nbsp; <span style="color: #0000DD;">Dim</span> C&nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #0000DD;">As</span> <span style="color: #0000DD;">Long</span><br />
&nbsp; &nbsp; <span style="color: #0000DD;">Dim</span> Answer&nbsp; <span style="color: #0000DD;">As</span> <span style="color: #0000DD;">String</span><br />
&nbsp;<br />
&nbsp; &nbsp; <span style="color: #0000DD;">If</span> <span style="color: #0000DD;">Len</span><span style="color:#008800;">&#40;</span>Adder1<span style="color:#008800;">&#41;</span>&gt; <span style="color: #0000DD;">Len</span><span style="color:#008800;">&#40;</span>Adder2<span style="color:#008800;">&#41;</span> <span style="color: #0000DD;">Then</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #0000DD;">For</span> C = <span style="color: #cc66cc;">1</span> <span style="color: #0000DD;">To</span> <span style="color: #0000DD;">Len</span><span style="color:#008800;">&#40;</span>Adder1<span style="color:#008800;">&#41;</span> - <span style="color: #0000DD;">Len</span><span style="color:#008800;">&#40;</span>Adder2<span style="color:#008800;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Adder2 = <span style="color: #ff0000;">"0"</span> &amp;amp; Adder2<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #0000DD;">Next</span> C<br />
&nbsp; &nbsp; <span style="color: #0000DD;">ElseIf</span> <span style="color: #0000DD;">Len</span><span style="color:#008800;">&#40;</span>Adder2<span style="color:#008800;">&#41;</span>&gt; <span style="color: #0000DD;">Len</span><span style="color:#008800;">&#40;</span>Adder1<span style="color:#008800;">&#41;</span> <span style="color: #0000DD;">Then</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #0000DD;">For</span> C = <span style="color: #cc66cc;">1</span> <span style="color: #0000DD;">To</span> <span style="color: #0000DD;">Len</span><span style="color:#008800;">&#40;</span>Adder2<span style="color:#008800;">&#41;</span> - <span style="color: #0000DD;">Len</span><span style="color:#008800;">&#40;</span>Adder1<span style="color:#008800;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Adder1 = <span style="color: #ff0000;">"0"</span> &amp; Adder1<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #0000DD;">Next</span> C<br />
&nbsp; &nbsp; <span style="color: #0000DD;">End</span> <span style="color: #0000DD;">If</span><br />
&nbsp;<br />
&nbsp; &nbsp; <span style="color: #0000DD;">For</span> C = <span style="color: #0000DD;">Len</span><span style="color:#008800;">&#40;</span>Adder1<span style="color:#008800;">&#41;</span> <span style="color: #0000DD;">To</span> <span style="color: #cc66cc;">1</span> <span style="color: #0000DD;">Step</span> -<span style="color: #cc66cc;">1</span>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000DD;">Sum</span> = Carry + <span style="color: #0000DD;">CLng</span><span style="color:#008800;">&#40;</span><span style="color: #0000DD;">Mid</span><span style="color:#008800;">&#40;</span>Adder1, C, <span style="color: #cc66cc;">1</span><span style="color:#008800;">&#41;</span><span style="color:#008800;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000DD;">Sum</span> = <span style="color: #0000DD;">Sum</span> + <span style="color: #0000DD;">CLng</span><span style="color:#008800;">&#40;</span><span style="color: #0000DD;">Mid</span><span style="color:#008800;">&#40;</span>Adder2, C, <span style="color: #cc66cc;">1</span><span style="color:#008800;">&#41;</span><span style="color:#008800;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Carry = <span style="color: #0000DD;">Int</span><span style="color:#008800;">&#40;</span><span style="color: #0000DD;">Sum</span> / <span style="color: #cc66cc;">10</span><span style="color:#008800;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000DD;">If</span> C&nbsp; &lt;&gt; <span style="color: #cc66cc;">1</span> <span style="color: #0000DD;">Then</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Answer = <span style="color: #0000DD;">CStr</span><span style="color:#008800;">&#40;</span><span style="color: #0000DD;">Sum</span> Mod <span style="color: #cc66cc;">10</span><span style="color:#008800;">&#41;</span> &amp; Answer<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000DD;">Else</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Answer = <span style="color: #0000DD;">CStr</span><span style="color:#008800;">&#40;</span><span style="color: #0000DD;">Sum</span><span style="color:#008800;">&#41;</span> &amp; Answer<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000DD;">End</span> <span style="color: #0000DD;">If</span><br />
&nbsp; &nbsp; <span style="color: #0000DD;">Next</span> C<br />
&nbsp;<br />
&nbsp; &nbsp; AddAsStrings = Answer<br />
&nbsp;<br />
<span style="color: #0000DD;">End</span> <span style="color: #0000DD;">Function</span></div>
</div>
</div>
<p></p>
<p>AddAsStrings() does well on Fibonacci numbers, simple multiplication (including squaring), and factorials.  It doesn't do as well on cubes and higher powers.  It becomes loops inside loops.  It works on powers of 2 because all we do is double and redouble...</p>
<p>You've seen me around here as both Michael and ...mrt.  For whatever it helps, I'm pleased to contribute.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.dailydoseofexcel.com/archives/2008/12/22/euler-problem-16/feed/</wfw:commentRss>
		</item>
		<item>
		<title>New Contributor</title>
		<link>http://www.dailydoseofexcel.com/archives/2008/12/21/new-contributor/</link>
		<comments>http://www.dailydoseofexcel.com/archives/2008/12/21/new-contributor/#comments</comments>
		<pubDate>Sun, 21 Dec 2008 20:30:30 +0000</pubDate>
		<dc:creator>Dick Kusleika</dc:creator>
		
		<category><![CDATA[General]]></category>

		<guid isPermaLink="false">http://www.dailydoseofexcel.com/archives/2008/12/21/new-contributor/</guid>
		<description><![CDATA[Long time reader Michael Tollefson has been messing around with Project Euler.  He has graciously offered to post some of his exploits here.  Expect some posts from Michael soon.
]]></description>
			<content:encoded><![CDATA[<p>Long time reader Michael Tollefson has been messing around with <a href="http://projecteuler.net/">Project Euler</a>.  He has graciously offered to post some of his exploits here.  Expect some posts from Michael soon.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.dailydoseofexcel.com/archives/2008/12/21/new-contributor/feed/</wfw:commentRss>
		</item>
		<item>
		<title>VBA Framework II</title>
		<link>http://www.dailydoseofexcel.com/archives/2008/12/21/vba-framework-ii/</link>
		<comments>http://www.dailydoseofexcel.com/archives/2008/12/21/vba-framework-ii/#comments</comments>
		<pubDate>Sun, 21 Dec 2008 20:27:09 +0000</pubDate>
		<dc:creator>Dick Kusleika</dc:creator>
		
		<category><![CDATA[Visual Basic Editor]]></category>

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

		<guid isPermaLink="false">http://www.dailydoseofexcel.com/archives/2008/12/21/vba-framework-ii/</guid>
		<description><![CDATA[See VBA Framework for the first revision.
For this revision, you can select which VBProject in which to add the code and you can identify a parent class.

I refactored the code to use a class module to make the code more readable.  Concatenating strings is always messy, so I hope this helps a little.  [...]]]></description>
			<content:encoded><![CDATA[<p>See <a href="http://www.dailydoseofexcel.com/archives/2008/12/07/vba-framework/">VBA Framework</a> for the first revision.</p>
<p>For this revision, you can select which VBProject in which to add the code and you can identify a parent class.</p>
<p><img src="http://www.dailydoseofexcel.com/blogpix/vbaframe2.gif" height="507" width="347" alt="" /></p>
<p>I refactored the code to use a class module to make the code more readable.  Concatenating strings is always messy, so I hope this helps a little.  I made a property for every variation of the class name I'd need.  Here are some examples using the Paycheck class:</p>
<table>
<tr>
<td>CSingular</td>
<td>CPaycheck</td>
</tr>
<tr>
<td>clsSingular</td>
<td>clsPaycheck</td>
</tr>
<tr>
<td>mcolPlural</td>
<td>mcolPaychecks</td>
</tr>
<tr>
<td>ParentName</td>
<td>Employee</td>
</tr>
<tr>
<td>CParentName</td>
<td>CEmployee</td>
</tr>
<tr>
<td>tblPlural</td>
<td>tblPaychecks</td>
</tr>
</table>
<p></p>
<p>I couldn't identify the name of an unsaved workbook given the VBProject, so I used this code to fill the project combobox:</p>
<div class="syntax_hilite">
<div id="vb-37">
<div class="vb"><span style="color: #0000DD;">For</span> <span style="color: #0000DD;">Each</span> vbProj <span style="color: #0000DD;">In</span> Application.VBE.VBProjects<br />
&nbsp; &nbsp; sWbName = <span style="color: #ff0000;">""</span><br />
&nbsp; &nbsp; lProjCnt = lProjCnt + <span style="color: #cc66cc;">1</span><br />
&nbsp; &nbsp; <span style="color: #0000DD;">If</span> vbProj.Protection = vbext_pp_none <span style="color: #0000DD;">Then</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000DD;">Me</span>.cbxProject.AddItem vbProj.<span style="color: #0000DD;">Name</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000DD;">On</span> <span style="color: #0000DD;">Error</span> <span style="color: #0000DD;">Resume</span> <span style="color: #0000DD;">Next</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; sWbName = <span style="color: #0000DD;">Dir</span><span style="color:#008800;">&#40;</span>vbProj.Filename<span style="color:#008800;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000DD;">On</span> <span style="color: #0000DD;">Error</span> <span style="color: #0000DD;">GoTo</span> <span style="color: #cc66cc;">0</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000DD;">If</span> <span style="color: #0000DD;">Len</span><span style="color:#008800;">&#40;</span>sWbName<span style="color:#008800;">&#41;</span> = <span style="color: #cc66cc;">0</span> <span style="color: #0000DD;">Then</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000DD;">Me</span>.cbxProject.List<span style="color:#008800;">&#40;</span><span style="color: #0000DD;">Me</span>.cbxProject.ListCount - <span style="color: #cc66cc;">1</span>, <span style="color: #cc66cc;">1</span><span style="color:#008800;">&#41;</span> = <span style="color: #ff0000;">"(Unsaved Workbook)"</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000DD;">Else</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000DD;">Me</span>.cbxProject.List<span style="color:#008800;">&#40;</span><span style="color: #0000DD;">Me</span>.cbxProject.ListCount - <span style="color: #cc66cc;">1</span>, <span style="color: #cc66cc;">1</span><span style="color:#008800;">&#41;</span> = sWbName<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000DD;">End</span> <span style="color: #0000DD;">If</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000DD;">Me</span>.cbxProject.List<span style="color:#008800;">&#40;</span><span style="color: #0000DD;">Me</span>.cbxProject.ListCount - <span style="color: #cc66cc;">1</span>, <span style="color: #cc66cc;">2</span><span style="color:#008800;">&#41;</span> = lProjCnt<br />
&nbsp; &nbsp; <span style="color: #0000DD;">End</span> <span style="color: #0000DD;">If</span><br />
&nbsp; &nbsp; <br />
<span style="color: #0000DD;">Next</span> vbProj</div>
</div>
</div>
<p></p>
<p>I just identify "Unsaved Workbook" if there is not a Filename property.  I only list projects that aren't protected to avoid errors writing to protected projects.  If there are existing classes in the project, I fill the Parent combobox thusly:</p>
<div class="syntax_hilite">
<div id="vb-38">
<div class="vb"><span style="color: #0000DD;">Private</span> <span style="color: #0000DD;">Sub</span> cbxProject_AfterUpdate<span style="color:#008800;">&#40;</span><span style="color:#008800;">&#41;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #0000DD;">Dim</span> vbc <span style="color: #0000DD;">As</span> VBComponent<br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #0000DD;">Me</span>.cbxParent.Clear<br />
&nbsp; &nbsp; <span style="color: #0000DD;">Me</span>.cbxParent.AddItem gsNOPARENT<br />
&nbsp; &nbsp; <span style="color: #0000DD;">Me</span>.cbxParent.ListIndex = <span style="color: #cc66cc;">0</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #0000DD;">If</span> <span style="color: #0000DD;">Me</span>.cbxProject.ListIndex&gt; -<span style="color: #cc66cc;">1</span> <span style="color: #0000DD;">Then</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000DD;">If</span> mclsClass <span style="color: #0000DD;">Is</span> <span style="color: #0000DD;">Nothing</span> <span style="color: #0000DD;">Then</span> <span style="color: #0000DD;">Set</span> mclsClass = <span style="color: #0000DD;">New</span> CClass<br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000DD;">Set</span> mclsClass.Project = Application.VBE.VBProjects<span style="color:#008800;">&#40;</span><span style="color: #0000DD;">Val</span><span style="color:#008800;">&#40;</span><span style="color: #0000DD;">Me</span>.cbxProject.List<span style="color:#008800;">&#40;</span><span style="color: #0000DD;">Me</span>.cbxProject.ListIndex, <span style="color: #cc66cc;">2</span><span style="color:#008800;">&#41;</span><span style="color:#008800;">&#41;</span><span style="color:#008800;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000DD;">For</span> <span style="color: #0000DD;">Each</span> vbc <span style="color: #0000DD;">In</span> mclsClass.Project.VBComponents<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000DD;">If</span> vbc.<span style="color: #0000DD;">Type</span> = vbext_ct_ClassModule <span style="color: #0000DD;">Then</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000DD;">Me</span>.cbxParent.AddItem vbc.<span style="color: #0000DD;">Name</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000DD;">End</span> <span style="color: #0000DD;">If</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000DD;">Next</span> vbc<br />
&nbsp; &nbsp; <span style="color: #0000DD;">End</span> <span style="color: #0000DD;">If</span><br />
&nbsp; &nbsp; <br />
<span style="color: #0000DD;">End</span> <span style="color: #0000DD;">Sub</span></div>
</div>
</div>
<p></p>
<p>I'd like to only include the singular versions of the classes, but I haven't gotten there yet.  I imagine there are a lot of ways to relate classes, but I only code for one.  Using the example mdb, there are a number of Employees stored in a global Collection variable.  Each Employee instance has a Paychecks property which retrieves a CPaychecks collecton class.  This holds CPaycheck objects that only relate to the Employee.</p>
<p><a href="http://www.dailydoseofexcel.com/excel/VBAFramework2.zip">Download VBAFramework2.zip</a></p>
<p>Still on the to do list:</p>
<ul>
<li>Browse to mdb instead of hardcoded</li>
<li>Create a userform to add/edit/delete records</li>
<li>Automatically set an ADO reference</li>
<li>Option to make functions instead of subs (for error handling)</li>
<li>Allow recreation of the classes and fill code</li>
<li>Option to make properties read-only</li>
<li>Your suggestions</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.dailydoseofexcel.com/archives/2008/12/21/vba-framework-ii/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Bowl Picking</title>
		<link>http://www.dailydoseofexcel.com/archives/2008/12/19/bowl-picking/</link>
		<comments>http://www.dailydoseofexcel.com/archives/2008/12/19/bowl-picking/#comments</comments>
		<pubDate>Fri, 19 Dec 2008 19:40:05 +0000</pubDate>
		<dc:creator>Dick Kusleika</dc:creator>
		
		<category><![CDATA[Formatting Cells]]></category>

		<category><![CDATA[List and Table Functions]]></category>

		<guid isPermaLink="false">http://www.dailydoseofexcel.com/archives/2008/12/19/bowl-picking/</guid>
		<description><![CDATA[It's college football bowl season once again.  I have a spreadsheet I use to help me identify winners and losers (for entertainment purposes only).

The four yardage columns are yards per game for rushing offense, rushing defense, passing offense, and passing defense, respectively.  I'm trying to identify teams that have better defenses (because defense [...]]]></description>
			<content:encoded><![CDATA[<p>It's college football bowl season once again.  I have a spreadsheet I use to help me identify winners and losers (for entertainment purposes only).</p>
<p><img src="http://www.dailydoseofexcel.com/blogpix/bowlstats2008.gif" height="237" width="814" alt="" /></p>
<p>The four yardage columns are yards per game for rushing offense, rushing defense, passing offense, and passing defense, respectively.  I'm trying to identify teams that have better defenses (because defense wins championships).  While Wisconsin is rushing for 212 yards per game this season, Florida State is only allowing their opponents to rush for 127 yards per game.  This, to me, is an advantage for Florida State.</p>
<p>California is +14 in turnovers, taking possession from their opponents more often than they give it away.  That's turnover margin for the season, not per game.  Miami, on the other hand, can't seem to hang on to the ball.  It seems that Cal should get at least one turnover in their bowl game.</p>
<p>The Bowl Wins ratio is bowl games won to bowl games played.  Western Michigan (not shown) has won zero bowl games in four attempts.  Are they due for a win?  Probably not.  It's more likely that their coach doesn't prepare them well for bowl games.</p>
<p>Columns R &#038; S are thresholds.  If the disparity between rushing offense and defense is more than 75 yards per game, I think that's significant and I want to know about it.  If a team has won more than 65% of their games or less than 35%, I want to know.  But I can change those values if I like.</p>
<p>The hidden columns J:O are used in the conditional formatting of the other columns.  They are:</p>
<p>J: =MOD(ROW(),2)=1 'Tells me if I'm comparing the team above or below<br />
K: =IF(J2,D2-E1,D2-E3) 'Rushing offense differential<br />
L: =IF(J2,E2-D1,E2-D3) 'Rushing defense differential<br />
M: =IF(J2,F2-G1,F2-G3) 'Passing offense differential<br />
N: =IF(J2,G2-F1,G2-F3) 'Passing defense differential<br />
O: =IF(MOD(ROW(),2)=1,H2-H1,H2-H3) 'turnover differential<br />
P: =VLOOKUP(B2,Bowls!$A$1:$F$119,2,FALSE)/VLOOKUP(B2,Bowls!$A$1:$F$119,5,FALSE) 'bowl winning percentage</p>
<p>These formulas drive the conditional formatting in D:I.  The conditional formats all look something like this:</p>
<p><img src="http://www.dailydoseofexcel.com/blogpix/bowlstats2008cf.gif" height="169" width="542" alt="" /></p>
<p>You can <a href="http://www.dailydoseofexcel.com/excel/BowlStats2008.xls.zip">download BowlStats2008.xls.zip</a></p>
<p>So if you want to go .500 like me, now you have the tools.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.dailydoseofexcel.com/archives/2008/12/19/bowl-picking/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Create Unique List from Selected Cells</title>
		<link>http://www.dailydoseofexcel.com/archives/2008/12/11/create-unique-list-from-selected-cells/</link>
		<comments>http://www.dailydoseofexcel.com/archives/2008/12/11/create-unique-list-from-selected-cells/#comments</comments>
		<pubDate>Thu, 11 Dec 2008 23:13:36 +0000</pubDate>
		<dc:creator>Dick Kusleika</dc:creator>
		
		<category><![CDATA[Collections]]></category>

		<guid isPermaLink="false">http://www.dailydoseofexcel.com/archives/2008/12/11/create-unique-list-from-selected-cells/</guid>
		<description><![CDATA[Well, it's almost next year and you know what that means: New vendor files.  I need to create a couple hundred labels for next year's vendor files.  I started by exporting all of the bills from all of the vendors for this year.  Next, I'm going to count and sum the bills. [...]]]></description>
			<content:encoded><![CDATA[<p>Well, it's almost next year and you know what that means: New vendor files.  I need to create a couple hundred labels for next year's vendor files.  I started by exporting all of the bills from all of the vendors for this year.  Next, I'm going to count and sum the bills.  Then I'm going to find the newest invoice date.  With that, I should be able to weed out vendors we likely won't pay next year and those whose invoices are so few that they go in the Misc. folder.</p>
<p>But I need to start with a list of all the vendors who had bills.  I'm so sick of creating unique lists with formulas, that I finally just wrote a utility to do it.</p>
<p>Recently added to my Personal.xls</p>
<div class="syntax_hilite">
<div id="vb-40">
<div class="vb"><span style="color: #0000DD;">Sub</span> GetUniqueList<span style="color:#008800;">&#40;</span><span style="color:#008800;">&#41;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #0000DD;">Dim</span> rCell <span style="color: #0000DD;">As</span> Range<br />
&nbsp; &nbsp; <span style="color: #0000DD;">Dim</span> colUnique <span style="color: #0000DD;">As</span> Collection<br />
&nbsp; &nbsp; <span style="color: #0000DD;">Dim</span> sh <span style="color: #0000DD;">As</span> Worksheet<br />
&nbsp; &nbsp; <span style="color: #0000DD;">Dim</span> i <span style="color: #0000DD;">As</span> <span style="color: #0000DD;">Long</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #007F00;">'only work on ranges</span><br />
&nbsp; &nbsp; <span style="color: #0000DD;">If</span> <span style="color: #0000DD;">TypeName</span><span style="color:#008800;">&#40;</span>Selection<span style="color:#008800;">&#41;</span> = <span style="color: #ff0000;">"Range"</span> <span style="color: #0000DD;">Then</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #007F00;">'create a new collection</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000DD;">Set</span> colUnique = <span style="color: #0000DD;">New</span> Collection<br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #007F00;">'loop through all selected cells</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #007F00;">'and add to collection</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000DD;">For</span> <span style="color: #0000DD;">Each</span> rCell <span style="color: #0000DD;">In</span> Selection.Cells<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000DD;">On</span> <span style="color: #0000DD;">Error</span> <span style="color: #0000DD;">Resume</span> <span style="color: #0000DD;">Next</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #007F00;">'if value exists, it won't be added</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; colUnique.Add rCell.Value, <span style="color: #0000DD;">CStr</span><span style="color:#008800;">&#40;</span>rCell.Value<span style="color:#008800;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000DD;">On</span> <span style="color: #0000DD;">Error</span> <span style="color: #0000DD;">GoTo</span> <span style="color: #cc66cc;">0</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000DD;">Next</span> rCell<br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #007F00;">'make a new sheet to put the unique list</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000DD;">Set</span> sh = ActiveWorkbook.Worksheets.Add<br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #007F00;">'Write the unique list to the new sheet</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000DD;">For</span> i = <span style="color: #cc66cc;">1</span> <span style="color: #0000DD;">To</span> colUnique.<span style="color: #0000DD;">Count</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; sh.Range<span style="color:#008800;">&#40;</span><span style="color: #ff0000;">"A1"</span><span style="color:#008800;">&#41;</span>.Offset<span style="color:#008800;">&#40;</span>i, <span style="color: #cc66cc;">0</span><span style="color:#008800;">&#41;</span>.Value = colUnique<span style="color:#008800;">&#40;</span>i<span style="color:#008800;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000DD;">Next</span> i<br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #007F00;">'sort with no headers</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; sh.Range<span style="color:#008800;">&#40;</span>sh.Range<span style="color:#008800;">&#40;</span><span style="color: #ff0000;">"A2"</span><span style="color:#008800;">&#41;</span>, sh.Range<span style="color:#008800;">&#40;</span><span style="color: #ff0000;">"A2"</span><span style="color:#008800;">&#41;</span>.<span style="color: #0000DD;">End</span><span style="color:#008800;">&#40;</span>xlDown<span style="color:#008800;">&#41;</span><span style="color:#008800;">&#41;</span> _<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; .Sort sh.Range<span style="color:#008800;">&#40;</span><span style="color: #ff0000;">"A2"</span><span style="color:#008800;">&#41;</span>, xlAscending, , , , , , xlNo<br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #0000DD;">End</span> <span style="color: #0000DD;">If</span><br />
&nbsp; &nbsp; <br />
<span style="color: #0000DD;">End</span> <span style="color: #0000DD;">Sub</span></div>
</div>
</div>
<p></p>
]]></content:encoded>
			<wfw:commentRss>http://www.dailydoseofexcel.com/archives/2008/12/11/create-unique-list-from-selected-cells/feed/</wfw:commentRss>
		</item>
		<item>
		<title>VBA Framework</title>
		<link>http://www.dailydoseofexcel.com/archives/2008/12/07/vba-framework/</link>
		<comments>http://www.dailydoseofexcel.com/archives/2008/12/07/vba-framework/#comments</comments>
		<pubDate>Mon, 08 Dec 2008 01:49:00 +0000</pubDate>
		<dc:creator>Dick Kusleika</dc:creator>
		
		<category><![CDATA[Visual Basic Editor]]></category>

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

		<guid isPermaLink="false">http://www.dailydoseofexcel.com/archives/2008/12/07/vba-framework/</guid>
		<description><![CDATA[In Create Classes... I had this todo list:

Create the class module rather than copy and paste
Name the class module based on the table name
Select the database and table from a list on a userform
Establish Parent Child relationships between two classes
Create functions to fill the class from a recordset
Create a userform to add/edit/delete records

I need to [...]]]></description>
			<content:encoded><![CDATA[<p>In <a href="http://www.dailydoseofexcel.com/archives/2008/11/15/creating-classes-from-access-tables/">Create Classes...</a> I had this todo list:</p>
<ul>
<li><strike>Create the class module rather than copy and paste</strike></li>
<li><strike>Name the class module based on the table name</strike></li>
<li><strike>Select the database and table from a list on a userform</strike></li>
<li><strike>Establish Parent Child relationships between two classes</strike></li>
<li><strike>Create functions to fill the class from a recordset</strike></li>
<li>Create a userform to add/edit/delete records</li>
</ul>
<p>I need to add</p>
<ul>
<li>Create relationships between two child classes</li>
<li>Automatically set an ADO reference</li>
<li>Option to make functions instead of subs (for error handling)</li>
<li>Allow recreation of the classes and fill code</li>
</ul>
<p>You can <a href="http://www.dailydoseofexcel.com/excel/Payroll.zip">Download Payroll.zip</a>.  It contains the VBAFramework.xls workbook and a Payroll.mdb Access database.</p>
<p>Here's where it all starts</p>
<div class="syntax_hilite">
<div id="vb-42">
<div class="vb"><span style="color: #0000DD;">Public</span> <span style="color: #0000DD;">Sub</span> PickTable<span style="color:#008800;">&#40;</span><span style="color:#008800;">&#41;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #0000DD;">Dim</span> axCat <span style="color: #0000DD;">As</span> ADOX.Catalog<br />
&nbsp; &nbsp; <span style="color: #0000DD;">Dim</span> ufSelect <span style="color: #0000DD;">As</span> USelectTable<br />
&nbsp; &nbsp; <span style="color: #0000DD;">Dim</span> vaSelected <span style="color: #0000DD;">As</span> <span style="color: #0000DD;">Variant</span><br />
&nbsp; &nbsp; <span style="color: #0000DD;">Dim</span> axTable <span style="color: #0000DD;">As</span> ADOX.Table<br />
&nbsp; &nbsp; <span style="color: #0000DD;">Dim</span> i <span style="color: #0000DD;">As</span> <span style="color: #0000DD;">Long</span><br />
&nbsp; &nbsp; <span style="color: #0000DD;">Dim</span> sChildCode <span style="color: #0000DD;">As</span> <span style="color: #0000DD;">String</span>, sParentCode <span style="color: #0000DD;">As</span> <span style="color: #0000DD;">String</span><br />
&nbsp; &nbsp; <span style="color: #0000DD;">Dim</span> sFillCode <span style="color: #0000DD;">As</span> <span style="color: #0000DD;">String</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; InitializeConnection<br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #0000DD;">Set</span> axCat = <span style="color: #0000DD;">New</span> ADOX.Catalog<br />
&nbsp; &nbsp; <span style="color: #0000DD;">Set</span> axCat.ActiveConnection = gadCon<br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #0000DD;">Set</span> ufSelect = <span style="color: #0000DD;">New</span> USelectTable<br />
&nbsp; &nbsp; <span style="color: #0000DD;">Set</span> ufSelect.Catalog = axCat<br />
&nbsp; &nbsp; ufSelect.Initialize<br />
&nbsp; &nbsp; ufSelect.Show<br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #0000DD;">If</span> <span style="color: #0000DD;">Not</span> ufSelect.UserCancel <span style="color: #0000DD;">Then</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; vaSelected = ufSelect.SelectedFields<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000DD;">Set</span> axTable = ufSelect.Table<br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000DD;">If</span> ActiveWorkbook.<span style="color: #0000DD;">Name</span> = ThisWorkbook.<span style="color: #0000DD;">Name</span> <span style="color: #0000DD;">Then</span> Workbooks.Add<br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; ChildClassCode axTable, vaSelected, sChildCode<br />
&nbsp; &nbsp; &nbsp; &nbsp; MakeChildClass axTable, sChildCode<br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; ParentClassCode axTable, sParentCode<br />
&nbsp; &nbsp; &nbsp; &nbsp; MakeParentClass axTable, sParentCode<br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; FillClassesCode axTable, vaSelected, sFillCode<br />
&nbsp; &nbsp; &nbsp; &nbsp; MakeFillModule axTable, sFillCode<br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #0000DD;">End</span> <span style="color: #0000DD;">If</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #0000DD;">Set</span> axCat = <span style="color: #0000DD;">Nothing</span><br />
&nbsp; &nbsp; <span style="color: #0000DD;">Unload</span> ufSelect<br />
&nbsp; &nbsp; <span style="color: #0000DD;">Set</span> ufSelect = <span style="color: #0000DD;">Nothing</span><br />
&nbsp; &nbsp; <br />
<span style="color: #0000DD;">End</span> <span style="color: #0000DD;">Sub</span></div>
</div>
</div>
<p></p>
<p>Most of the code is bunch of string concatenation, which is pretty boring.  But not as boring as actually typing the code.  When you run PickTable, you get</p>
<p><img src="http://www.dailydoseofexcel.com/blogpix/vbaframeselect.gif" height="403" width="347" alt="" /></p>
<p>It allows you to select a table and fields to include in your classes.  The code creates a class based on the field and a collection class to serve as its parent.  Then it creates (or modifies an existing) standard module that holds code to fill the classes.</p>
<p>There's no customization options (it's in pre-Beta).  But if you happen to use the same conventions as me, it will work perfectly.  First, it assumes you name your Access tables as plural and your classes exactly the same way (but singular for the child class).  It assumes you have an ID field that is SingularTableNameID, so tblEmployees will have an EmployeeID field.  That one is used to uniquely identify the record in the collection class, so it's important.  I should probably not allow the user to deselect that one in the listbox.  Oh yeah, it also assumes you prefix your tables with "tbl".  Everyone does that, right?</p>
<p>I imagine I'll add some customization options as I go so it's useful to more than just me.  So if there's a convention that's near and dear to your heart, leave a comment.  But I don't plan on making it fully customizable.  I'm going the Ruby on Rails route of "this will work as long as you do it just like me".</p>
<p>Let me know what you think.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.dailydoseofexcel.com/archives/2008/12/07/vba-framework/feed/</wfw:commentRss>
		</item>
		<item>
		<title>UK Excel User Conference</title>
		<link>http://www.dailydoseofexcel.com/archives/2008/12/06/uk-excel-user-group-conference/</link>
		<comments>http://www.dailydoseofexcel.com/archives/2008/12/06/uk-excel-user-group-conference/#comments</comments>
		<pubDate>Sat, 06 Dec 2008 07:40:37 +0000</pubDate>
		<dc:creator>Nick Hodge</dc:creator>
		
		<category><![CDATA[MVP]]></category>

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

		<guid isPermaLink="false">http://www.dailydoseofexcel.com/archives/2008/12/06/uk-excel-user-group-conference/</guid>
		<description><![CDATA[A meeting of the above group will take place on Wednesday 1st and Thursday 2nd April 2009 in London. This FREE event has some fantastic speakers from the Excel community.
The agenda for the two days is outlined below and you can book for either or both days by emailing bookings@excelusergroup.org.
Microsoft will be providing the venue [...]]]></description>
			<content:encoded><![CDATA[<p>A meeting of the above group will take place on <strong>Wednesday 1st and Thursday 2nd April 2009 in London</strong>. This <font color="#ff0000"><strong><u>FREE</u></strong></font><font color="#000000"> event has some fantastic speakers from the Excel community.</font></p>
<p><font color="#000000">The agenda for the two days is outlined below and you can book for either or both days by emailing <a href="mailto:bookings@excelusergroup.org">bookings@excelusergroup.org</a>.</font></p>
<p><font color="#000000">Microsoft will be providing the venue and the hospitality and we look forward to a great and informative couple of days. The agenda is below, but if you want the full version with session details and speaker bios, <a title="EUG UK Meeting Agenda" href="http://www.dailydoseofexcel.com/blogpix/uk-excel-user-group-meeting-rev2.doc">it can be downloaded here.</a>.</font></p>
<p><b>Venue:      <br /></b><b>Microsoft London (Cardinal Place)</b>     <br />100 Victoria Street     <br />London SW1E 5JL     <br />Tel: 0870 60 10 100</p>
<p>Agenda:</p>
<p><strong>Wednesday 1st April 2009</strong></p>
<table cellspacing="0" cellpadding="1" width="500" border="1">
<tbody>
<tr>
<td valign="top" width="166"><strong>Time</strong></td>
<td valign="top" width="166"><strong>Event</strong></td>
<td valign="top" width="166"><strong>Speaker</strong></td>
</tr>
<tr>
<td valign="top" width="166">9:15am - 9:45am</td>
<td valign="top" width="166">Registration &amp; coffee</td>
<td valign="top" width="166"