3109 (dtest)

some ls-kind experiment

#!/bin/bash
#going through some tests with dirs
#todo basename $0, set scriptname from basename, switch case (if/elseif/else) ./dir/file
FILE=$1
DIR=`dirname $FILE`
FILES=`ls $DIR`

echo "Filename specified: $FILE"
echo "Parent directory: $DIR"

for f in $FILES; do
echo "- $f"
done

3107 (n-queen-problem, graphical)

graphical solution for the n-queen-problem in java

package nq2;

import java.util.Stack;
import comp102x.Canvas;
import comp102x.ColorImage;

public class NQueens {

    public static Stack<Integer> s = new Stack<Integer>();
    public static int n; 
    public static int total; 
    private static Canvas canvas;
    private static ColorImage board;
    private static int gridSize = 80;
    private static ColorImage queen = new ColorImage("/home/evemat/Dokumente/javaio/workspace/nq2/nq2/bq80.png");
    private static ColorImage wq = new ColorImage("/home/evemat/Dokumente/javaio/workspace/nq2/nq2/wq80.png");
    private static ColorImage[] queens;
    
    public NQueens(int size) {
        
        n = size;
        int iSize = gridSize*n;
        canvas = new Canvas(iSize+10, iSize+10);
        board = new ColorImage(iSize, iSize);
        queens = new ColorImage[n];
        for (int i = 0; i<iSize; i++)
            for (int j = 0; j<iSize; j++){
                int r = i/gridSize;
                int c = j/gridSize;
                if ((r+c)/2*2 == (r+c)) board.setRGB(i, j, 0, 0, 255);
                    else board.setRGB(i, j, 255, 255, 255);
                }
                
        for (int i=0; i<n; i++)
            queens[i] = new ColorImage(queen);
            
        canvas.add(board);
        displayI(wq, n+1, n+1);
    }
            
      //finds and prints out all solutions to the n-queens problem
    public static int solve(){
        
        int i = 0;   // i goes through each row to place a queen
        int x = 0;   // x goes through the columns within each row 
        total = 0;
    
        while ( i < n ) {        
            while (x < n) {
                moveI(wq, x, i);
                if(isConflict(i, x) == false){ 
                    s.push(x); // no conflict, push x
                    moveI(wq, n+1, n+1);
                    displayI(queens[i], x, i);
                    //was commented out
                    pause(200);
                    break; //break out of loop to next row
                }
                else 
                    x++;
            }
              
            if (s.isEmpty() == true) break;
              
            if (x >= n) {
                moveI(wq, n+1, n+1);
                x = s.pop() + 1;
                i--;
                removeI(queens[i]);
                //was commented out
                pause(200);
            }
            
            else {
                i++;
                x = 0;
            }
              
            if (s.size()==n){ 
                total++; 
                pause(200);
                System.out.println(total + ": " + s);
                //if (total == 1) printSolution(s);
                removeI(queens[n-1]);
                x = s.pop() + 1;
                i--;                    
            }
        } 
        return total; 
    }

    public static boolean isConflict(int row, int col){
        int diff = row-col;
        int sum = row+col;
        for (int i = 0; i < row; i++) {
            int t = s.get(i);
            if (t==col || i-t == diff || i+t == sum) return true;
          }
          return false;
    }
    
    private static void printSolution(Stack<Integer> s) {
        for (int i = 0; i < s.size(); i ++) {
            for (int j = 0; j < s.size(); j ++) {
                if (j == s.get(i))
                    System.out.print("Q ");
                else
                    System.out.print("* ");
            }//for
            System.out.println();
        }//for
        System.out.println();  
    }//printSolution()

    public static void displayI(ColorImage image, int x, int y){
      x = x * gridSize;
      y = y * gridSize;
      canvas.add(image, x, y);
    }
    
    public static void removeI(ColorImage image){
       canvas.remove(image);
    }
    
    public static void moveI(ColorImage image, int x, int y){
        image.setX(x*gridSize);
        image.setY(y*gridSize);
    }
  
    public static void pause(int sleepTime){
        try {
            Thread.sleep(sleepTime);
        }catch (InterruptedException e) {
            System.err.println("Error in running animation!");
            System.exit(-1);
        }
    }

    public void demo() {
        //NQueens nQ = new NQueens(n);

        int number = solve();
        System.out.println("There are " + number + " solutions to the " + n + "-queens problem.");
    }
	public static void main (String[] args)
	{
	int ein = 0;
	ein = eingabe.readInt ("anzahl queens:");
	NQueens nQ = new NQueens (ein);
	nQ.demo();
	}
}

3105 (array histogram special case max 3)

public class hist
{
    
    public static int[] histogram (int [][] arrayA)
    {  // nested for loop to go through the array.
        int max = 0;
       for ( int row = 0; row<arrayA.length; row++)
		{
           for ( int col=0; col < arrayA[row].length; col++)
			{

               if ( arrayA[row][col]> max )
				{
                   max = arrayA[row][col];
            	}
        	}
    	}
	System.out.println("max:"+max);
    int histA[] = new int [max+1];
	int lauf = 0;
	for (lauf=0;lauf<max+1;lauf++)
	{
    for ( int row = 0; row<arrayA.length; row++)
		{
           for ( int col=0; col < arrayA[row].length; col++)
			{
				if (arrayA[row][col] == lauf)
				{
					histA[lauf]++;
				}
               //histA[arrayA[row][col]]++;
            }
        }
	}
        //System.out.println(histA);
        return histA;
    }
	public static void main (String[]args)
    {
        // declearing and initializing a 2D array.
        int [][] arrayA = {{0,1,2},{3,0,2},{3,3,0}};
		int erg[]={};
        erg = histogram(arrayA);
		for (int i = 0; i<=3; i++)
		{
			System.out.println(i+":"+erg[i]);
		}

    }
}

3103 (promotion, fellows)

item no
https://courses.edx.org/certificates/35e679b8e0fd4d56a660a3be3c9d1630?lipi=urn%3Ali%3Apage%3Ad_flagship3_profile_view_base%3Bbq1UXR60Tja2yOnKqfIRoA%3D%3D 1
https://courses.edx.org/certificates/86822b6b06d243cf8b6ca1cf411dd655?lipi=urn%3Ali%3Apage%3Ad_flagship3_profile_view_base%3Bbq1UXR60Tja2yOnKqfIRoA%3D%3D 2
https://www.serverproject.de/ 3
https://www.linkedin.com/in/matthias-evering-08824b9b/ 4
https://configedit.wordpress.com/ 0

3101 (some convertingtools)

4 javapieces int_to_bin/bin_to_int/int_to_hex/hex_to_int

int_to_bin

class dec_bin
{
public static String b0(int n) {

        if (n == 0) return "0";
        if (n == 1) return "1";
        
        return b0(n / 2) + (n % 2);
}
public static void main (String[] args)
{
int ein=0;
String erg="";
ein=eingabe.readInt("Integer:");
erg= b0(ein);
System.out.println(erg);
}
}

bin_to_int

class bin_dec
{
public static void main (String[] args)
{
String ein = "";
int foo=0;
ein=eingabe.readString("String(bin):");
foo = Integer.parseInt(ein, 2);
System.out.println(foo);
}
}

int_to_hex

class dec_hex
{
public static String intToHexStr(int i){
    return "0x"+String.format("%2s", Integer.toHexString(i)).replace(' ', '0');
}
public static void main (String[] args)
{
int ein=0;
String erg="";
ein=eingabe.readInt("Integer:");
erg=intToHexStr(ein);
System.out.println(erg);
}
}

hex_to_int

class hex_dec
{
public static void main (String[] args)
{
String ein = "";
String foo="";
String bar="";
int value=0;
ein=eingabe.readString("String(hex):");
foo=ein.substring(0,2);
if (foo.equals("0x")) { bar = ein.substring(2); }
else { bar = ein; }
value = Integer.parseInt(bar, 16);
System.out.println(value);
}
}

3097

drei 3D-arrays bilden eine entwicklung ueber die zeit ab. the values were coincidentally chosen (random), ausser des startpunktes einer 2D-nullkoordinate.

class time
{
	//main method, arguments may be passed on commandline execution
	public static void main(String args[])
	{
		// declare and initialize 4D array
		int arr[][][][] = {
								{
									{ {0,0,0},{2,6,6},{7,4,2} },
									{ {0,0,0},{9,6,2},{9,1,3} },
									{ {0,0,0},{4,5,6},{2,5,2} }
								},
								{
									{ {0,4,2},{2,6,1},{9,3,1} },
									{ {3,7,9},{9,6,2},{0,1,5} },
									{ {5,8,4},{4,7,6},{6,5,2} }
								},
								{
									{ {7,5,2},{2,6,2},{6,5,5} },
									{ {6,8,9},{7,5,2},{8,5,9} },
									{ {2,8,5},{3,7,7},{4,5,8} }
								}
							};
		// print time array in four nested for-loops
		for (int l = 0; l<3; l++)		
		{	
			//print 3D-element number
			System.out.println(l);
			for (int i=0; i< 3 ; i++)
			{
				for (int j=0; j < 3 ; j++)
				{
					for (int k=0; k < 3; k++)
					{
						//print element
						System.out.print(arr[l][i][j][k] + " ");
					}
					//print whitespaces
					System.out.print("     ");
				}
				//newline
				System.out.println();
			}
		}
	}
}

3083 (toodoo intro <1)

#comment
#freeze

#!/bin/bash
#base href = https://www.serverproject.de
#this is toodoo intro version < 1
#it is evaluation, examination, experiment and exercise
#the code is commented in english
#fragile || predictable
#temp

#retrieve name
var0=`basename "$0"`;
#output name
echo $var0;
#blob
URL=https://github.com/ewingson/edx-02-intro/blob/master/intro

#retrieve arguments to var1 to var5
var1=$1;
var2=$2;
var3=$3;
var4=$4;
var5=$5;

#COUNTER (not yet used)
#count[1]=$var1;
#count[2]=$var2;
#count[3]=$var3;
#count[4]=$var4;
#count[5]=$var5;

#alternative extreme array conscience programming (rule conform)
self[0]=$var1
self[1]=$var2
self[2]=$var3
self[3]=$var4
self[4]=$var5

#output and count arguments
j=0
for i in ${self[@]}; do
echo $i
j+=1
done
slength="$j"
size=${#slength}
#echo $COUNTER

#toodoo
#we must check if arguments are set

#boole b1 must be set if argument $1 exists (!-ne)
if [ -n $var1 ]
  then
        b1=false
else
	b1=true 
fi
#boole b2
if [ -n $var2 ]
  then
        b2=false
else
	b2=true 
fi
#boole b3
if [ -n $var3 ]
  then
        b3=false
else
	b3=true 
fi
#boole b4
if [ -n $var4 ]
  then
        b4=false
else
	b4=true 
fi
#boole b5
if [ -n $var5 ]
  then
        b5=false
else
	b5=true 
fi
#now we have all we need

#check the five boolean
if [[ $b1=true || $b2=true || $b3=true || $b4=true || $b5=true ]];
then flag=1
else flag=0
fi
    if [ $flag=1 ]
    then
#whether exists or not output status and argument 
            if [ $b1=true ]
            then
            echo argument ${var1} exists
#other case
            else
            echo argument ${var1} does not exist
            fi
            if [ $b2=true ]
            then
            echo argument ${var2} exists
            else
            echo argument ${var2} does not exist
            fi
		    if [ $b3=true ]
            then
            echo argument ${var3} exists
            else
            echo argument ${var3} does not exist
            fi
            if [ $b4=true ]
            then
            echo argument ${var4} exists
            else
            echo argument ${var4} does not exist
            fi
            if [ $b5=true ]
            then
            echo argument ${var5} exists
            else
            echo argument ${var5} does not exist
            fi
    else
#error message and exit if invalid number of arguments
    echo "Arguments are zero or > 5"
#exit 1
    exit 1
    fi
#array syntax is variable[index]=$value
arrlength=$size-1;
echo $size;

#toodoo
#we want printf(%d total %d arguments, $size, $arrlength);

#toodoo
#direction = (0 || 1 || 2038 || x203x || 4 || (5 && true))

#SI-Einheiten

#SI seconds for light to sun
sun=8*60
#SI seconds for lifetime sun
runtime=5000000000*365*24*60*60
#SI speed of light in meter/second
lightspeed=299792458
#SI distance light makes in a year in meter/year
lightyear=9460730472580800
#alphabet
alphabet="abcdefghijklmnopqrstuvwxyz"

#if (variable0=true)
#{
#ping 2a01:488:42:1000:50ed:854a:cc:d5a8
#}

#exit 0
exit 0

https://github.com/ewingson/edx-02-intro

3080 (ex*)

experiment or exercise ?

<a href = 'https://github.com/'>https://github.com/</a> | <a href = 'https://guides.github.com/activities/hello-world/'>https://guides.github.com/activities/hello-world/</a><br />

<a href = 'https://www.geeksforgeeks.org/'>https://www.geeksforgeeks.org/</a> | <a href = 'https://ide.geeksforgeeks.org/index.php'>https://ide.geeksforgeeks.org/index.php</a><br />

3078 (SELECT * FROM *)

k.i. theoretisch

item word
https://www.google.com ball
https://www.google.nl pons
https://www.google.es quicksort
https://www.google.to speed
https://www.google.com.tw meditation
https://www.google.com.hk vengeance
https://www.google.mg unity
https://www.google.de useless stuff

k.i. praktisch

item association
http://www.datakind.org/ relax
https://dssg-berlin.org/ link
https://ai4good.org/ global
https://www.unglobalpulse.org/ local
http://www.globalforestwatch.org/ forest
https://gamaya.com/ peace
https://www.foodtracks.de/en/ share
https://sourceforge.net/speedtest/ topic
https://sourceforge.net/projects/kibirth/ game
https://cambridgeanalytica.org/ collect

source: https://perspective-daily.de/article/442/sJ1IaeFE