Răsfoiți Sursa

nommal ufgabn

git-svn-id: http://repo.nplusc.de/svn/iZink@171 8b19561d-0d00-6744-8ac1-9afc8f58a8aa
masterX244 11 ani în urmă
părinte
comite
1f3d2bd4e5

+ 59 - 0
HHN/%C3%9C2/src/A.java

@@ -0,0 +1,59 @@
+/*
+ * To change this template, choose Tools | Templates
+ * and open the template in the editor.
+ */
+
+/**
+ *
+ * @author LH
+ */
+// H  e  l    l   o      W  o  r   l    d  !
+//72,101,108,108,111,32,87,111,114,108,100 33
+import static java.lang.Integer.*;
+class A
+{
+    public static void main(String[] args)
+    {
+        /*while(Math.random()>0)
+        {
+            for(long l=0;l!=-1;l++)
+            {
+                System.out.println("1234567890");
+            }
+        }*/
+    }
+    
+    static String longestWord(String... s)//hack with the variable args length to get a array even with a sinle string
+    {
+        s = s[0].split(" ");
+        for (String l : s)
+        {
+            if (l.length() > s[0].length())
+            {
+                s[0] = l; //putting the longest element at position 0 of the array
+            }
+        }
+        return s[0];
+    }
+}
+   /* public static void main(String[] args)
+    {
+        Integer a=0,b=a++,e=a++;  // making a 0 a 1 and a 2 which is required later;
+        String c=e.toString(),d=b.toString(),l=((char)parseInt(d+c+c+d+c+c+d+d,a)+c).substring(0, e);  //
+        
+        String H = l+((char)parseInt(d+c+d+d+c+d+d+d,a))+  // binärwerte erzeugen und in char wandeln
+                ((char)parseInt(d+c+c+d+d+c+d+c,a))+
+                l+
+                l+
+                (char)parseInt(d+c+c+d+c+c+c+c,a)+
+                (char)parseInt(d+d+c+d+d+d+d+d,a)+
+                (char)parseInt(d+c+d+c+d+c+c+c,a)+
+                (char)parseInt(d+c+c+d+c+c+c+c,a)+
+                (char)parseInt(d+c+c+c+d+d+c+d,a)+l+
+                //(char)parseInt(d+c+c+d+c+c+d+d,a)+
+                (char)parseInt(d+c+c+d+d+c+d+d,a)+
+                (char)parseInt(d+d+c+d+d+d+d+c,a)
+                ;
+        System.out.println(H.substring(e));  //obvious
+    }*/
+//}

+ 13 - 0
HHN/%C3%9C2/src/Maeander.java

@@ -0,0 +1,13 @@
+/*
+ * To change this template, choose Tools | Templates
+ * and open the template in the editor.
+ */
+
+/**
+ *
+ * @author LH
+ */
+public class Maeander
+{
+    
+}

+ 161 - 0
HHN/%C3%9C2/src/Matrix.java

@@ -0,0 +1,161 @@
+/*
+ * To change this template, choose Tools | Templates
+ * and open the template in the editor.
+ */
+
+/**
+ *
+ * @author LH
+ */
+public class Matrix
+{
+    
+    private double[][] matrixdata;
+    
+    public Matrix(int height, int width)
+    {
+        matrixdata = new double[height][width];
+    }
+    
+    public double getEntry(int height,int width)
+    {
+        
+        return matrixdata[height-1][width-1];
+    }
+    
+    
+    public void setEntry(int height,int width,double value)
+    {
+        matrixdata[height-1][width-1]=value;
+    }
+    
+    public int getHeight()
+    {
+        return matrixdata.length;
+    }
+    
+    public int getWidth()
+    {
+        if(getHeight()>0)
+        {
+            return matrixdata[0].length;
+        }
+        return 0;//wenn keine zeilen dann auch keine spalten....
+    }
+    
+    public Matrix add(Matrix m2)
+    {
+        
+        if(m2.getHeight()==getHeight()&&m2.getWidth()==getWidth())
+        {
+            int height = getHeight();
+            int width = getWidth();
+            int cells = height*width;
+            Matrix o = new Matrix(height,width);
+            for (int i = 0; i < cells; i++)
+            {
+                
+                
+                int row = i/width+1;
+                int col = i%width+1;
+                o.setEntry(row,col, m2.getEntry(row, col)+getEntry(row, col));
+            }
+            return o;
+        }
+        return null;//keine add mögl
+    }
+    
+    public Matrix multiply(Matrix m2)
+    {
+        
+        if(m2.getHeight()==getWidth())
+        {
+            
+            int height = getHeight();
+            int width = m2.getWidth();
+            Matrix o = new Matrix(height,m2.getWidth());
+            for (int i = 0; i < height; i++)
+            {
+                for (int j = 0; j <width; j++)
+                {
+                    double cc = 0;
+                    for (int k = 0; k < getWidth(); k++)
+                    {
+                        System.out.print((i+1)+"|"+(j+1)+"|"+(k+1));
+                        double mt = m2.getEntry(k+1,j+1);
+                        cc=cc+(getEntry(i+1, k+1)*mt);
+                        System.out.println("|"+mt+"|"+cc);
+                    }
+                    o.setEntry(i+1, j+1, cc);
+                }
+            }
+            return o;
+        }
+        return null;//keine add mögl
+    }
+    
+    
+    public String toString()
+    {
+        String result = "";
+        String zeile = "";
+        String klammerauf= "│",klammerzu="│";
+        for (int i = 0; i < matrixdata.length; i++)
+        {
+            klammerauf= "│";
+            klammerzu="│";
+            if(i==matrixdata.length-1)
+            {
+                klammerauf="└";
+                klammerzu="┘";
+            }
+            if(i==0)
+            {
+                klammerauf="┌";
+                klammerzu="┐";
+            }
+            double[] linedata = matrixdata[i];
+            zeile=klammerauf;
+            for (double zelle : linedata)
+            {
+                zeile+=zelle+"\t";
+            }
+            
+            zeile=zeile.trim();
+            zeile+=klammerzu;
+            result+=zeile+"\n";
+        }
+ 
+        return result;
+    }
+    
+    
+    
+    public static void main(String[] args) throws Exception
+    {
+        Matrix m = new Matrix(4,4);
+        
+        
+        m.setEntry(1, 1, 0);
+        m.setEntry(1, 2, 1);
+        m.setEntry(1, 3, 0);
+        m.setEntry(1, 4, 0);
+        
+        m.setEntry(2, 1, 0);
+        m.setEntry(2, 2, 0);
+        m.setEntry(2, 3, 1);
+        m.setEntry(2, 4, 0);
+        
+        m.setEntry(3, 1, 0);
+        m.setEntry(3, 2, 0);
+        m.setEntry(3, 3, 1);
+        m.setEntry(3, 4, 0);
+        
+        m.setEntry(4, 1, -1);
+        m.setEntry(4, 2, 1);
+        m.setEntry(4, 3, -1);
+        m.setEntry(4, 4, 3);
+        InteractiveIO.write(m.multiply(m)+"");
+    }
+    
+}

+ 47 - 0
HHN/%C3%9C2/src/PrimeFrac.java

@@ -0,0 +1,47 @@
+
+
+/*
+ * To change this template, choose Tools | Templates
+ * and open the template in the editor.
+ */
+
+/**
+ *
+ * @author LH
+ */
+public class PrimeFrac
+{
+    public static void main(String[] args)
+    {
+        Rational[] prg = 
+            {new Rational(3,11),new Rational(847,45),new Rational(143,6),
+            
+            
+            new Rational(7,3),new Rational(10,91),new Rational(3,7),
+            
+            
+            new Rational(36,325),new Rational(1,2),new Rational(36,5)
+            };
+        Rational b = new Rational(10,1);
+        System.out.println(0+"|"+b);
+        for (int i = 1; i < 10017; i++)
+        {
+            for (Rational r : prg)
+            {
+                Rational tmp = r.multiply(b);
+                if(tmp.isInteger())
+                {
+                    
+                    b=tmp;
+                    break; //ARSCHLOCH; hab dich vergessen und es hat nicht gefunzt...
+                }
+            }
+            System.out.println(i+"|"+b);
+            
+            
+            //Resultat= 105206017600756801139532489776611328125
+        }
+    
+        
+    }
+}

+ 117 - 0
HHN/%C3%9C2/src/Rational.java

@@ -0,0 +1,117 @@
+
+import java.math.BigDecimal;
+import java.math.BigInteger;
+
+/*
+ * To change this template, choose Tools | Templates
+ * and open the template in the editor.
+ */
+
+/**
+ *
+ * @author LH
+ */
+public class Rational extends Number
+{
+    private BigInteger za,ne;
+    
+    public Rational(int z,int n)
+    {
+        za=new BigInteger(z+"");
+        ne=new BigInteger(n+"");
+    }
+    public Rational(String z,String n)
+    {
+        za=new BigInteger(z);
+        ne=new BigInteger(n);
+    }
+    public Rational(BigInteger z, BigInteger n)
+    {
+        za=z;
+        ne=n;
+    }
+    
+    public Rational add(Rational r)
+    {
+        BigInteger ggt = ne.gcd(r.ne);
+        BigInteger gemNenner=ne.multiply(r.ne).divide(ggt);
+        BigInteger b1m = gemNenner.divide(ne);
+        BigInteger b2m = gemNenner.divide(r.ne);
+        BigInteger z = b1m.multiply(za).add(b2m.multiply(r.za));
+        BigInteger ktemp = z.gcd(gemNenner);
+        return new Rational(z.divide(ktemp),gemNenner.divide(ktemp));
+    }
+    public Rational subtract(Rational r)
+    {
+        BigInteger ggt = ne.gcd(r.ne);
+        BigInteger gemNenner=ne.multiply(r.ne).divide(ggt);
+        BigInteger b1m = gemNenner.divide(ne);
+        BigInteger b2m = gemNenner.divide(r.ne);
+        BigInteger z = b1m.multiply(za).subtract(b2m.multiply(r.za));
+        BigInteger ktemp = z.gcd(gemNenner);
+        return new Rational(z.divide(ktemp),gemNenner.divide(ktemp));
+    }
+    
+    public Rational multiply(Rational r)
+    {
+        BigInteger mz = za.multiply(r.za);
+        BigInteger mn = ne.multiply(r.ne);
+        BigInteger ktemp = mz.gcd(mn);
+        //System.out.println(">>>"+ktemp+"|"+mz.divide(ktemp)+"|"+mn.divide(ktemp));
+        return new Rational(mz.divide(ktemp),mn.divide(ktemp));
+    }
+    @Override
+    public String toString()
+    {
+        return za+(isInteger()?"/"+ne:"")+"";
+    }
+    
+    
+    public boolean isInteger()
+    {
+        return ne.intValue()==1;
+    }
+    
+    
+    
+    
+    //räzel für sie :P
+    //   import static java.lang.Integer.*;class A{public static void main(String[] args){Integer a=0,b=a++,e=a++;String c=e.toString(),d=b.toString(),l=((char)parseInt(d+c+c+d+c+c+d+d,a)+c).substring(0, e);String H = l+((char)parseInt(d+c+d+d+c+d+d+d,a))+((char)parseInt(d+c+c+d+d+c+d+c,a))+l+l+(char)parseInt(d+c+c+d+c+c+c+c,a)+(char)parseInt(d+d+c+d+d+d+d+d,a)+(char)parseInt(d+c+d+c+d+c+c+c,a)+(char)parseInt(d+c+c+d+c+c+c+c,a)+(char)parseInt(d+c+c+c+d+d+c+d,a)+l+(char)parseInt(d+c+c+d+d+c+d+d,a)+(char)parseInt(d+d+c+d+d+d+d+c,a);System.out.println(H.substring(e));}}
+    //   //was würde dieser codeschnipsel machen?
+    //   //und welche tricks benutz ich da (ps: das war im kurs schon dran :P)
+    //ende räzel
+    
+    
+    
+    
+    
+    //implementskram
+    @Override
+    public int intValue()
+    {
+         return za.divide(ne).intValue();
+    }
+
+    @Override
+    public long longValue()
+    {
+        return za.divide(ne).longValue();
+    }
+
+    @Override
+    public float floatValue()
+    {
+        BigDecimal za2=new BigDecimal(za);
+        BigDecimal ne2=new BigDecimal(ne);
+        return za2.divide(ne2).floatValue();
+    }
+
+    @Override
+    public double doubleValue()
+    {
+        BigDecimal za2=new BigDecimal(za);
+        BigDecimal ne2=new BigDecimal(ne);
+        return za2.divide(ne2).doubleValue();  
+    }
+    
+}

+ 12 - 19
HHN/%C3%9C2/src/Sin.java

@@ -9,31 +9,24 @@
  */
 public class Sin
 {
+
     public static void main(String[] args) throws Exception
     {
-        InteractiveIO.write(sin(Math.PI/2)+"");
+        InteractiveIO.write(sin(Math.PI / 2) + "");
     }
-    
+
     public static double sin(double x) throws Exception
     {
-        double acc = 0;
-        double r = 0;
-        double rprev=0;
-        double mdifference = 0.000_000_1;
-        double difference=1;
-        int i = 0;
-        InteractiveIO.write(x+"");
-        while(difference>mdifference)
+        int k = 0, n = 1000;
+        double maxError = 1e-10, sum = 0.0, xk = x;
+        while (Math.abs(xk) >= maxError && k <= n)
         {
-            rprev=r;
-            acc =(x*x)/((2*i)*(2*i+1));
-            r=Math.pow(1.0f, i)*acc;
-            InteractiveIO.write(r+"");
-            InteractiveIO.write(rprev+"");
-            InteractiveIO.write(acc+"");
-            InteractiveIO.write(i+"\nend of this loop run\n###########################");
-            difference=Math.abs(r-rprev);
+            sum += xk;
+            InteractiveIO.write("k: " + k + " xk: " + xk + " sum: " + sum);
+            k++;
+            xk = -xk * x * x / (2 * k) / (2 * k + 1);
         }
-        return r;
+        return sum + xk;
+
     }
 }