September 2017 Update

This commit is contained in:
Ingy döt Net 2017-09-23 10:01:46 +02:00
parent bba7bfd280
commit ba8067c3b7
14570 changed files with 153136 additions and 63871 deletions

View file

@ -1,17 +1,16 @@
#import system.
#import extensions.
import extensions.
#symbol program =
program =
[
#var n := Integer new.
#var m := Integer new.
var n := Integer new.
var m := Integer new.
console write:"Enter two space delimited integers:".
console readLine:n:m.
console write:"Enter two space delimited integers:".
console readLine(n,m).
#var myArray := RealMatrix new:n:m.
var myArray := RealMatrix new(n,m).
myArray@0@0 := 2.
myArray[0][0] := 2.
console writeLine:(myArray@0@0).
console printLine(myArray[0][0]).
].

View file

@ -1,19 +1,18 @@
#import system.
#import system'routines.
#import extensions.
import system'routines.
import extensions.
#symbol program =
program =
[
#var n := Integer new.
#var m := Integer new.
var n := Integer new.
var m := Integer new.
console write:"Enter two space delimited integers:".
console readLine:n:m.
console write:"Enter two space delimited integers:".
console readLine(n,m).
#var myArray2 := Array new:n set &every:(&index:i) [ Array new:m ].
myArray2@0@0 := 2.
myArray2@1@0 := "Hello".
var myArray2 := Array new:n; populate(:i)( Array new:m ).
myArray2[0][0] := 2.
myArray2[1][0] := "Hello".
console writeLine:(myArray2@0@0).
console writeLine:(myArray2@1@0).
console printLine(myArray2[0][0]).
console printLine(myArray2[1][0]).
].

View file

@ -1 +1,3 @@
doit n m = a!(0,0) where a = array ((0,0),(n,m)) [((0,0),42)]
import Data.Array
doit n m = a!(0,0) where a = array ((0,0),(n,m)) [((0,0),42)]

View file

@ -1,7 +1,15 @@
fun main(args: Array<String>) {
val dim = args.map { it.toInt() } // interpret
val array = Array(dim[0], { IntArray(dim[1]) } ) // build
// build
val dim = arrayOf(10, 15)
val array = Array(dim[0], { IntArray(dim[1]) } )
array.forEachIndexed { i, it -> for (j in it.indices) it[j] = 1 + i + j } // fill
array.forEach { println(it.asList()) } // print
// fill
array.forEachIndexed { i, it ->
it.indices.forEach { j ->
it[j] = 1 + i + j
}
}
// print
array.forEach { println(it.asList()) }
}

View file

@ -0,0 +1,11 @@
Say "enter first dimension"
pull d1
say "enter the second dimension"
pull d2
a = .array~new(d1, d2)
a[1, 1] = "Abc"
say a[1, 1]
say d1 d2 a[d1,d2]
say a[10,10]
max=1000000000
b = .array~new(max,max)

View file

@ -0,0 +1,28 @@
use std::env;
fn main() {
let mut args = env::args().skip(1).flat_map(|num| num.parse());
let rows = args.next().expect("Expected number of rows as first argument");
let cols = args.next().expect("Expected number of columns as second argument");
assert!(rows != 0 && cols != 0);
// Creates a vector of vectors with all elements initialized to 0.
let mut v = init_vec(rows, || init_vec(cols, || 0));
v[0][0] = 1;
println!("{}", v[0][0]);
}
// Returns a dynamically-allocated array of size `n`,
// initialized with the values computed by `f`
fn init_vec<F,T>(n: usize, f: F) -> Vec<T>
where F: Fn() -> T
{
let mut vec = Vec::with_capacity(n);
for _ in 0..n {
vec.push(f());
}
vec
}

View file

@ -0,0 +1,24 @@
(import (scheme base)
(scheme read)
(scheme write))
;; Read x/y from user
(define x (begin (display "X: ") (flush-output-port) (read)))
(define y (begin (display "Y: ") (flush-output-port) (read)))
;; Create a vector, and fill it with a vector for each row
(define arr (make-vector x))
(do ((i 0 (+ 1 i)))
((= i x) )
(vector-set! arr i (make-vector y 0)))
;; set element (x/2, y/2) to 3
(vector-set! (vector-ref arr (floor (/ x 2)))
(floor (/ y 2))
3)
(display arr) (newline)
(display "Retrieved: ")
(display (vector-ref (vector-ref arr (floor (/ x 2)))
(floor (/ y 2))))
(newline)

View file

@ -0,0 +1,18 @@
(import (except (scheme base) equal?)
(scheme read)
(scheme write)
(srfi 63) ; an array SRFI
)
;; Read x/y from user
(define x (begin (display "X: ") (flush-output-port) (read)))
(define y (begin (display "Y: ") (flush-output-port) (read)))
;; Create an array
(define array (make-array #(0) x y))
;; Write to middle element of the array
(array-set! array 3 (floor (/ x 2)) (floor (/ y 2)))
;; Retrieve and display result
(display (array-ref array (floor (/ x 2)) (floor (/ y 2)))) (newline)

View file

@ -0,0 +1,6 @@
display "Number of rows?" _request(nr)
display "Number of columns?" _request(nc)
matrix define a=J($nr,$nc,0)
matrix a[1,2]=1.5
matrix list a
matrix drop a

View file

@ -0,0 +1,8 @@
mata
mata stata display "Number of rows?" _request(nr)
mata stata display "Number of columns?" _request(nc)
a=J($nr,$nc,0)
a[1,2]=1.5
a
mata drop a
end

View file

@ -0,0 +1,6 @@
rows:=ask("Rows: ").toInt();
cols:=ask("columns: ").toInt();
array:=rows.pump(List.createLong(rows),List.createLong(cols,0).copy);
array[1][2]=123;
array.println();
array[1][2].println();

View file

@ -0,0 +1,7 @@
var [const] GSL=Import("zklGSL"); // libGSL (GNU Scientific Library)
rows:=ask("Rows: ").toInt();
cols:=ask("columns: ").toInt();
m:=GSL.Matrix(rows,cols);
m[1,2]=123;
m.format().println();
println(m[1,2]);