Exercise Idea: composite-resistors
Maintainer thường phản hồi trong vòng 1 ngày
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 5/5
- Thời gian dự kiến
- Hơn một tuần
- Mức phù hợp với người mới
- 25/100
Hướng nghiên cứu
Bắt đầu bằng cách đọc đề xuất này cùng với bài tập resistor-color-trio của track Haskell và tài liệu tham chiếu về luật monoid được liên kết. Hãy làm rõ phạm vi dự kiến của bài tập, biểu diễn và các tính chất cần có trước khi triển khai; được xem là hoàn tất khi community đã thống nhất một đặc tả cho bài tập composite-resistors.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
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.
- Ngôn ngữ chính
- Ruby
- Star
- 362
- Fork
- 566
- Merge trung bình
- 15 giờ 13 phút
- Pull request đã merge (30 ngày)
- 8
Chuẩn bị môi trường
Dự án này không cung cấp dev container, Dockerfile hay hướng dẫn đóng góp, nên bạn cần tự thiết lập môi trường: hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của exercism/problem-specifications
-
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 90/100
exercism/problem-specifications#2686 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 25/100
exercism/problem-specifications#2704 · 21 bình luận · 8 reaction ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 1/5 1-3 giờ Mức phù hợp với người mới 35/100
exercism/problem-specifications#2153 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 35/100
exercism/problem-specifications#2120 · 7 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 25/100
exercism/problem-specifications#2108 · 1 bình luận · 5 reaction ·
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của exercism/problem-specifications
Issue tương tự
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Bug Ruby Waiting for: Product Owner
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
getsentry/sentry-ruby#3228 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
Maintainer thường phản hồi trong vòng 1 ngày
-
開発用DockerイメージにPlaywrightのシステム依存を追加するCó thể đã có người làm @momocus đã nhận hôm nay. Đang mở
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 85/100
sakazuki-org/sakazuki#1453 ·
Maintainer thường phản hồi trong vòng 3 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100