2016 Update

This commit is contained in:
Tina Müller 2016-12-05 22:15:40 +01:00
parent 948b86eafa
commit dcf5d15da3
7965 changed files with 139854 additions and 31002 deletions

View file

@ -23,4 +23,6 @@ int main()
// get rid of array
delete[] array;
delete[] array_data;
return 0;
}

View file

@ -19,4 +19,5 @@ int main()
std::cout << array[0][0] << std::endl;
// the array is automatically freed at the end of main()
return 0;
}

View file

@ -12,9 +12,11 @@ int main()
// create array
two_d_array_type A(boost::extents[dim1][dim2]);
// write elements
// write element
A[0][0] = 3.1415;
// read elements
// read element
std::cout << A[0][0] << std::endl;
return 0;
}

View file

@ -0,0 +1,18 @@
#include <cstdlib>
#include <boost/numeric/ublas/matrix.hpp>
#include <boost/numeric/ublas/io.hpp>
int main (const int argc, const char** argv) {
if (argc > 2) {
using namespace boost::numeric::ublas;
matrix<double> m(atoi(argv[1]), atoi(argv[2])); // build
for (unsigned i = 0; i < m.size1(); i++)
for (unsigned j = 0; j < m.size2(); j++)
m(i, j) = 1.0 + i + j; // fill
std::cout << m << std::endl; // print
return EXIT_SUCCESS;
}
return EXIT_FAILURE;
}

View file

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

View file

@ -0,0 +1,19 @@
#import system.
#import system'routines.
#import extensions.
#symbol program =
[
#var n := Integer new.
#var m := Integer new.
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".
console writeLine:(myArray2@0@0).
console writeLine:(myArray2@1@0).
].

View file

@ -0,0 +1,29 @@
defmodule TwoDimArray do
def create(w, h) do
List.duplicate(0, w)
|> List.duplicate(h)
end
def set(arr, x, y, value) do
List.replace_at(arr, x,
List.replace_at(Enum.at(arr, x), y, value)
)
end
def get(arr, x, y) do
arr |> Enum.at(x) |> Enum.at(y)
end
end
width = IO.gets "Enter Array Width: "
w = width |> String.trim() |> String.to_integer()
height = IO.gets "Enter Array Height: "
h = height |> String.trim() |> String.to_integer()
arr = TwoDimArray.create(w, h)
arr = TwoDimArray.set(arr,2,0,42)
IO.puts(TwoDimArray.get(arr,2,0))

View file

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

View file

@ -1,4 +1,3 @@
$ ./two-dee
Dimensions? 5x35
[@ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @]
[@ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @]

View file

@ -0,0 +1,4 @@
my ($major,$minor) = +«prompt("Dimensions? ").comb(/\d+/);
my Int @array[$major;$minor] = (7 xx $minor ) xx $major;
@array[$major div 2;$minor div 2] = 42;
say @array;

View file

@ -0,0 +1,2 @@
Dimensions? 3 x 10
[[7 7 7 7 7 7 7 7 7 7] [7 7 7 7 7 42 7 7 7 7] [7 7 7 7 7 7 7 7 7 7]]

View file

@ -0,0 +1,22 @@
function Read-ArrayIndex ([string]$Prompt = "Enter an integer greater than zero")
{
[int]$inputAsInteger = 0
while (-not [Int]::TryParse(([string]$inputString = Read-Host $Prompt), [ref]$inputAsInteger))
{
$inputString = Read-Host "Enter an integer greater than zero"
}
if ($inputAsInteger -gt 0) {return $inputAsInteger} else {return 1}
}
$x = $y = $null
do
{
if ($x -eq $null) {$x = Read-ArrayIndex -Prompt "Enter two dimensional array index X"}
if ($y -eq $null) {$y = Read-ArrayIndex -Prompt "Enter two dimensional array index Y"}
}
until (($x -ne $null) -and ($y -ne $null))
$array2d = New-Object -TypeName 'System.Object[,]' -ArgumentList $x, $y

View file

@ -0,0 +1,6 @@
[int]$k = 1
for ($i = 0; $i -lt 6; $i++)
{
0..5 | ForEach-Object -Begin {$k += 10} -Process {$array2d[$i,$_] = $k + $_}
}

View file

@ -0,0 +1,4 @@
for ($i = 0; $i -lt 6; $i++)
{
"{0}`t{1}`t{2}`t{3}`t{4}`t{5}" -f (0..5 | ForEach-Object {$array2d[$i,$_]})
}