Another update from ingydotnet^djgoku
This commit is contained in:
parent
91df62d461
commit
948b86eafa
7604 changed files with 108452 additions and 22726 deletions
|
|
@ -0,0 +1,22 @@
|
|||
begin
|
||||
integer dimension1UpperBound, dimension2UpperBound;
|
||||
write( "upper bound for dimension 1: " );
|
||||
read( dimension1UpperBound );
|
||||
write( "upper bound for dimension 2: " );
|
||||
read( dimension2UpperBound );
|
||||
|
||||
begin
|
||||
% we start a new block because declarations must precede statements %
|
||||
% and variables in array bounds must be from outside the block %
|
||||
integer array matrix ( 1 :: dimension1UpperBound
|
||||
, 1 :: dimension2UpperBound
|
||||
);
|
||||
% set the first element - the program will crash if the user input %
|
||||
% upper bounds less than 1 %
|
||||
matrix( 1, 1 ) := 3;
|
||||
% write it %
|
||||
write( matrix( 1, 1 ) );
|
||||
% the array is automatically deleted when the block ends %
|
||||
end
|
||||
|
||||
end.
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
10 INPUT "ENTER TWO INTEGERS:"; X%, Y%
|
||||
20 DIM A%(X% - 1, Y% - 1)
|
||||
30 X% = RND(1) * X%
|
||||
40 Y% = RND(1) * Y%
|
||||
50 A%(X%, Y%) = -32767
|
||||
60 PRINT A%(X%, Y%)
|
||||
70 CLEAR
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
CLS
|
||||
INPUT a, b 'inputs need to be separated by commas
|
||||
DIM array (1 TO a, 1 TO b)
|
||||
array(1,1) = 42
|
||||
PRINT array(1,1)
|
||||
ERASE array
|
||||
|
|
@ -1,28 +1,17 @@
|
|||
var w = parseInt( get_input("Enter a width:") );
|
||||
var w = parseInt( get_input("Enter a height:") );
|
||||
var width = Number(prompt("Enter width: "));
|
||||
var height = Number(prompt("Enter height: "));
|
||||
|
||||
// create the 2-D array
|
||||
var a = new Array(h);
|
||||
for (var i = 0; i < h; i++)
|
||||
a[i] = new Array(w);
|
||||
//make 2D array
|
||||
var arr = new Array(height);
|
||||
|
||||
for (var i = 0; i < h; i++) {
|
||||
arr[i] = new Array(width);
|
||||
}
|
||||
|
||||
//set value of element
|
||||
a[0][0] = 'foo';
|
||||
WScript.Echo('a[0][0] = ' + a[0][0]);
|
||||
//print value of element
|
||||
console.log('arr[0][0] = ' + arr[0][0]);
|
||||
|
||||
a = null;
|
||||
|
||||
function get_input(prompt) {
|
||||
output(prompt);
|
||||
try {
|
||||
return WScript.StdIn.readLine();
|
||||
} catch(e) {
|
||||
return readline();
|
||||
}
|
||||
}
|
||||
function output(prompt) {
|
||||
try {
|
||||
return WScript.echo(prompt);
|
||||
} catch(e) {
|
||||
return print(prompt);
|
||||
}
|
||||
}
|
||||
//cleanup array
|
||||
arr = void(0);
|
||||
|
|
|
|||
|
|
@ -0,0 +1,38 @@
|
|||
julia> "Inspired by Python's `input` function."
|
||||
function input(prompt::AbstractString="")
|
||||
print(prompt)
|
||||
chomp(readline())
|
||||
end
|
||||
input (generic function with 2 methods)
|
||||
|
||||
julia> n = parse(Int, input("Upper bound for dimension 1: ")) # parse as `Int`
|
||||
Upper bound for dimension 1: 5
|
||||
5
|
||||
|
||||
julia> m = parse(Int, input("Upper bound for dimension 2: "))
|
||||
Upper bound for dimension 2: 5
|
||||
5
|
||||
|
||||
julia> x = rand(n, m) # create an n·m random matrix
|
||||
5x5 Array{Float64,2}:
|
||||
0.80217 0.422318 0.594049 0.45547 0.208822
|
||||
0.0533981 0.304858 0.0276755 0.797732 0.828796
|
||||
0.522506 0.563856 0.216759 0.865961 0.034306
|
||||
0.792363 0.815744 0.868697 0.42509 0.588946
|
||||
0.112034 0.539611 0.674581 0.508299 0.939373
|
||||
|
||||
julia> x[3, 3] # overloads `getindex` generic function
|
||||
0.21675944652281487
|
||||
|
||||
julia> x[3, 3] = 5 # overloads `setindex!` generic function
|
||||
5
|
||||
|
||||
julia> x::Matirx # `Matrix{T}` is an alias for `Array{T, 2}`
|
||||
5x5 Array{Float64,2}:
|
||||
0.80217 0.422318 0.594049 0.45547 0.208822
|
||||
0.0533981 0.304858 0.0276755 0.797732 0.828796
|
||||
0.522506 0.563856 5.0 0.865961 0.034306
|
||||
0.792363 0.815744 0.868697 0.42509 0.588946
|
||||
0.112034 0.539611 0.674581 0.508299 0.939373
|
||||
|
||||
julia> x = 0; gc() # Julia has no `del` command, rebind `x` and call the garbage collector
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
$ ./two-dee
|
||||
Dimensions? 5x35
|
||||
@ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @
|
||||
@ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @
|
||||
@ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @
|
||||
@ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @
|
||||
@ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @
|
||||
[@ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @]
|
||||
[@ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @]
|
||||
[@ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @]
|
||||
[@ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @]
|
||||
[@ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @]
|
||||
|
|
|
|||
|
|
@ -0,0 +1,6 @@
|
|||
Input "ROWS? ",R
|
||||
Input "COLS? ",C
|
||||
{R,C}→dim([A])
|
||||
42→[A](1,1)
|
||||
Disp [A](1,1)
|
||||
DelVar [A]
|
||||
|
|
@ -1,17 +1,16 @@
|
|||
package require Tcl 8.5
|
||||
|
||||
puts "enter X dimension:"
|
||||
set dim2 [gets stdin]
|
||||
puts "enter Y dimension:"
|
||||
set dim1 [gets stdin]
|
||||
# Make the "array"; we'll keep it in row-major form
|
||||
set l [lrepeat $dim1 [lrepeat $dim2 {}]]
|
||||
# Select a point at around the middle of the "array"
|
||||
set y [expr {$dim1>>1}]
|
||||
set x [expr {$dim2>>1}]
|
||||
# Set the value at that point
|
||||
lset l $y $x aValue
|
||||
# Read the value at that point
|
||||
puts [lindex $l $y $x]
|
||||
# Delete the "array"
|
||||
unset l
|
||||
puts "Enter width:"
|
||||
set width [gets stdin]
|
||||
puts "Enter height:"
|
||||
set height [gets stdin]
|
||||
# Initialize array
|
||||
for {set i 0} {$i < $width} {incr i} {
|
||||
for {set j 0} {$j < $height} {incr j} {
|
||||
set arr($i,$j) ""
|
||||
}
|
||||
}
|
||||
# Store value
|
||||
set arr(0,0) "abc"
|
||||
# Print value
|
||||
puts "Element (0/0): $arr(0,0)"
|
||||
# Cleanup array
|
||||
unset arr
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue