Skip to content

Commit

Permalink
Fix: trailing white space and missing EOL
Browse files Browse the repository at this point in the history
  • Loading branch information
kotp committed Jul 17, 2024
1 parent 41becb8 commit d1326e4
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 14 deletions.
4 changes: 2 additions & 2 deletions exercises/practice/knapsack/.docs/instructions.append.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
The items are represented by [records](https://lfe.gitbooks.io/reference-guide/content/16.html), defined in `item.lfe`.
Use `item-weight` to get the weight and `item-value` to get the value.
Use `item-weight` to get the weight and `item-value` to get the value.

```
;; Create an item with weight=5, value=50
Expand All @@ -10,4 +10,4 @@ Use `item-weight` to get the weight and `item-value` to get the value.
;; Get the value. Returns 50.
(item-value item)
```
```
20 changes: 10 additions & 10 deletions exercises/practice/knapsack/.meta/example.lfe
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@
(weight-value (item-weight item))
(value-value (item-value item))
(left-over-capacity (- capacity weight-value)))
(if
(if
(< left-over-capacity 0)
value-without
(let
(let
((value-with
(+
(lists:nth (+ left-over-capacity 1) last-values)
Expand All @@ -22,27 +22,27 @@

(defun next-values
([item last-values -1 acc] acc)
([item last-values capacity acc]
(next-values
item
last-values
(- capacity 1)
([item last-values capacity acc]
(next-values
item
last-values
(- capacity 1)
(cons (find-max item last-values capacity) acc))))

(defun do-maximum-values
(['() last-values capacity] (lists:last last-values))
([(cons item remaining) last-values capacity]
(do-maximum-values
remaining
remaining
(next-values item last-values capacity '())
capacity)))

(defun maximum-value
(('() _capacity) 0)
((items capacity)
(do-maximum-values
(do-maximum-values
items
(lists:duplicate
(lists:duplicate
(+ capacity 1)
0)
capacity)))
2 changes: 1 addition & 1 deletion exercises/practice/knapsack/include/item.lfe
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
; This include file defines the item record used in the exercise.
; There shouldn't be any need to modify this file.

(defrecord item weight value)
(defrecord item weight value)
1 change: 0 additions & 1 deletion exercises/practice/knapsack/test/knapsack-tests.lfe
Original file line number Diff line number Diff line change
Expand Up @@ -81,4 +81,3 @@
(make-item weight 118 value 229)
(make-item weight 120 value 240))
750)))

0 comments on commit d1326e4

Please sign in to comment.