<rss xmlns:atom="http://www.w3.org/2005/Atom" version="2.0">
    <channel>
        <title>练习答案 - 标签 - MartinLwx&#39;s Blog</title>
        <link>https://martinlwx.github.io/zh-cn/tags/%E7%BB%83%E4%B9%A0%E7%AD%94%E6%A1%88/</link>
        <description>练习答案 - 标签 - MartinLwx&#39;s Blog</description>
        <generator>Hugo -- gohugo.io</generator><language>zh-CN</language><managingEditor>martinlwx@163.com (MartinLwx)</managingEditor>
            <webMaster>martinlwx@163.com (MartinLwx)</webMaster><copyright>&lt;a rel=&#34;license noopener&#34; href=&#34;https://creativecommons.org/licenses/by-nc-nd/4.0/&#34; target=&#34;_blank&#34;&gt;CC BY-NC-ND 4.0&lt;/a&gt;</copyright><lastBuildDate>Fri, 21 Apr 2023 10:18:16 &#43;0800</lastBuildDate><atom:link href="https://martinlwx.github.io/zh-cn/tags/%E7%BB%83%E4%B9%A0%E7%AD%94%E6%A1%88/" rel="self" type="application/rss+xml" /><item>
    <title>CS61A 的项目四之 Scheme 解释器实现 (2021-Fall)</title>
    <link>https://martinlwx.github.io/zh-cn/proj4-scheme-interpreter-of-cs61a-of-ucb-fa21/</link>
    <pubDate>Fri, 21 Apr 2023 10:18:16 &#43;0800</pubDate><author>
        <name>MartinLwx</name>
    </author><guid>https://martinlwx.github.io/zh-cn/proj4-scheme-interpreter-of-cs61a-of-ucb-fa21/</guid>
    <description><![CDATA[<h2 id="引言" class="headerLink">
    <a href="#%e5%bc%95%e8%a8%80" class="header-mark"></a>引言</h2><p>最近正在跟着<a href="https://craftinginterpreters.com/" target="_blank" rel="noopener noreferrer">《Crafting interpreter》</a>这本书写解释器，原本书里面用 Java 实现了一个 Tree-walker 解释器 jlox，我正在用 Python 重写一遍，称为 <a href="https://github.com/MartinLwx/pylox" target="_blank" rel="noopener noreferrer">pylox</a>。看了这本书感觉对解释器的理解越来越深刻了，很推荐👍。此时的我突然想起来之前看完的 CS61A 的 Scheme 解释器还有几个小问题没有解决，导致它一直是未完成的状态，于是今天我打开了这个项目，打算从头到尾捋一遍，讲讲思路。</p>]]></description>
</item><item>
    <title>CS61A 的项目三之 Ants vs SomeBees 实现 (2021-Fall)</title>
    <link>https://martinlwx.github.io/zh-cn/proj3.ants-vs-somebees-of-cs61a-of-ucb/</link>
    <pubDate>Thu, 10 Mar 2022 21:43:59 &#43;0800</pubDate><author>
        <name>MartinLwx</name>
    </author><guid>https://martinlwx.github.io/zh-cn/proj3.ants-vs-somebees-of-cs61a-of-ucb/</guid>
    <description><![CDATA[<h2 id="intro" class="headerLink">
    <a href="#intro" class="header-mark"></a>Intro</h2><hr>
<p>前两个项目还算简单, 比较不复杂. 但是今天这个第三个项目难度确实是上升了(看游戏规则就知道这个有多复杂了). 感觉像是植物大战僵尸</p>
<p>所以我打算为他写一篇博客来整理一下写代码时候的思路. 话不多说, 让我们进入正题吧 !</p>]]></description>
</item><item>
    <title>Lab14 题解 (UCB CS61A@2021 Fall)</title>
    <link>https://martinlwx.github.io/zh-cn/lab14-cs61a-of-ucb/</link>
    <pubDate>Thu, 03 Mar 2022 08:17:14 &#43;0800</pubDate><author>
        <name>MartinLwx</name>
    </author><guid>https://martinlwx.github.io/zh-cn/lab14-cs61a-of-ucb/</guid>
    <description><![CDATA[<h2 id="trees" class="headerLink">
    <a href="#trees" class="header-mark"></a>Trees</h2><hr>
<h3 id="q1-prune-min" class="headerLink">
    <a href="#q1-prune-min" class="header-mark"></a>Q1: Prune Min</h3><blockquote>
  <p>Write a function that prunes a <code>Tree</code> <code>t</code> mutatively. <code>t</code> and its branches always have zero or two branches. For the trees with two branches, reduce the number of branches from two to one by keeping the branch that has the smaller label value. Do nothing with trees with zero branches.</p>
<p>Prune the tree in a direction of your choosing (top down or bottom up). The result should be a linear tree.</p>]]></description>
</item><item>
    <title>Hw10 题解 (UCB CS61A@2021 Fall)</title>
    <link>https://martinlwx.github.io/zh-cn/hw10-of-cs61a-of-ucb/</link>
    <pubDate>Wed, 02 Mar 2022 13:36:13 &#43;0800</pubDate><author>
        <name>MartinLwx</name>
    </author><guid>https://martinlwx.github.io/zh-cn/hw10-of-cs61a-of-ucb/</guid>
    <description><![CDATA[<h2 id="bnf" class="headerLink">
    <a href="#bnf" class="header-mark"></a>BNF</h2><hr>
<h3 id="q1-grouping-and-pipes" class="headerLink">
    <a href="#q1-grouping-and-pipes" class="header-mark"></a>Q1: Grouping and Pipes</h3><blockquote>
  <p>In this question, you will add support for grouping and piping.</p>
<p>Recall that grouping allows for an entire regular expression to be treated as a single unit, and piping allows for a pattern to match an expression on either side. Combined, these will let us create patterns which match multiple strings!</p>
<p>Define the <code>group</code> and <code>pipe</code> expressions in your grammar.</p>
<ol>
<li>A <strong><code>group</code></strong> consists of any <code>regex</code> expression surrounded by parentheses (<code>()</code>).</li>
<li>A <strong><code>pipe</code></strong> operator consists of a <code>regex</code> expression, followed by a pipe (<code>|</code>) character, and lastly followed by another <code>regex</code> expression.</li>
</ol>
<p>For example, <code>r&quot;apples&quot;</code> would match exactly the phrase &ldquo;apples&rdquo; in an input. If we wanted our pattern from before to match &ldquo;oranges&rdquo; as well, we could expand our <code>rstring</code> to do so using groupings and pipes: <code>r&quot;(apples)|(oranges)&quot;</code>.</p>]]></description>
</item><item>
    <title>Lab12 题解 (UCB CS61A@2021 Fall)</title>
    <link>https://martinlwx.github.io/zh-cn/lab12-ca61a-of-ucb/</link>
    <pubDate>Wed, 02 Mar 2022 11:15:08 &#43;0800</pubDate><author>
        <name>MartinLwx</name>
    </author><guid>https://martinlwx.github.io/zh-cn/lab12-ca61a-of-ucb/</guid>
    <description><![CDATA[<h2 id="regular-expressions" class="headerLink">
    <a href="#regular-expressions" class="header-mark"></a>Regular Expressions</h2><hr>
<h3 id="q1-calculator-ops" class="headerLink">
    <a href="#q1-calculator-ops" class="header-mark"></a>Q1: Calculator Ops</h3><blockquote>
  <p>Write a regular expression that parses strings written in the 61A Calculator language and returns any expressions which have two numeric operands, leaving out the parentheses around them.</p>

</blockquote><p>写一个符合 <code>(operand operator1 operator2)</code> 格式的正则表达式. 这个是比较简单的, 因为这里的运算符只有 <code>+</code>, <code>-</code>, <code>*</code>, <code>/</code>. 我们用 <code>[]</code> 括起来就可以, 但是要注意**<code>-</code> 需要用 <code>\</code> 转义**</p>]]></description>
</item><item>
    <title>Hw09 题解 (UCB CS61A@2021 Fall)</title>
    <link>https://martinlwx.github.io/zh-cn/hw09-of-cs61a-of-ucb/</link>
    <pubDate>Tue, 01 Mar 2022 21:13:22 &#43;0800</pubDate><author>
        <name>MartinLwx</name>
    </author><guid>https://martinlwx.github.io/zh-cn/hw09-of-cs61a-of-ucb/</guid>
    <description><![CDATA[<h3 id="q2-roman-numerals" class="headerLink">
    <a href="#q2-roman-numerals" class="header-mark"></a>Q2: Roman Numerals</h3><blockquote>
  <p>Write a regular expression that finds any string of letters that resemble a Roman numeral and aren&rsquo;t part of another word. A Roman numeral is made up of the letters I, V, X, L, C, D, M and is at least one letter long.</p>
<blockquote>
  <p>For the purposes of this problem, don&rsquo;t worry about whether or not a Roman numeral is valid. For example, &ldquo;VIIIII&rdquo; is not a Roman numeral, but it is fine if your regex matches it.</p>]]></description>
</item><item>
    <title>Lab11 题解 (UCB CS61A@2021 Fall)</title>
    <link>https://martinlwx.github.io/zh-cn/lab11-cs61a-of-ucb/</link>
    <pubDate>Tue, 01 Mar 2022 00:41:21 &#43;0800</pubDate><author>
        <name>MartinLwx</name>
    </author><guid>https://martinlwx.github.io/zh-cn/lab11-cs61a-of-ucb/</guid>
    <description><![CDATA[<h2 id="context" class="headerLink">
    <a href="#context" class="header-mark"></a>Context</h2><hr>
<h3 id="problem-1" class="headerLink">
    <a href="#problem-1" class="header-mark"></a>Problem 1</h3><blockquote>
  <blockquote>
  <p><strong>Important:</strong> Your code for this part should go in <code>buffer.py</code>.</p>

</blockquote><p>Your job in this part is to implement the <code>current</code> and <code>pop_first</code> methods of the <code>Buffer</code> class.</p>
<p><code>current</code> should return the current token of the current line we&rsquo;re on in the <code>Buffer</code> instance <em>without</em> removing it. If there are no more tokens in the current line, then <code>current</code> should move onto the next valid line, and return the <strong>first</strong> token of <em>this</em> line. If there are no more tokens left to return from the entire source (we&rsquo;ve reached the end of all input lines), then <code>current</code> should return <code>None</code> (this logic is already provided for you in the <code>except StopIteration</code> block).</p>]]></description>
</item><item>
    <title>Hw08 题解 (UCB CS61A@2021 Fall)</title>
    <link>https://martinlwx.github.io/zh-cn/hw08-of-cs61a-of-ucb/</link>
    <pubDate>Mon, 28 Feb 2022 00:28:31 &#43;0800</pubDate><author>
        <name>MartinLwx</name>
    </author><guid>https://martinlwx.github.io/zh-cn/hw08-of-cs61a-of-ucb/</guid>
    <description><![CDATA[<h3 id="q1-my-filter" class="headerLink">
    <a href="#q1-my-filter" class="header-mark"></a>Q1: My Filter</h3><blockquote>
  <p>Write a procedure <code>my-filter</code>, which takes a predicate <code>func</code> and a list <code>lst</code>, and returns a new list containing only elements of the list that satisfy the predicate. The output should contain the elements in the same order that they appeared in the original list.</p>
<p><strong>Note:</strong> Make sure that you are not just calling the built-in <code>filter</code> function in Scheme - we are asking you to re-implement this!</p>]]></description>
</item><item>
    <title>Hw06 题解 (UCB CS61A@2021 Fall)</title>
    <link>https://martinlwx.github.io/zh-cn/hw06-of-cs61a-of-ucb/</link>
    <pubDate>Sun, 27 Feb 2022 13:17:39 &#43;0800</pubDate><author>
        <name>MartinLwx</name>
    </author><guid>https://martinlwx.github.io/zh-cn/hw06-of-cs61a-of-ucb/</guid>
    <description><![CDATA[<h2 id="oop" class="headerLink">
    <a href="#oop" class="header-mark"></a>OOP</h2><hr>
<h3 id="q1-vending-machine" class="headerLink">
    <a href="#q1-vending-machine" class="header-mark"></a>Q1: Vending Machine</h3><blockquote>
  <p>In this question you&rsquo;ll create a <a href="https://en.wikipedia.org/wiki/Vending_machine" target="_blank" rel="noopener noreferrer">vending machine</a> that only outputs a single product and provides change when needed.</p>
<p>Create a class called <code>VendingMachine</code> that represents a vending machine for some product. A <code>VendingMachine</code>object returns strings describing its interactions. Remember to match <strong>exactly</strong> the strings in the doctests &ndash; including punctuation and spacing!</p>
<p>Fill in the <code>VendingMachine</code> class, adding attributes and methods as appropriate, such that its behavior matches the following doctests:</p>]]></description>
</item><item>
    <title>Lab10 题解 (UCB CS61A@2021 Fall)</title>
    <link>https://martinlwx.github.io/zh-cn/lab10-cs61a-of-ucb/</link>
    <pubDate>Sun, 27 Feb 2022 01:04:02 &#43;0800</pubDate><author>
        <name>MartinLwx</name>
    </author><guid>https://martinlwx.github.io/zh-cn/lab10-cs61a-of-ucb/</guid>
    <description><![CDATA[<h2 id="q2-over-or-under" class="headerLink">
    <a href="#q2-over-or-under" class="header-mark"></a>Q2: Over or Under</h2><blockquote>
  <p>Define a procedure <code>over-or-under</code> which takes in a number <code>num1</code> and a number <code>num2</code> and returns the following:</p>
<ul>
<li>-1 if <code>num1</code> is less than <code>num2</code></li>
<li>0 if <code>num1</code> is equal to <code>num2</code></li>
<li>1 if <code>num1</code> is greater than <code>num2</code></li>
</ul>
<blockquote>
  <p>Challenge: Implement this in 2 different ways using <code>if</code> and <code>cond</code>!</p>

</blockquote><div class="code-block highlight is-open show-line-numbers  tw-group tw-my-2">
  <div class="
    
    tw-flex 
    tw-flex-row
    tw-flex-1 
    tw-justify-between 
    tw-w-full tw-bg-bgColor-secondary
    ">      
    <button 
      class="
        code-block-button
        tw-mx-2 
        tw-flex
        tw-flex-row
        tw-flex-1"
      aria-hidden="true">
          <div class="group-[.is-open]:tw-rotate-90 tw-transition-[transform] tw-duration-500 tw-ease-in-out print:!tw-hidden tw-w-min tw-h-min tw-my-1 tw-mx-1"><svg class="icon"
    xmlns="http://www.w3.org/2000/svg" viewBox="0 0 320 512"><!-- Font Awesome Free 5.15.4 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free (Icons: CC BY 4.0, Fonts: SIL OFL 1.1, Code: MIT License) --><path d="M285.476 272.971L91.132 467.314c-9.373 9.373-24.569 9.373-33.941 0l-22.667-22.667c-9.357-9.357-9.375-24.522-.04-33.901L188.505 256 34.484 101.255c-9.335-9.379-9.317-24.544.04-33.901l22.667-22.667c9.373-9.373 24.569-9.373 33.941 0L285.475 239.03c9.373 9.372 9.373 24.568.001 33.941z"/></svg></div>
          <p class="tw-select-none !tw-my-1">text</p>]]></description>
</item></channel>
</rss>
