Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p><em>Here is the answer that I posted to <a href="https://codereview.stackexchange.com/a/31409/9357">Code Review</a>. I'm using Python as executable pseudocode.</em></p> <hr> <p>You must be working for American health care. The key insight about American healthcare is that the first question is always "Do you have insurance?" Indeed, if you restructure your code to ask that first, you'll find that the pattern will be more obvious.</p> <pre><code>if insured: if first: if preferred: print('Monthly Statement') else: print('Pay one-half and Billed one-half') else: if preferred then: print('Monthly Statement') else: print('Monthly Statement') else: if first: if preferred: print('Pay one-half and Billed one-half') else: print('Pay full') else: if preferred: print('Pay one-half and Billed one-half') else: print('Pay one-half and Billed one-half') </code></pre> <p>The next goal is to consolidate to avoid repetition. You'll notice that the "preferred" status only matters for first-time customers, so <code>(first and not preferred)</code> is a useful common expression; I've parenthesized them as such for emphasis.</p> <p>Answer:</p> <pre><code>if (not insured) and (first and not preferred): pay_in_full() elif (not insured) or (first and not preferred): pay_half_bill_half() else: monthly_statement() </code></pre> <p>From there, you gain the insight that in general, insured patients get monthly bills, and uninsured patients pay half up front. However, being <code>(first and not preferred)</code> carries a penalty of one degree of trustworthiness. The following code implements this intuitive classification process.</p> <pre><code># Actions def pay_in_full(): ... def pay_half_bill_half(): ... def monthly_statement(): ... # Determine trust level trust_levels = [pay_in_full, pay_half_bill_half, monthly_statement] trust = 2 if insured else 1 # insured -&gt; monthly. uninsured -&gt; pay half trust -= 1 if first and not preferred # penalty for first-time unpreferred customers # Call the code corresponding to the trust level trust_levels[trust]() </code></pre> <p>It's up to you to decide whether you think the code based on truth-table minimization or on the intuitive classification is better.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload