Lowlands Tactical: Forum
De grote programmeer opdracht 2016! - Printable Version

+- Lowlands Tactical: Forum (http://forums.lowtac.nl)
+-- Forum: Publiek (http://forums.lowtac.nl/forumdisplay.php?fid=1)
+--- Forum: Speeltuin (http://forums.lowtac.nl/forumdisplay.php?fid=6)
+--- Thread: De grote programmeer opdracht 2016! (/showthread.php?tid=652)



De grote programmeer opdracht 2016! - Sacha - 08-10-2016

Neem de taal die je kent en laat zien wat je kan en hoe dit eruit ziet:
Archu Wrote:-Create an array of ten integers
-Fill the array with ten random numbers (1-100)
-Copy the array (into another array of the same capacity)
-Change the last value in the first array to a -7
-Display the contents of both arrays

Toon hier jullie resultaten!


RE: De grote programmeer opdracht 2016! - Sacha - 08-10-2016

Code:
#!/usr/bin/env python3
import random
myArray = []
for n in range(0,10):
 myArray.append(random.randint(1,100))
urArray = myArray.copy()
myArray[-1] = -7
print("1st Array: "+str(myArray)+"\n"+"2nd Array: "+str(urArray))

Result Wrote:$ ./test.py
1st Array: [32, 67, 97, 67, 5, 23, 53, 33, 4, -7]
2nd Array: [32, 67, 97, 67, 5, 23, 53, 33, 4, 63]



RE: De grote programmeer opdracht 2016! - PingWing - 08-10-2016

Voor PHP:

PHP Code:
$arr1 = array();
for(
$i 0$i 10$i++){
   $arr1[] = rand(099);
}
$arr2 $arr1;
$arr1[9] = -7;
var_dump($arr1,$arr2); 



Code:
# Result:
array (size=10)
 0 => int 93
 1 => int 80
 2 => int 53
 3 => int 49
 4 => int 85
 5 => int 87
 6 => int 52
 7 => int 33
 8 => int 39
 9 => int -7
array (size=10)
 0 => int 93
 1 => int 80
 2 => int 53
 3 => int 49
 4 => int 85
 5 => int 87
 6 => int 52
 7 => int 33
 8 => int 39
 9 => int 14



RE: De grote programmeer opdracht 2016! - Archu - 08-10-2016

Fur Java:

Code:
public class CopyArrays {

    static ArrayList arr1 = new ArrayList();
    static ArrayList arr2;

    private static ArrayList<Integer> randomize(ArrayList<Integer> array) {

        Integer cnt1;
        Random rndm = new Random();

        for (int i = 0; i < 10; i++) {
            cnt1 = rndm.nextInt(100);
            array.add(cnt1);
        }
        return array;
    }

    public static void main(String[] args) {

        randomize(arr1);
        arr2 = (ArrayList<String>) arr1.clone();
        arr1.set(9, "-7");

        System.out.println("Array 1: " + arr1 + "\n" + "Array 2: " + arr2);
    }
}


Result:
Quote:Array 1: [77, 38, 3, 37, 58, 48, 27, 18, 16, -7]

Array 2: [77, 38, 3, 37, 58, 48, 27, 18, 16, 42]



RE: De grote programmeer opdracht 2016! - Sacha - 08-10-2016

PHP Code:
#include <stdlib.h>
#include <stdio.h>
#include <time.h>

int main()
{
  
int myArray[10];
  
int urArray[10];
  
int ij;
  
time_t t;

  
/* Seed with me */
  
srand((unsignedtime(&t));

  for (
i=0;i<10;i++) {
    
myArray] = rand() % 100;
  }

  for (
i=0;i<10;i++) {
    
urArray[i] = myArray[i];
  }

  
myArray[9] = -7;

  
printf("1st Array: ");
  for (
j=0;j<10;j++) {
    
printf("%d ",myArray[j]);
  }
  
printf("\n");

  
printf("2nd Array: ");
  for (
j=0;j<10;j++) {
    
printf("%d ",urArray[j]);
  }
  
printf("\n");



Code:
$ ./a.out
1st Array: 39 63 41 96 97 47 79 45 30 -7
2nd Array: 39 63 41 96 97 47 79 45 30 31



RE: De grote programmeer opdracht 2016! - Sacha - 08-11-2016

Een externe contributie:

PHP Code:
#!/bin/bash

declare -a myArray
for i in `seq 0 9`; do myArray[$i]=$(($(random -er 100;echo $?)+1)); done
for index in "${!myArray[@]}"; do newArray[$index]=${myArray[$index]}; done
myArray
[$index]=-7;
B=$index;
A=0;echo -"1st Array:[";for index in "${!myArray[@]}"; do echo -${myArray[$index]}; if [ $A -lt $B ]; then echo -","fi;A=$(($A+1)); done; echo \];
A=0;echo -"2nd Array:[";for index in "${!newArray[@]}"; do echo -${newArray[$index]}; if [ $A -lt $B ]; then echo -","fi;A=$(($A+1)); done; echo \];