Physik-beschleunigung
-
Nobuo T schrieb:
Vielleicht peil ich ja diese Folge nicht, und die ist in wirklichkeit viel trickreicher, als sie mir auf den ersten Blick scheint, aber ... dafuer braucht man echt 1300 Zeilen code und mehrere durchgemachte Naechte? Hast du das in 65C816-Assembler oder Brainfuck geschrieben?
Wohl eher in Brainfuck 2D.
-
Ich habs in Delphi geschrieben. assembler kann ich auch, aber daswären mal mindestens 10000 Zeilen... Dadurch dass diese Folge irgendwie keinen festen Algorithmus hat oder ich ihn zumindest nicht sehe musste ich das alles in Teilalgorithmen strukturieren. das sind dann 1200 zeilen.Und das hat nur 12 Stunden gedauert
-
Da fehlt wohl der "mathematische Blick" - ich stell die Reihe mal in ternärer Form dar:
a1 = 13
a2 = 103
a3 = 11
a4 = 100
a5 = 101
a7 = 110
a8 = 111
...Erkennst du jetzt ein Muster?
-
Toddy schrieb:
Dadurch dass diese Folge irgendwie keinen festen Algorithmus hat oder ich ihn zumindest nicht sehe musste ich das alles in Teilalgorithmen strukturieren. das sind dann 1200 zeilen.Und das hat nur 12 Stunden gedauert
Ich glaube, deine Lösung ist viel zu kompliziert. Ich habe das in 5 Minuten in C++ geschrieben, mit ca. 20 Zeilen. Das kann in Delphi nicht viel mehr sein.
-
CStoll: 1.du hast a6 vergessen
2.Nein, eben nicht denn a9=30+33 a10=31+33 !a11=32+33! : nach deinem Algorithmus wäre a8=1000³ a9=1001³ a10=1010³ aber a11=1011->33+31+3^0 ist aber nicht RICHTIG. Das war auch bei mir das Problem... Außer jemand findet wirklich noch einen algorithmus der 100% richtig ist
.
Hier zur Sicherheit noch ein paar Glieder: a12=30+31+3^3 a13=30+32+3^3 a14=31+32+3^3 a15=30+31+32+33 a16=3^4...Bitte sagt mir das wenn was falsch ist.
-
Wie weit war denn die Reihe gegeben? Und solltest du tatsächlich das Bildungsgesetz selber herleiten?
(PS: ich hab' a6 nicht vergessen, sondern übersprungen
-
Ich sollte eigentlich nur das 100.te Glied a100 berechnen.
-
Toddy schrieb:
CStoll: 1.du hast a6 vergessen
2.Nein, eben nicht denn a9=30+33 a10=31+33 !a11=32+33! : nach deinem Algorithmus wäre a8=1000³ a9=1001³ a10=1010³ aber a11=1011->33+31+3^0 ist aber nicht RICHTIG. Das war auch bei mir das Problem... Außer jemand findet wirklich noch einen algorithmus der 100% richtig ist
.
Hier zur Sicherheit noch ein paar Glieder: a12=30+31+3^3 a13=30+32+3^3 a14=31+32+3^3 a15=30+31+32+33 a16=3^4...Bitte sagt mir das wenn was falsch ist.
Sind die Glieder ab a12 noch in der Aufgabe gegeben oder entsprechen sie deiner Lösung?
tt
-
Meine Kursleiterin hat die Glieder bis zum 16. aufgeschrieben.
-
Irgendwie hat sie dabei a11 und a12 vertauscht, da bin ich mir ziemlich sicher.
-
es könnte sein schließlich ist sie auch en bissl verpeilt aber eigentlich ganz nett..
-
MFK schrieb:
Toddy schrieb:
Dadurch dass diese Folge irgendwie keinen festen Algorithmus hat oder ich ihn zumindest nicht sehe musste ich das alles in Teilalgorithmen strukturieren. das sind dann 1200 zeilen.Und das hat nur 12 Stunden gedauert
Ich glaube, deine Lösung ist viel zu kompliziert. Ich habe das in 5 Minuten in C++ geschrieben, mit ca. 20 Zeilen. Das kann in Delphi nicht viel mehr sein.
Stimmt, obwohl eher 10 Zeilen in 10 Minuten:
#include <iostream> int a_i( int x ) { int erg = 0; for( int faktor = 1; x; x /= 2, faktor *= 3 ) if( x % 2 ) erg += faktor; return erg; } int main() { std::cout << "Die Loesung fuer a100 ist: " << a_i( 100 ) << std::endl; return 0; }
Aber mal im Ernst, was steht in den 1200 Zeilen von Toddy?
Gruß
Werner
-
Mal ne Frage:Was bedeutet der Begriff
if( x % 2 )
? Wird das abgelehnt wenn x modulo 2 gleich 0 ist?
Außerdem hab ich ihr das Problem nochmal gemeldet und sie wollte da nochmal nachschauen.Übrigens,ich habe eure Lösung natürlich auch als Programm (Delphi, kann auch c++ aber egal) geschrieben, und sogar mit variabler Basis und Variablen Index
:
procedure TForm1.Button1Click(Sender: TObject); var n,b,a,x,arrayzahl,exp,Rest,Erg:Integer; function Potenz(Basis: Integer; Exponent: Integer): Integer; begin if Exponent > 0 then Result := Basis * Potenz(Basis, Exponent - 1) else Result := 1; end; begin a:=StrToInt(Edit1.text); n:=StrToInt(Edit2.text); b:=n; if n<1 then begin ShowMessage('Kleinstes Element ist 1!'); exit; end; erg:=0; exp:=0; x:=0; if b=1 then begin Edit3.text:=IntToStr(a)+'^0'; Edit4.text:=IntToStr(1); exit; end; while x<>1 do begin x:=b div 2; b:=x; exp:=exp+1; end; Rest:=n-Potenz(2,exp); b:=Rest; Edit3.text:=IntToStr(a)+'^'+IntToStr(exp); erg:=Potenz(a,exp); while Rest<>0 do begin exp:=0; x:=0; while (x<>1) and (b<>1) do begin x:=b div 2; b:=x; exp:=exp+1; end; Rest:=Rest-Potenz(2,exp); b:=Rest; Edit3.text:=Edit3.text+'+'+IntToStr(a)+'^'+IntToStr(exp); erg:=erg+Potenz(a,exp); end; Edit4.text:=IntToStr(erg); end; procedure TForm1.Button2Click(Sender: TObject); begin close; end;
Hier zur Krönung noch die 1000 Zeilen:
procedure TForm1.Button1Click(Sender: TObject); var n,b,a,x,exp,counter,Restsub,h1,h2,h3,h4,h5,h6,h7:Integer;Rest,Erg:Real; function Potenz(Basis: Extended; Exponent: Extended): Extended; begin if Exponent > 0 then Result := Basis * Potenz(Basis, Exponent - 1) else Result := 1; end; function Test3(exp:Integer):Integer; var p1,p2,Res:Integer; begin Res:=1; p1:=0; p2:=1; repeat if p2=exp-1 then begin inc (p1); p2:=p1+1; end else inc (p2); inc (Res); until (p2=exp-1) and (p1=exp-2); Result:=Res; end; function Test4(exp:Integer):Integer; var p1,p2,p3,Res:Integer; begin Res:=1; p1:=0; p2:=1; p3:=2; repeat if (p2=exp-2) and (p3=exp-1) then begin inc (p1); p2:=p1+1; p3:=p1+2; end else if p3=exp-1 then begin inc (p2); p3:=p2+1; end else inc (p3); inc (Res); until (p1=exp-3) and (p2=exp-2) and (p3=exp-1); Result:=Res; end; function Test5(exp:Integer):Integer; var p1,p2,p3,p4,Res:Integer; begin Res:=1; p1:=0; p2:=1; p3:=2; p4:=3; repeat if (p2=exp-3) and (p3=exp-2) and (p4=exp-1) then begin inc (p1); p2:=p1+1; p3:=p1+2; p4:=p1+3; end else if (p3=exp-2) and (p4=exp-1) then begin inc (p2); p3:=p2+1; p4:=p2+2; end else if p4=exp-1 then begin inc (p3); p4:=p3+1; end else inc (p4); inc (Res); until (p1=exp-4) and (p2=exp-3) and (p3=exp-2) and (p4=exp-1); Result:=Res; end; function Test6(exp:Integer):Integer; var p1,p2,p3,p4,p5,Res:Integer; begin Res:=1; p1:=0; p2:=1; p3:=2; p4:=3; p5:=4; repeat if (p2=exp-4) and (p3=exp-3) and (p4=exp-2) and (p5=exp-1) then begin inc (p1); p2:=p1+1; p3:=p1+2; p4:=p1+3; p5:=p1+4; end else if (p3=exp-3) and (p4=exp-2) and (p5=exp-1) then begin inc (p2); p3:=p2+1; p4:=p2+2; p5:=p2+3; end else if (p4=exp-2) and (p5=exp-1) then begin inc (p3); p4:=p3+1; p5:=p3+2; end else if p5=exp-1 then begin inc (p4); p5:=p4+1; end else inc (p5); inc (Res); until (p1=exp-5) and (p2=exp-4) and (p3=exp-3) and (p4=exp-2) and (p5=exp-1); Result:=Res; end; function Test7(exp:Integer):Integer; var p1,p2,p3,p4,p5,p6,Res:Integer; begin Res:=1; p1:=0; p2:=1; p3:=2; p4:=3; p5:=4; p6:=5; repeat if (p2=exp-5) and (p3=exp-4) and (p4=exp-3) and (p5=exp-2) and (p6=exp-1) then begin inc (p1); p2:=p1+1; p3:=p1+2; p4:=p1+3; p5:=p1+4; p6:=p1+5; end else if (p3=exp-4) and (p4=exp-3) and (p5=exp-2) and (p6=exp-1) then begin inc (p2); p3:=p2+1; p4:=p2+2; p5:=p2+3; p6:=p2+4; end else if (p4=exp-3) and (p5=exp-2) and (p6=exp-1) then begin inc (p3); p4:=p3+1; p5:=p3+2; p6:=p3+3; end else if (p5=exp-2) and (p6=exp-1) then begin inc (p4); p5:=p4+1; p6:=p4+2; end else if p6=exp-1 then begin inc (p5); p6:=p5+1; end else inc (p6); inc (Res); until (p1=exp-6) and (p2=exp-5) and (p3=exp-4) and (p4=exp-3) and (p5=exp-2) and (p6=exp-1); Result:=Res; end; function Test8(exp:Integer):Integer; var p1,p2,p3,p4,p5,p6,p7,Res:Integer; begin Res:=1; p1:=0; p2:=1; p3:=2; p4:=3; p5:=4; p6:=5; p7:=6; repeat if (p2=exp-6) and (p3=exp-5) and (p4=exp-4) and (p5=exp-3) and (p6=exp-2) and (p7=exp-1) then begin inc (p1); p2:=p1+1; p3:=p1+2; p4:=p1+3; p5:=p1+4; p6:=p1+5; p7:=p1+6; end else if (p3=exp-5) and (p4=exp-4) and (p5=exp-3) and (p6=exp-2) and (p7=exp-1) then begin inc (p2); p3:=p2+1; p4:=p2+2; p5:=p2+3; p6:=p2+4; p7:=p2+5; end else if (p4=exp-4) and (p5=exp-3) and (p6=exp-2) and (p7=exp-1) then begin inc (p3); p4:=p3+1; p5:=p3+2; p6:=p3+3; p7:=p3+4; end else if (p5=exp-3) and (p6=exp-2) and (p7=exp-1) then begin inc (p4); p5:=p4+1; p6:=p4+2; p7:=p4+3; end else if (p6=exp-2) and (p7=exp-1) then begin inc (p5); p6:=p5+1; p7:=p5+2; end else if p7=exp-1 then begin inc (p6); p7:=p6+1; end else inc (p7); inc (Res); until (p1=exp-7) and (p2=exp-6) and (p3=exp-5) and (p4=exp-4) and (p5=exp-3) and (p6=exp-2) and (p7=exp-1); Result:=Res; end; function Test9(exp:Integer):Integer; var p1,p2,p3,p4,p5,p6,p7,p8,Res:Integer; begin Res:=1; p1:=0; p2:=1; p3:=2; p4:=3; p5:=4; p6:=5; p7:=6; p8:=7; repeat if (p2=exp-7) and (p3=exp-6) and (p4=exp-5) and (p5=exp-4) and (p6=exp-3) and (p7=exp-2) and (p8=exp-1) then begin inc (p1); p2:=p1+1; p3:=p1+2; p4:=p1+3; p5:=p1+4; p6:=p1+5; p7:=p1+6; p8:=p1+7; end else if (p3=exp-6) and (p4=exp-5) and (p5=exp-4) and (p6=exp-3) and (p7=exp-2) and (p8=exp-1) then begin inc (p2); p3:=p2+1; p4:=p2+2; p5:=p2+3; p6:=p2+4; p7:=p2+5; p8:=p2+6; end else if (p4=exp-5) and (p5=exp-4) and (p6=exp-3) and (p7=exp-2) and (p8=exp-1) then begin inc (p3); p4:=p3+1; p5:=p3+2; p6:=p3+3; p7:=p3+4; p8:=p3+5; end else if (p5=exp-4) and (p6=exp-3) and (p7=exp-2) and (p8=exp-1) then begin inc (p4); p5:=p4+1; p6:=p4+2; p7:=p4+3; p8:=p4+4; end else if (p6=exp-3) and (p7=exp-2) and (p8=exp-1) then begin inc (p5); p6:=p5+1; p7:=p5+2; p8:=p5+3; end else if (p7=exp-2) and (p8=exp-1) then begin inc (p6); p7:=p6+1; p8:=p6+2; end else if p8=exp-1 then begin inc (p7); p8:=p7+1; end else inc (p8); inc (Res); until (p1=exp-8) and (p2=exp-7) and (p3=exp-6) and (p4=exp-5) and (p5=exp-4) and (p6=exp-3) and (p7=exp-2) and (p8=exp-1); Result:=Res; end; function Test10(exp:Integer):Integer; var p1,p2,p3,p4,p5,p6,p7,p8,p9,Res:Integer; begin Res:=1; p1:=0; p2:=1; p3:=2; p4:=3; p5:=4; p6:=5; p7:=6; p8:=7; p9:=8; repeat if (p2=exp-8) and (p3=exp-7) and (p4=exp-6) and (p5=exp-5) and (p6=exp-4) and (p7=exp-3) and (p8=exp-2) and (p9=exp-1) then begin inc (p1); p2:=p1+1; p3:=p1+2; p4:=p1+3; p5:=p1+4; p6:=p1+5; p7:=p1+6; p8:=p1+7; p9:=p1+8; end else if (p3=exp-7) and (p4=exp-6) and (p5=exp-5) and (p6=exp-4) and (p7=exp-3) and (p8=exp-2) and (p9=exp-1) then begin inc (p2); p3:=p2+1; p4:=p2+2; p5:=p2+3; p6:=p2+4; p7:=p2+5; p8:=p2+6; p9:=p2+7; end else if (p4=exp-6) and (p5=exp-5) and (p6=exp-4) and (p7=exp-3) and (p8=exp-2) and (p9=exp-1) then begin inc (p3); p4:=p3+1; p5:=p3+2; p6:=p3+3; p7:=p3+4; p8:=p3+5; p9:=p3+6; end else if (p5=exp-5) and (p6=exp-4) and (p7=exp-3) and (p8=exp-2) and (p9=exp-1) then begin inc (p4); p5:=p4+1; p6:=p4+2; p7:=p4+3; p8:=p4+4; p9:=p4+5; end else if (p6=exp-4) and (p7=exp-3) and (p8=exp-2) and (p9=exp-1) then begin inc (p5); p6:=p5+1; p7:=p5+2; p8:=p5+3; p9:=p5+4; end else if (p7=exp-3) and (p8=exp-2) and (p9=exp-1) then begin inc (p6); p7:=p6+1; p8:=p6+2; p9:=p6+3; end else if (p8=exp-2) and (p9=exp-1) then begin inc (p7); p8:=p7+1; p9:=p7+2; end else if p9=exp-1 then begin inc (p8); p9:=p8+1; end else inc (p9); inc (Res); until (p1=exp-9) and (p2=exp-8) and (p3=exp-7) and (p4=exp-6) and (p5=exp-5) and (p6=exp-4) and (p7=exp-3) and (p8=exp-2)and (p9=exp-1); Result:=Res; end; function L3(Rest:Real;a,exp:Integer):Integer; var p1,p2:Integer;Hauptrest:Real; begin p1:=0; p2:=1; Hauptrest:=Rest-exp-1; while Hauptrest>0 do begin if p2=exp-1 then begin inc (p1); p2:=p1+1; end else inc (p2); Hauptrest:=Hauptrest-1; end; Edit3.text:=IntToStr(a)+'^'+FloatToStr(p1)+'+'+IntToStr(a)+'^'+FloatToStr(p2)+'+'+IntToStr(a)+'^'+IntToStr(exp); erg:=Potenz(a,exp)+Potenz(a,p1)+Potenz(a,p2); Edit4.text:=FloatToStr(erg); end; function L4(Rest:Real;a,Restsub,exp:Integer):Integer; var p1,p2,p3:Integer;Hauptrest:Real; begin p1:=0; p2:=1; p3:=2; Hauptrest:=Rest-Restsub-1; if Hauptrest<0 then L3(Rest,a,exp); while Hauptrest>0 do begin if (p2=exp-2) and (p3=exp-1) then begin inc (p1); p2:=p1+1; p3:=p1+2; end else if p3=exp-1 then begin inc (p2); p3:=p2+1; end else inc (p3); Hauptrest:=Hauptrest-1; end; Edit3.text:=IntToStr(a)+'^'+FloatToStr(p1)+'+'+IntToStr(a)+'^'+FloatToStr(p2)+'+'+IntToStr(a)+'^'+FloatToStr(p3)+'+'+IntToStr(a)+'^'+IntToStr(exp); erg:=Potenz(a,exp)+Potenz(a,p1)+Potenz(a,p2)+Potenz(a,p3); Edit4.text:=FloatToStr(erg); end; function L5(Rest:Real;a,Restsub,exp:Integer):Integer; var p1,p2,p3,p4:Integer;Hauptrest:Real; begin p1:=0; p2:=1; p3:=2; p4:=3; Hauptrest:=Rest-Restsub-1; if Hauptrest<0 then L4(Rest,a,Restsub,exp); while Hauptrest>0 do begin if (p2=exp-3) and (p3=exp-2) and (p4=exp-1) then begin inc (p1); p2:=p1+1; p3:=p1+2; p4:=p1+3; end else if (p3=exp-2) and (p4=exp-1) then begin inc (p2); p3:=p2+1; p4:=p2+2; end else if p4=exp-1 then begin inc (p3); p4:=p3+1; end else inc (p4); Hauptrest:=Hauptrest-1; end; Edit3.text:=IntToStr(a)+'^'+FloatToStr(p1)+'+'+IntToStr(a)+'^'+FloatToStr(p2)+'+'+IntToStr(a)+'^'+FloatToStr(p3)+'+'+IntToStr(a)+'^'+FloatToStr(p4)+'+'+IntToStr(a)+'^'+IntToStr(exp); erg:=Potenz(a,exp)+Potenz(a,p1)+Potenz(a,p2)+Potenz(a,p3)+Potenz(a,p4); Edit4.text:=FloatToStr(erg); end; function L6(Rest:Real;a,Restsub,exp:Integer):Integer; var p1,p2,p3,p4,p5:Integer;Hauptrest:Real; begin p1:=0; p2:=1; p3:=2; p4:=3; p5:=4; Hauptrest:=Rest-Restsub-1; if Hauptrest<0 then L5(Rest,a,Restsub,exp); while Hauptrest>0 do begin if (p2=exp-4) and (p3=exp-3) and (p4=exp-2) and (p5=exp-1) then begin inc (p1); p2:=p1+1; p3:=p1+2; p4:=p1+3; p5:=p1+4; end else if (p3=exp-3) and (p4=exp-2) and (p5=exp-1) then begin inc (p2); p3:=p2+1; p4:=p2+2; p5:=p2+3; end else if (p4=exp-2) and (p5=exp-1) then begin inc (p3); p4:=p3+1; p5:=p3+2; end else if p5=exp-1 then begin inc (p4); p5:=p4+1; end else inc (p5); Hauptrest:=Hauptrest-1; end; Edit3.text:=IntToStr(a)+'^'+FloatToStr(p1)+'+'+IntToStr(a)+'^'+FloatToStr(p2)+'+'+IntToStr(a)+'^'+FloatToStr(p3)+'+'+IntToStr(a)+'^'+FloatToStr(p4)+'+'+IntToStr(a)+'^'+FloatToStr(p5)+'+'+IntToStr(a)+'^'+IntToStr(exp); erg:=Potenz(a,exp)+Potenz(a,p1)+Potenz(a,p2)+Potenz(a,p3)+Potenz(a,p4)+Potenz(a,p5); Edit4.text:=FloatToStr(erg); end; function L7(Rest:Real;a,Restsub,exp:Integer):Integer; var p1,p2,p3,p4,p5,p6:Integer;Hauptrest:Real; begin p1:=0; p2:=1; p3:=2; p4:=3; p5:=4; p6:=5; Hauptrest:=Rest-Restsub-1; if Hauptrest<0 then L6(Rest,a,Restsub,exp); while Hauptrest>0 do begin if (p2=exp-5) and (p3=exp-4) and (p4=exp-3) and (p5=exp-2) and (p6=exp-1) then begin inc (p1); p2:=p1+1; p3:=p1+2; p4:=p1+3; p5:=p1+4; p6:=p1+5; end else if (p3=exp-4) and (p4=exp-3) and (p5=exp-2) and (p6=exp-1) then begin inc (p2); p3:=p2+1; p4:=p2+2; p5:=p2+3; p6:=p2+4; end else if (p4=exp-3) and (p5=exp-2) and (p6=exp-1) then begin inc (p3); p4:=p3+1; p5:=p3+2; p6:=p3+3; end else if (p5=exp-2) and (p6=exp-1) then begin inc (p4); p5:=p4+1; p6:=p4+2; end else if p6=exp-1 then begin inc (p5); p6:=p5+1; end else inc (p6); Hauptrest:=Hauptrest-1; end; Edit3.text:=IntToStr(a)+'^'+FloatToStr(p1)+'+'+IntToStr(a)+'^'+FloatToStr(p2)+'+'+IntToStr(a)+'^'+FloatToStr(p3)+'+'+IntToStr(a)+'^'+FloatToStr(p4)+'+'+IntToStr(a)+'^'+FloatToStr(p5)+'+'+IntToStr(a)+'^'+FloatToStr(p6)+'+'+IntToStr(a)+'^'+IntToStr(exp); erg:=Potenz(a,exp)+Potenz(a,p1)+Potenz(a,p2)+Potenz(a,p3)+Potenz(a,p4)+Potenz(a,p5)+Potenz(a,p6); Edit4.text:=FloatToStr(erg); end; function L8(Rest:Real;a,Restsub,exp:Integer):Integer; var p1,p2,p3,p4,p5,p6,p7:Integer;Hauptrest:Real; begin p1:=0; p2:=1; p3:=2; p4:=3; p5:=4; p6:=5; p7:=6; Hauptrest:=Rest-Restsub-1; if Hauptrest<0 then L7(Rest,a,Restsub,exp); while Hauptrest>0 do begin if (p2=exp-6) and (p3=exp-5) and (p4=exp-4) and (p5=exp-3) and (p6=exp-2) and (p7=exp-1) then begin inc (p1); p2:=p1+1; p3:=p1+2; p4:=p1+3; p5:=p1+4; p6:=p1+5; p7:=p1+6; end else if (p3=exp-5) and (p4=exp-4) and (p5=exp-3) and (p6=exp-2) and (p7=exp-1) then begin inc (p2); p3:=p2+1; p4:=p2+2; p5:=p2+3; p6:=p2+4; p7:=p2+5; end else if (p4=exp-4) and (p5=exp-3) and (p6=exp-2) and (p7=exp-1) then begin inc (p3); p4:=p3+1; p5:=p3+2; p6:=p3+3; p7:=p3+4; end else if (p5=exp-3) and (p6=exp-2) and (p7=exp-1) then begin inc (p4); p5:=p4+1; p6:=p4+2; p7:=p4+3; end else if (p6=exp-2) and (p7=exp-1) then begin inc (p5); p6:=p5+1; p7:=p5+2; end else if p7=exp-1 then begin inc (p6); p7:=p6+1; end else inc (p7); Hauptrest:=Hauptrest-1; end; Edit3.text:=IntToStr(a)+'^'+FloatToStr(p1)+'+'+IntToStr(a)+'^'+FloatToStr(p2)+'+'+IntToStr(a)+'^'+FloatToStr(p3)+'+'+IntToStr(a)+'^'+FloatToStr(p4)+'+'+IntToStr(a)+'^'+FloatToStr(p5)+'+'+IntToStr(a)+'^'+FloatToStr(p6)+'+'+IntToStr(a)+'^'+FloatToStr(p7)+'+'+IntToStr(a)+'^'+IntToStr(exp); erg:=Potenz(a,exp)+Potenz(a,p1)+Potenz(a,p2)+Potenz(a,p3)+Potenz(a,p4)+Potenz(a,p5)+Potenz(a,p6)+Potenz(a,p7); Edit4.text:=FloatToStr(erg); end; function L9(Rest:Real;a,Restsub,exp:Integer):Integer; var p1,p2,p3,p4,p5,p6,p7,p8:Integer;Hauptrest:Real; begin p1:=0; p2:=1; p3:=2; p4:=3; p5:=4; p6:=5; p7:=6; p8:=7; Hauptrest:=Rest-Restsub-1; if Hauptrest<0 then L8(Rest,a,Restsub,exp); while Hauptrest>0 do begin if (p2=exp-7) and (p3=exp-6) and (p4=exp-5) and (p5=exp-4) and (p6=exp-3) and (p7=exp-2) and (p8=exp-1) then begin inc (p1); p2:=p1+1; p3:=p1+2; p4:=p1+3; p5:=p1+4; p6:=p1+5; p7:=p1+6; p8:=p1+7; end else if (p3=exp-6) and (p4=exp-5) and (p5=exp-4) and (p6=exp-3) and (p7=exp-2) and (p8=exp-1) then begin inc (p2); p3:=p2+1; p4:=p2+2; p5:=p2+3; p6:=p2+4; p7:=p2+5; p8:=p2+6; end else if (p4=exp-5) and (p5=exp-4) and (p6=exp-3) and (p7=exp-2) and (p8=exp-1) then begin inc (p3); p4:=p3+1; p5:=p3+2; p6:=p3+3; p7:=p3+4; p8:=p3+5; end else if (p5=exp-4) and (p6=exp-3) and (p7=exp-2) and (p8=exp-1) then begin inc (p4); p5:=p4+1; p6:=p4+2; p7:=p4+3; p8:=p4+4; end else if (p6=exp-3) and (p7=exp-2) and (p8=exp-1) then begin inc (p5); p6:=p5+1; p7:=p5+2; p8:=p5+3; end else if (p7=exp-2) and (p8=exp-1) then begin inc (p6); p7:=p6+1; p8:=p6+2; end else if p8=exp-1 then begin inc (p7); p8:=p7+1; end else inc (p8); Hauptrest:=Hauptrest-1; end; Edit3.text:=IntToStr(a)+'^'+FloatToStr(p1)+'+'+IntToStr(a)+'^'+FloatToStr(p2)+'+'+IntToStr(a)+'^'+FloatToStr(p3)+'+'+IntToStr(a)+'^'+FloatToStr(p4)+'+'+IntToStr(a)+'^'+FloatToStr(p5)+'+'+IntToStr(a)+'^'+FloatToStr(p6)+'+'+IntToStr(a)+'^'+FloatToStr(p7)+'+'+IntToStr(a)+'^'+FloatToStr(p8)+'+'+IntToStr(a)+'^'+IntToStr(exp); erg:=Potenz(a,exp)+Potenz(a,p1)+Potenz(a,p2)+Potenz(a,p3)+Potenz(a,p4)+Potenz(a,p5)+Potenz(a,p6)+Potenz(a,p7)+Potenz(a,p8); Edit4.text:=FloatToStr(erg); end; function L10(Rest:Real;a,Restsub,exp:Integer):Integer; var p1,p2,p3,p4,p5,p6,p7,p8,p9:Integer;Hauptrest:Real; begin p1:=0; p2:=1; p3:=2; p4:=3; p5:=4; p6:=5; p7:=6; p8:=7; p9:=8; Hauptrest:=Rest-Restsub-1; if Hauptrest<0 then L9(Rest,a,Restsub,exp); while Hauptrest>0 do begin if (p2=exp-8) and (p3=exp-7) and (p4=exp-6) and (p5=exp-5) and (p6=exp-4) and (p7=exp-3) and (p8=exp-2) and (p9=exp-1) then begin inc (p1); p2:=p1+1; p3:=p1+2; p4:=p1+3; p5:=p1+4; p6:=p1+5; p7:=p1+6; p8:=p1+7; p9:=p1+8; end else if (p3=exp-7) and (p4=exp-6) and (p5=exp-5) and (p6=exp-4) and (p7=exp-3) and (p8=exp-2) and (p9=exp-1) then begin inc (p2); p3:=p2+1; p4:=p2+2; p5:=p2+3; p6:=p2+4; p7:=p2+5; p8:=p2+6; p9:=p2+7; end else if (p4=exp-6) and (p5=exp-5) and (p6=exp-4) and (p7=exp-3) and (p8=exp-2) and (p9=exp-1) then begin inc (p3); p4:=p3+1; p5:=p3+2; p6:=p3+3; p7:=p3+4; p8:=p3+5; p9:=p3+6; end else if (p5=exp-5) and (p6=exp-4) and (p7=exp-3) and (p8=exp-2) and (p9=exp-1) then begin inc (p4); p5:=p4+1; p6:=p4+2; p7:=p4+3; p8:=p4+4; p9:=p4+5; end else if (p6=exp-4) and (p7=exp-3) and (p8=exp-2) and (p9=exp-1) then begin inc (p5); p6:=p5+1; p7:=p5+2; p8:=p5+3; p9:=p5+4; end else if (p7=exp-3) and (p8=exp-2) and (p9=exp-1) then begin inc (p6); p7:=p6+1; p8:=p6+2; p9:=p6+3; end else if (p8=exp-2) and (p9=exp-1) then begin inc (p7); p8:=p7+1; p9:=p7+2; end else if p9=exp-1 then begin inc (p8); p9:=p8+1; end else inc (p9); Hauptrest:=Hauptrest-1; end; Edit3.text:=IntToStr(a)+'^'+FloatToStr(p1)+'+'+IntToStr(a)+'^'+FloatToStr(p2)+'+'+IntToStr(a)+'^'+FloatToStr(p3)+'+'+IntToStr(a)+'^'+FloatToStr(p4)+'+'+IntToStr(a)+'^'+FloatToStr(p5)+'+'+IntToStr(a)+'^'+FloatToStr(p6)+'+'+IntToStr(a)+'^'+FloatToStr(p7)+'+'+IntToStr(a)+'^'+FloatToStr(p8)+'+'+IntToStr(a)+'^'+FloatToStr(p9)+'+'+IntToStr(a)+'^'+IntToStr(exp); erg:=Potenz(a,exp)+Potenz(a,p1)+Potenz(a,p2)+Potenz(a,p3)+Potenz(a,p4)+Potenz(a,p5)+Potenz(a,p6)+Potenz(a,p7)+Potenz(a,p8)+Potenz(a,p9); Edit4.text:=FloatToStr(erg); end; begin a:=StrToInt(Edit1.text); n:=StrToInt(Edit2.text); b:=n; if n<1 then begin ShowMessage('Kleinstes Element ist 1!'); exit; end; if n=1 then begin Edit3.text:=IntToStr(a)+'^0'; Edit4.text:=IntToStr(1); exit; end; exp:=0; repeat x:=b div 2; b:=x; exp:=exp+1; until x=1; Rest:=n-Potenz(2,exp); if Rest=0 then begin Edit3.text:=IntToStr(a)+'^'+IntToStr(exp); erg:=Potenz(a,exp); Edit4.text:=FloatToStr(erg); end else if Rest<exp+1 then begin Edit3.text:=IntToStr(a)+'^'+FloatToStr(Rest-1)+'+'+IntToStr(a)+'^'+IntToStr(exp); erg:=Potenz(a,exp)+Potenz(a,Rest-1); Edit4.text:=FloatToStr(erg); end else if n=2*Potenz(2,exp)-1 then begin Edit3.text:=IntToStr(a)+'^0'; counter:=1; repeat Edit3.text:=Edit3.text+'+'+IntToStr(a)+'^'+IntToStr(counter); inc (counter); until counter=exp+1; erg:=1; counter:=1; repeat erg:=erg+Potenz(a,counter); inc (counter); until counter=exp+1; Edit4.text:=FloatToStr(erg) end else begin //h1:=exp+Test3(exp)+Test4(exp); //h2:=exp+Test3(exp)+Test4(exp)+Test5(exp); //h3:=exp+Test3(exp)+Test4(exp)+Test5(exp)+Test6(exp); //h4:=exp+Test3(exp)+Test4(exp)+Test5(exp)+Test6(exp)+Test7(exp); //h5:=exp+Test3(exp)+Test4(exp)+Test5(exp)+Test6(exp)+Test7(exp)+Test8(exp); //h6:=exp+Test3(exp)+Test4(exp)+Test5(exp)+Test6(exp)+Test7(exp)+Test8(exp)+Test9(exp); //h7:=exp+Test3(exp)+Test4(exp)+Test5(exp)+Test6(exp)+Test7(exp)+Test8(exp)+Test9(exp)+Test10(exp); case exp of 3:begin L3(Rest,a,exp); end; 4:begin if Rest<exp+Test3(exp)+1 then begin L3(Rest,a,exp); exit; end else begin Restsub:=exp+Test3(exp); L4(Rest,a,Restsub,exp); end; end; 5:begin if Rest<exp+Test3(exp)+Test4(exp)+1 then begin if Rest<exp+Test3(exp)+1 then begin L3(Rest,a,exp); exit; end else begin Restsub:=exp+Test3(exp); L4(Rest,a,Restsub,exp); exit; end; end else begin Restsub:=exp+Test3(exp)+Test4(exp); L5(Rest,a,Restsub,exp); end; end; 6:begin if Rest<exp+Test3(exp)+Test4(exp)+Test5(exp)+1 then begin if Rest<exp+Test3(exp)+Test4(exp)+1 then begin if Rest<exp+Test3(exp)+1 then begin L3(Rest,a,exp); exit; end else begin Restsub:=exp+Test3(exp); L4(Rest,a,Restsub,exp); end; end else begin Restsub:=exp+Test3(exp)+Test4(exp); L5(Rest,a,Restsub,exp); exit; end; end else begin Restsub:=exp+Test3(exp)+Test4(exp)+Test5(exp); L6(Rest,a,Restsub,exp); exit; end; end; 7:begin if Rest<exp+Test3(exp)+Test4(exp)+Test5(exp)+Test6(exp)+1 then begin if Rest<exp+Test3(exp)+Test4(exp)+Test5(exp)+1 then begin if Rest<exp+Test3(exp)+Test4(exp)+1 then begin if Rest<exp+Test3(exp)+1 then begin L3(Rest,a,exp); exit; end else begin Restsub:=exp+Test3(exp); L4(Rest,a,Restsub,exp); end; end else begin Restsub:=exp+Test3(exp)+Test4(exp); L5(Rest,a,Restsub,exp); exit; end; end else begin Restsub:=exp+Test3(exp)+Test4(exp)+Test5(exp); L6(Rest,a,Restsub,exp); exit; end; end else begin Restsub:=exp+Test3(exp)+Test4(exp)+Test5(exp)+Test6(exp); L7(Rest,a,Restsub,exp); exit; end; end; 8:begin if Rest<exp+Test3(exp)+Test4(exp)+Test5(exp)+Test6(exp)+Test7(exp)+1 then begin if Rest<exp+Test3(exp)+Test4(exp)+Test5(exp)+Test6(exp)+1 then begin if Rest<exp+Test3(exp)+Test4(exp)+Test5(exp)+1 then begin if Rest<exp+Test3(exp)+Test4(exp)+1 then begin if Rest<exp+Test3(exp)+1 then begin L3(Rest,a,exp); exit; end else begin Restsub:=exp+Test3(exp); L4(Rest,a,Restsub,exp); end; end else begin Restsub:=exp+Test3(exp)+Test4(exp); L5(Rest,a,Restsub,exp); exit; end; end else begin Restsub:=exp+Test3(exp)+Test4(exp)+Test5(exp); L6(Rest,a,Restsub,exp); exit; end; end else begin Restsub:=exp+Test3(exp)+Test4(exp)+Test5(exp)+Test6(exp); L7(Rest,a,Restsub,exp); exit; end; end else begin Restsub:=exp+Test3(exp)+Test4(exp)+Test5(exp)+Test6(exp)+Test7(exp); L8(Rest,a,Restsub,exp); exit; end; end; 9:begin if Rest<exp+Test3(exp)+Test4(exp)+Test5(exp)+Test6(exp)+Test7(exp)+Test8(exp)+1 then begin if Rest<exp+Test3(exp)+Test4(exp)+Test5(exp)+Test6(exp)+Test7(exp)+1 then begin if Rest<exp+Test3(exp)+Test4(exp)+Test5(exp)+Test6(exp)+1 then begin if Rest<exp+Test3(exp)+Test4(exp)+Test5(exp)+1 then begin if Rest<exp+Test3(exp)+Test4(exp)+1 then begin if Rest<exp+Test3(exp)+1 then begin L3(Rest,a,exp); exit; end else begin Restsub:=exp+Test3(exp); L4(Rest,a,Restsub,exp); end; end else begin Restsub:=exp+Test3(exp)+Test4(exp); L5(Rest,a,Restsub,exp); exit; end; end else begin Restsub:=exp+Test3(exp)+Test4(exp)+Test5(exp); L6(Rest,a,Restsub,exp); exit; end; end else begin Restsub:=exp+Test3(exp)+Test4(exp)+Test5(exp)+Test6(exp); L7(Rest,a,Restsub,exp); exit; end; end else begin Restsub:=exp+Test3(exp)+Test4(exp)+Test5(exp)+Test6(exp)+Test7(exp); L8(Rest,a,Restsub,exp); exit; end; end else begin Restsub:=exp+Test3(exp)+Test4(exp)+Test5(exp)+Test6(exp)+Test7(exp)+Test8(exp); L9(Rest,a,Restsub,exp); exit; end; end; 10:begin if Rest<exp+Test3(exp)+Test4(exp)+Test5(exp)+Test6(exp)+Test7(exp)+Test8(exp)+Test9(exp)+1 then begin if Rest<exp+Test3(exp)+Test4(exp)+Test5(exp)+Test6(exp)+Test7(exp)+Test8(exp)+1 then begin if Rest<exp+Test3(exp)+Test4(exp)+Test5(exp)+Test6(exp)+Test7(exp)+1 then begin if Rest<exp+Test3(exp)+Test4(exp)+Test5(exp)+Test6(exp)+1 then begin if Rest<exp+Test3(exp)+Test4(exp)+Test5(exp)+1 then begin if Rest<exp+Test3(exp)+Test4(exp)+1 then begin if Rest<exp+Test3(exp)+1 then begin L3(Rest,a,exp); exit; end else begin Restsub:=exp+Test3(exp); L4(Rest,a,Restsub,exp); end; end else begin Restsub:=exp+Test3(exp)+Test4(exp); L5(Rest,a,Restsub,exp); exit; end; end else begin Restsub:=exp+Test3(exp)+Test4(exp)+Test5(exp); L6(Rest,a,Restsub,exp); exit; end; end else begin Restsub:=exp+Test3(exp)+Test4(exp)+Test5(exp)+Test6(exp); L7(Rest,a,Restsub,exp); exit; end; end else begin Restsub:=exp+Test3(exp)+Test4(exp)+Test5(exp)+Test6(exp)+Test7(exp); L8(Rest,a,Restsub,exp); exit; end; end else begin Restsub:=exp+Test3(exp)+Test4(exp)+Test5(exp)+Test6(exp)+Test7(exp)+Test8(exp); L9(Rest,a,Restsub,exp); exit; end; end else begin Restsub:=exp+Test3(exp)+Test4(exp)+Test5(exp)+Test6(exp)+Test7(exp)+Test8(exp)+Test9(exp); L10(Rest,a,Restsub,exp); end; end; end; end; end;
MFG Toddy
-
Das ist noch echte Wertarbeit
-
Also mich stört das 12 Element erheblich. Ich glaube [jetzt] auch das ein Austausch mit dem 11. richtig ist. Hier mal eine Auflistung der Exponenten:
0 1 1 0 2 2 0 2 1 2 1 0 3 3 0 3 1 // ab hier(10.) sollte es imho so weiter gehen: 3 1 0 3 2 3 2 0 3 2 1 3 2 1 0 4 //...
Eine gewisse Regelmäßigkeit ist nicht abzustreiten.
Gruß
Don06
-
Hallo, bewundert meinen Code!!! (Nur Spaß...)
Also wenn man so weiter macht wie ich es mir vorgestellt habe kommen beim 100. glied gravierende Änderungen vor wie wenn man nach der Regelmäßigkeit der 2er-Potenzen vorgeht. Versuchts mal selbst...
MFG Toddy