Skip to content

Commit

Permalink
Prepare article for publication
Browse files Browse the repository at this point in the history
  • Loading branch information
ploeh committed Dec 23, 2024
1 parent 6e1c9b3 commit cb8839c
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
4 changes: 2 additions & 2 deletions _posts/2024-12-09-implementation-and-usage-mindsets.html
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ <h3 id="f0cbf02e11484e9a8c8d0fab9a6463f2">
Some examples may be in order. In the next two articles, I'll first examine how easy it is to implement an algorithm in various programming languages. Then I'll discuss how to encapsulate that algorithm.
</p>
<ul>
<li>Implementing rod-cutting</li>
<li><a href="/2024/12/23/implementing-rod-cutting">Implementing rod-cutting</a></li>
<li>Encapsulating rod-cutting</li>
</ul>
<p>
Expand All @@ -99,6 +99,6 @@ <h3 id="97b3e722024b4228924faa2d6ff5d188">
This may be used as a heuristic for 'picking the right tool for the job'. If I need to suss out an algorithm, perhaps I should do it in Python. If, on the other hand, I need to publish a reusable library, perhaps Haskell is a better choice.
</p>
<p>
<strong>Next:</strong> Implementing rod-cutting.
<strong>Next:</strong> <a href="/2024/12/23/implementing-rod-cutting">Implementing rod-cutting</a>.
</p>
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
layout: post
title: "Implementing rod-cutting"
description: "From pseudocode to implementation in three languages."
date: 2024-11-25 8:02 UTC
date: 2024-12-23 8:53 UTC
tags: [Code, Languages, F#]
image: "/content/binary/rod-size-7-cut-into-2.png"
image_alt: "Two rods, one of a single segment, and one made from six segments. Above the single segment is the number 1, and above the six segments is the number 17."
Expand All @@ -14,7 +14,7 @@
<em>{{ page.description }}</em>
</p>
<p>
This article picks up where <a href="">Implementation and usage mindsets</a> left off, examining how <a href="https://www.infoq.com/presentations/Simple-Made-Easy/">easy</a> it is to implement an algorithm in three different programming languages.
This article picks up where <a href="/2024/12/09/implementation-and-usage-mindsets">Implementation and usage mindsets</a> left off, examining how <a href="https://www.infoq.com/presentations/Simple-Made-Easy/">easy</a> it is to implement an algorithm in three different programming languages.
</p>
<p>
As an example, I'll use the bottom-up rod-cutting algorithm from <a href="/ref/clrs">Introduction to Algorithms</a>.
Expand Down Expand Up @@ -156,7 +156,7 @@ <h3 id="0a09280df48e48c7b5257346dc98eab3">
</tbody>
</table>
<p>
Such output doesn't really give a <em>solution</em>, but rather the raw data to find a solution. For example, for <code>n = 10</code>, you consult the table for (one-indexed) index <em>10</em>, and see that you can get the revenue <em>30</em> from making a cut at position <em>10</em> (which effectively means no cut). For <code>n = 7</code>, you consult the table for index 7 and observe that you can get the total revenue <em>18</em> by making a cut at position <em>1</em>. This leaves you with two rods, and you again consult the table. For <code>n = 1</code>, you can get the revenue <em>1</em> by making a cut at position <em>1</em>; i.e. no further cut. For <code>n = 7 - 1 = 6</code> you consult the table and observe that you can get the revenue <em>17</em> by making a cut at position <em>6</em>, again indicating that no further cut is necessary.
Such output doesn't really give a <em>solution</em>, but rather the raw data to find a solution. For example, for <code>n = 10</code> (= <em>i</em>), you consult the table for (one-indexed) index <em>10</em>, and see that you can get the revenue <em>30</em> from making a cut at position <em>10</em> (which effectively means no cut). For <code>n = 7</code>, you consult the table for index 7 and observe that you can get the total revenue <em>18</em> by making a cut at position <em>1</em>. This leaves you with two rods, and you again consult the table. For <code>n = 1</code>, you can get the revenue <em>1</em> by making a cut at position <em>1</em>; i.e. no further cut. For <code>n = 7 - 1 = 6</code> you consult the table and observe that you can get the revenue <em>17</em> by making a cut at position <em>6</em>, again indicating that no further cut is necessary.
</p>
<p>
Another procedure prints the solution, using the above process:
Expand All @@ -178,7 +178,7 @@ <h3 id="36447b3aa2a14becbb895fd70fdd9d4a">
Translation to Python <a href="#36447b3aa2a14becbb895fd70fdd9d4a">#</a>
</h3>
<p>
The hypothesis of the <a href="">previous</a> article is that dynamically typed languages may be more suited for implementation tasks. The dynamically typed language that I know best is <a href="https://www.python.org/">Python</a>, so let's try that.
The hypothesis of the <a href="/2024/12/09/implementation-and-usage-mindsets">previous</a> article is that dynamically typed languages may be more suited for implementation tasks. The dynamically typed language that I know best is <a href="https://www.python.org/">Python</a>, so let's try that.
</p>
<p>
<pre><span style="color:blue;">def</span>&nbsp;<span style="color:#2b91af;">cut_rod</span>(p,&nbsp;n):
Expand Down

0 comments on commit cb8839c

Please sign in to comment.