]> gitweb.factorcode.org Git - factor.git/blobdiff - extra/rosetta-code/knapsack/knapsack.factor
Harmonize spelling
[factor.git] / extra / rosetta-code / knapsack / knapsack.factor
index ada59fd96da5bb3f4fa8f45ba115aef74fca5a3e..83417eae3f5280fe1d5818241c971c7639a99f21 100644 (file)
@@ -1,7 +1,7 @@
 ! Copyright (c) 2012 Anonymous
 ! See http://factorcode.org/license.txt for BSD license.
-USING: accessors arrays fry io kernel locals make math
-math.order math.parser math.ranges sequences sorting ;
+USING: accessors arrays io kernel make math math.order
+math.parser ranges sequences sorting ;
 IN: rosetta-code.knapsack
 
 ! http://rosettacode.org/wiki/Knapsack_problem/0-1
@@ -24,7 +24,7 @@ IN: rosetta-code.knapsack
 
 ! Which items does the tourist carry in his knapsack so that
 ! their total weight does not exceed 400 dag [4 kg], and their
-! total value is maximised?
+! total value is maximized?
 
 TUPLE: item
     name weight value ;
@@ -53,17 +53,17 @@ CONSTANT: items {
         T{ item f "socks" 4 50 }
         T{ item f "book" 30 10 }
     }
+
 CONSTANT: limit 400
+
 : make-table ( -- table )
     items length 1 + [ limit 1 + 0 <array> ] replicate ;
+
 :: iterate ( item-no table -- )
     item-no table nth :> prev
     item-no 1 + table nth :> curr
     item-no items nth :> item
-    limit [1,b] [| weight |
+    limit [1..b] [| weight |
         weight prev nth
         weight item weight>> - dup 0 >=
         [ prev nth item value>> + max ]
@@ -72,13 +72,13 @@ CONSTANT: limit 400
     ] each ;
 
 : fill-table ( table -- )
-    [ items length iota ] dip
+    [ items length <iota> ] dip
     '[ _ iterate ] each ;
 
 :: extract-packed-items ( table -- items )
     [
         limit :> weight!
-        items length iota <reversed> [| item-no |
+        items length <iota> <reversed> [| item-no |
             item-no table nth :> prev
             item-no 1 + table nth :> curr
             weight [ curr nth ] [ prev nth ] bi =