This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
v = values from item1..itemn | |
w = weights from item1..itemn | |
n = number of items | |
W = maximum weight of knapsack | |
m[n, n] = array(int, int) | |
function knapsack | |
for w=0..W | |
m[0, w] = 0 | |
for i=1 to n |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
detectAquamacs() | |
{ | |
if [ ! -e "/Applications/Aquamacs.app" ]; then | |
`$CD ok-msgbox --no-cancel --icon info --timeout 20 --title "Aquamacs not found" --text "This application is needed to run Mozart" --informative-text "You can download it from http://aquamacs.org/"` | |
exit 2 | |
fi | |
} | |
exec /Applications/Aquamacs.app/Contents/MacOS/Aquamacs --eval '(setq load-path (cons "'$OZHOME'/share/elisp" load-path))' -l oz.elc -f run-oz $2 & |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
detectAquamacs() | |
{ | |
if [ ! -e "/Applications/Aquamacs.app" ]; then | |
`$CD ok-msgbox --no-cancel --icon info --timeout 20 --title "Aquamacs not found" --text "This application is needed to run Mozart" --informative-text "You can download it from http://aquamacs.org/"` | |
exit 2 | |
fi | |
} | |
exec /Applications/Aquamacs.app/Contents/MacOS/Aquamacs --eval '(setq load-path (cons "'$OZHOME'/share/elisp" load-path))' -l oz.elc -f run-oz $2 & |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
v = values from item1..itemn | |
w = weights from item1..itemn | |
n = number of items | |
W = maximum weight of knapsack | |
m[n, n] = array(int, int) | |
function knapsack | |
for w=0..W | |
m[0, w] = 0 | |
for i=1 to n |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
v = values from item1..itemn | |
w = weights from item1..itemn | |
n = number of items | |
W = maximum weight of knapsack | |
m[n, n] = array(int, int) | |
function knapsack | |
for w=0..W | |
m[0, w] = 0 | |
for i=1 to n |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if i = 0 or w = 0 | |
m[i, w] = 0 | |
if w[i] > w | |
m[i - 1, w] | |
if w[i] <= w | |
max(m[i - 1, w], m[i - 1, w - w[i]] + v[i]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Repeater | |
@@subscribers = [] | |
# Add the new subscriber to our list of subscribers | |
def subscribe(newSubscriber) | |
@@subscribers << newSubscriber | |
end | |
# Send the message to all of our subscribers | |
def broadcast(message) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class GameState | |
include Subscriber | |
def initialize(repeater) | |
@repeater = repeater | |
@repeater.subscribe(self) | |
end | |
# Handle only messages of attempt move, ignore the rest | |
def accept(message) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class GameMultiplayer | |
include Subscriber | |
def initialize(repeater) | |
@repeater = repeater | |
@repeater.subscribe(self) | |
end | |
def accept(message) | |
case message[:command] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Repeater | |
@@subscribers = [] | |
def subscribe(newSubscriber) | |
@@subscribers << newSubscriber | |
end | |
def broadcast(message) | |
@@subscribers.each { |subscriber| | |
subscriber.send(message[:command], message[:options]) if subscriber.respond_to? message[:command] |
OlderNewer