Assigned Th 6/26/2008, due Fr 7/4 at 9pm. 50 points.
http://www.cs.nyu.edu/courses/summer08/G22.3033-002/
These are example solutions. Please keep in mind that often, there is not just one correct solution to a question. If you come up with different answers, then it may be that both your answers and these answers here are correct. Of course, these answers here may also contain mistakes. If you spot a mistake, please let me know so I can correct it.
6, 10
curry.
The environment is a call object for curry, with f=add
and x=1.
curry.
The environment is a call object for curry, with f bound
to the anonymous function function(x,y){x/y} and x=2.
var square = curry(
function(n,x){ for(var z=1;n>0;n--,z*=x); return z; },
2);
Cf, Dg, Ch
Cf, Dg, Eh
<html><head>
<meta http-equiv="Content-Script-Type" content="text/javascript" />
<script>
function c2f() {
var c = document.converter.celsius.value;
var f = c * 9 / 5 + 32;
document.converter.fahrenheit.value = f;
}
function f2c() {
var f = document.converter.fahrenheit.value;
var c = (f - 32) * 5 / 9;
document.converter.celsius.value = c;
}
</script>
</head><body>
<form name="converter">
<table border=0>
<tr>
<td>Celsius:
<td><input type="text" name="celsius">
<td><input type="button" value="To Fahrenheit" onclick="c2f();">
<tr>
<td>Fahrenheit:
<td><input type="text" name="fahrenheit">
<td><input type="button" value="To Celsius" onclick="f2c();">
</table>
</form>
</body></html>
function PriorityQueue() {
this.data = [];
}
PriorityQueue.prototype.push = function(x) {
this.data.push(x);
}
PriorityQueue.prototype.minIndex = function() {
var result;
for (var i in this.data)
if (undefined == result || this.data[i] < this.data[result])
result = i;
return result;
}
PriorityQueue.prototype.peek = function() {
return this.data[this.minIndex()];
}
PriorityQueue.prototype.pop = function() {
var i = this.minIndex();
var result = this.data[i];
delete this.data[i];
return result;
}