diff options
| author | mo khan <mo@mokhan.ca> | 2024-06-01 13:38:59 -0600 |
|---|---|---|
| committer | mo khan <mo@mokhan.ca> | 2024-06-01 13:38:59 -0600 |
| commit | 09051a67f719b4ceecae31530faca315c7e98175 (patch) | |
| tree | cfee4c83e63fba7b689852ef5a7cd69dad020241 /assignments/1-solution.md | |
| parent | 4726d4cd702abfb5b900bd13269764d944933079 (diff) | |
Add headings
Diffstat (limited to 'assignments/1-solution.md')
| -rw-r--r-- | assignments/1-solution.md | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/assignments/1-solution.md b/assignments/1-solution.md index c9ca093..7603c6b 100644 --- a/assignments/1-solution.md +++ b/assignments/1-solution.md @@ -9,6 +9,8 @@ Chapter 2: 4. Write an algorithm that gets the price for item A plus the quantity purchased. The algorithm prints the total cost, including 6% sales tax. + Pseudocode + ```plaintext Get values for `price` and `quantity` Set the value of `tax` to 1.06 @@ -16,9 +18,11 @@ Chapter 2: Print the value of `total` ``` + Ruby code + ```ruby def calculate_total(price, quantity, tax = 0.06) - return (price * quantity) * (1.0 + tax) + (price * quantity) * (1.0 + tax) end ``` @@ -27,6 +31,8 @@ Chapter 3: 21. Use the binary search algorithm to decide whether 35 is in the following list: `3, 6, 7, 9, 12, 14, 18, 21, 22, 31, 43` + Pseudocode + ```plaintext Get the list of numbers and assign to variable `items` Get the target number and assign to variable `target` @@ -54,6 +60,8 @@ Chapter 3: stop ``` + Ruby code + ```ruby def bsearch(target, items) min = 0 |
