Exercise Idea: composite-resistors
メンテナーはふだん 1 日以内に返信
まだ誰も着手していません。
評価
調査の方向性
まず、この提案を Haskell トラックの resistor-color-trio exercise およびリンクされている monoid-law reference と併せて読んでください。実装前に、想定される exercise の範囲、表現、期待される性質を明確にしてください。完了とは、community が composite-resistors exercise の仕様に合意した状態を指します。
索引モデルが issue の本文から書いたものです。
説明
This exercise is proposed in the context of the Haskell track, but I'm posting it here because I like the idea of sharing exercise ideas across, and monoid abstractions exist in other languages, too. In the process of porting resistor-color-trio in exercism/haskell#869, it occurred to me that resistors are monoids in two ways:
When you put them in series, they form an additive monoid (resistance adds up) with (black, black, black), better known as a wire, as the identity resistor. And when you put them in parallel, you don't exactly get a multiplicative monoid, since n resistors in parallel add up like 1/R = 1/R₁ + 1/R₂ + ... + 1/Rₙ. What's the identity resistor for a parallel circuit?
It isn't a wire, since then the current would follow the path of least resistance, which would always end up being the wire. A neutral resistor in a parallel circuit is any non-conductive material with infinite resistance. For example, my willingness to code in another language than Haskell.
Putting resistors in series and in parallel is neat in practice for making non-standard resistors or when you run out of a certain kind of resistor.
Haskell has some machinery for dealing with types that are monoids in more than one way: while one can define instance Monoid (Sum Resistor) where ... for the built-in Sum type, it seems necessary to define one's own Parallel type and make instance Monoid (Parallel Resistor) where ... instead.
Having this exercise in succession of resistor-color-trio leads to interesting thoughts:
- The data type
Resistoris given as a newtype wrapper around(Color, Color, Color). - But that means there is no constructor for a resistor with infinite resistance.
- But that means some composite resistors don't have such a representation:
let r50 = Resistor (Green, Black, Black) r1000 = Resistor (Brown, Black, Orange) r1050 = getSum (Sum r50 <> Sum r1000) r1050 == Resistor (???) - But that's okay, because this representation has another bad property:
(We don't comparelet ten1 = Resistor (Brown, Black, Black) ten2 = Resistor (Black, Brown, Brown) ohms ten1 == ohms ten2 -- True ten1 == ten2 -- FalseResistors for equality in -trio, so we live with it there.) - A necessary part of this exercise would then be to refactor the representation of -trio.
- This is an excellent opportunity for property-based tests of monoidal laws.
- 主要言語
- Ruby
- スター
- 362
- フォーク
- 566
- 平均マージ
- 15時間 13分
- マージ済み PR(30日)
- 8
環境構築
このプロジェクトには開発コンテナ、Dockerfile、コントリビューションガイドがありません。まず README を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
exercism/problem-specifications のほかの issue
-
難易度 1/5 1時間未満 初心者へのやさしさ 90/100
exercism/problem-specifications#2686 ·
メンテナーはふだん 1 日以内に返信
-
難易度 5/5 1週間以上 初心者へのやさしさ 25/100
exercism/problem-specifications#2704 · コメント 21 件 · リアクション 8 件 ·
メンテナーはふだん 1 日以内に返信
-
難易度 1/5 1〜3時間 初心者へのやさしさ 35/100
exercism/problem-specifications#2153 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
難易度 4/5 3〜5日 初心者へのやさしさ 35/100
exercism/problem-specifications#2120 · コメント 7 件 ·
メンテナーはふだん 1 日以内に返信
-
難易度 5/5 1週間以上 初心者へのやさしさ 25/100
exercism/problem-specifications#2108 · コメント 1 件 · リアクション 5 件 ·
メンテナーはふだん 1 日以内に返信
exercism/problem-specifications の issue をすべて見る
似ている issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
メンテナーはふだん 1 日以内に返信
-
Bug Ruby Waiting for: Product Owner
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
getsentry/sentry-ruby#3228 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
メンテナーはふだん 1 日以内に返信
-
開発用DockerイメージにPlaywrightのシステム依存を追加する対応中かも @momocus が今日担当しました。 オープン
難易度 1/5 1時間未満 初心者へのやさしさ 85/100
sakazuki-org/sakazuki#1453 ·
メンテナーはふだん 3 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100