Commit 09051a6
Changed files (2)
assignments
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
3431709-assignment-1.pdf
Binary file