[LÖSUNG] für Autoit.de kann nicht bis 100 zählen ;)

  • So, hier habe ich mal ein kleines Skript, das die Lösung für diesen Thread ausspuckt ;)
    [spiel] Autoit.de kann nicht bis 100 zählen
    Dazu habe ich zwei Funktionen aus der MathEx-UDF von eukalyptus verwendet und selbst neine Funktion nach AutoIt konvertiert, um die Zahlwörter zu erhalten.

    Spoiler anzeigen
    [autoit]

    ;##############################################
    ; ##OPTIONEN
    $_BEI_MESSAGEBOX_CLIPPUT = True ; ClipPut des Wertes, wenn die MsgBox angezeigt wird.
    ; ##
    ;##############################################
    #include<String.au3>
    #include<Array.au3>

    [/autoit] [autoit][/autoit] [autoit]

    ;<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
    #Region MathExPrime
    ; #include<MathEx.au3>

    [/autoit] [autoit][/autoit] [autoit]

    ; #FUNCTION# ====================================================================================================================
    ; Name...........: _MathEx_IsDivisible
    ; Beschreibung...: Prüft, ob eine Zahl durch eine andere teilbar ist.
    ; Syntax.........: _MathEx_IsPrime($numdividend, $numdivisor)
    ; Parameter......: $numdividend - Der Dividend
    ; $numdivisor - Der Divisor
    ; Rückgaben......: Erfolg - Gibt 1 zurück, wenn der Dividend durch den Divisor teilbar ist.
    ; Fehler - Gibt 0 zurück und setzt @error
    ; |0 - $numdividend und $numdivisor sind nicht teilbar
    ; |1 - $numdivisor ist 0
    ; |2 - $numdividdend oder $numdivisor ist keine Zahl
    ; Autor(en)......: eukalyptus <eukalyptus at autoit dot de>, Matthias Gianfelice <matthias at gianfelice dot de>
    ; ===============================================================================================================================
    Func _MathEx_IsDivisible($numdividend, $numdivisor)
    Local $integer_number_mathex_dividend = Number($numdividend), $integer_number_mathex_divisor = Number($numdivisor)
    If $integer_number_mathex_divisor = 0 Then SetError(1, 0, 0)
    If IsInt($integer_number_mathex_dividend) = 1 And $integer_number_mathex_dividend > 0 And IsInt($integer_number_mathex_divisor) = 1 And $integer_number_mathex_divisor > 0 Then
    If Not Mod($integer_number_mathex_dividend, $integer_number_mathex_divisor) Then
    Return 1
    Else
    SetError(0, 0, 0)
    EndIf
    Else
    SetError(2, 0, 0)
    EndIf
    EndFunc ;==>_MathEx_IsDivisible

    [/autoit] [autoit][/autoit] [autoit]

    ; #FUNCTION# ====================================================================================================================
    ; Name...........: _MathEx_IsPrime
    ; Beschreibung...: Prüft, ob eine Zahl eine Primzahl ist.
    ; Syntax.........: _MathEx_IsPrime($number[, $one_prime])
    ; Parameter......: $number - Die Nummer, die geprüft werden soll
    ; $one_prime - Auf 1 setzen, wenn 1 eine Primzahl sein soll.
    ; Rückgabe.......: Erfolg - Gibt 1 zurück, wenn die Zahl eine Primzahl ist.
    ; Fehler - Gibt 0 zurück und setzt @error
    ; |0 - $number ist keine Primzahl
    ; |1 - $number ist keine Zahl
    ; Author ........: Progandy <Progandy at autoit dot de>, Matthias Gianfelice <matthias at gianfelice dot de>
    ; ===============================================================================================================================
    Func _MathEx_IsPrime($number, $one_prime = 0)
    Local $integer_number_mathex_prime = Number($number)
    If IsInt($integer_number_mathex_prime) = 1 And $integer_number_mathex_prime > 0 Then
    If $integer_number_mathex_prime = 1 Then
    SetError(0)
    Return 0
    ElseIf $integer_number_mathex_prime = 2 Then
    Return 1
    EndIf
    Local $prime = True
    If _MathEx_IsDivisible($integer_number_mathex_prime, 2) Then
    $prime = False
    Else
    For $i = 3 To Sqrt($integer_number_mathex_prime) Step 2
    If _MathEx_IsDivisible($integer_number_mathex_prime, $i) Then
    $prime = False
    ExitLoop
    EndIf
    Next
    EndIf
    If $prime = False Then
    SetError(0)
    Return 0
    Else
    Return 1
    EndIf
    Else
    If $one_prime And IsInt($integer_number_mathex_prime) = 1 Then Return 1
    SetError(1)
    Return -1
    EndIf
    EndFunc ;==>_MathEx_IsPrime
    #EndRegion MathExPrime
    ;<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

    [/autoit] [autoit][/autoit] [autoit]

    Func _Zahlwort($n)
    ; basiert auf Code von d0nUt und chrispatsch
    ; Quelle: http://www.easy-coding.de/zahlen-drucken-t2685.html
    ; Author: Prog@ndy
    Dim $einer[10] = [ "", "ein", "zwei", "drei", "vier", "fünf", "sechs", "sieben", "acht", "neun" ];
    Dim $zehner[10] = [ "", "zehn", "zwanzig", "dreißig", "vierzig", "fünfzig", "sechzig", "siebzig", "achtzig", "neunzig" ];
    Dim $sonderfall[3] = [ "", "elf", "zwölf" ];
    Local $result = "", $digit
    Select
    Case $n=1
    $result = 'eins'
    Case $n >= 100
    $digit = Mod($n , 10);
    $result &= ($einer[Floor($n / 100)])
    $result &= "hundert"
    if ($digit > 0) Then $result &= "und" & Mod($n , 100);
    Case ($n > 12)
    $digit = Mod($n , 10);
    $result &= $einer[$digit]
    if ($digit > 0) And $n>19 Then $result &= "und"
    $result &= $zehner[Floor($n / 10)];
    Case ($n > 10)
    $result &= ($sonderfall[Mod($n , 10)]);
    Case $n>0
    $result = $einer[$n]
    Case $n=0
    $result = 'null'
    EndSelect
    Return $result
    EndFunc

    [/autoit] [autoit][/autoit] [autoit]

    Func _FormatZahl($zahl)
    ; Author: Prog@ndy
    $zahl = Int($zahl)
    If $zahl < 1 Or $zahl > 100 Then Return ""

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    Switch _MathEx_IsPrime($zahl)
    Case True
    $zahl = _Zahlwort($zahl)
    $zahl = StringReplace($zahl, "drei", "]b/[drei]b[")
    If @extended Then $zahl = _StringReverse($zahl)
    Case False
    $zahl = StringReplace($zahl, "3", "3")
    EndSwitch
    Return $zahl
    EndFunc

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    $zahl = InputBox("Zahl eingeben", "Zahl eingeben, dann wird sie nach den Regeln formatiert" & @CRLF & " -------- " & @CRLF & "Abbrechen für Liste aller Zahlen von 1 bis 100")
    If Not @error Then
    $zahl = Int($zahl)
    If $zahl > 0 And $zahl <= 100 Then
    $zahl = _FormatZahl($zahl)
    If $_BEI_MESSAGEBOX_CLIPPUT Then ClipPut($zahl)
    MsgBox(0, '', $zahl)
    EndIf
    EndIf

    [/autoit] [autoit][/autoit] [autoit]

    Dim $Array[101] = ['Zahlen für "Wette"']
    For $i = 1 To 100
    $Array[$i] = _FormatZahl($i)
    Next
    _ArrayDisplay($Array, "AutoIt.de bis 100 Zählen")

    [/autoit]

    Einmal editiert, zuletzt von progandy (10. August 2009 um 18:11)

  • In der MsgBox Strg-C drücken ;)

    Da bekomme ich
    ---------------------------

    ---------------------------
    14
    ---------------------------
    OK
    ---------------------------

    raus.


  • @progandy, ich habe da mal eine Sache die ich nicht verstehe.
    Schau mal bitte Array [83][1]. Da steht vorne die "83", aber das was da hinter kommt verstehe ich nun gar nicht. Also das in dem Feld re. daneben. Ist keine ZAhl und keine Nummer. Auch nicht in Worten. Soll das einfach nur etwas "schwachsinniges" stehen wenn es eine Primzahl ist oder ist das ein versteckter Code?
    Manno, ich blicke da nicht durch.

    Antwort bitte !!! Möchte nicht als Blondine eingestuft werden, auch wenn ich dunkelblond bin, aber das ist mir eindeutig zu hoch.

    Hmm, das sind die Regeln von der "Wette" ;)
    2) wenn in irgend einer Zahl eine 3 vorkommt, muss diese fett hervorgehoben werden
    --> 8[.b]3[./b]
    1) Primzahlen sollen als Worte ausgeschrieben werden
    --> [.b]drei[./b]undachtzig
    3) wenn in einer Primzahl eine 3 vorkommt, muss diese rückwärts geschrieben werden
    --> g i z t h c a d n u [.b] i e r d [./b]

    //Edit: du hast es ja selber rausgefunden, da dein Post weg ist :P

  • Das ist mir ja mal richtig PEINLICH !!!

    Dazu sage ich mal nichts mehr. Boh bin ich doch so blond ;):rofl:
    Müssen die Hormone sein :rofl:

    Lieben Gruß,
    Alina

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    Geheime Information: ;)
    OuBVU5ebLhHu5QvlnAyQB4A7SzBrvWulwL7RLl2BdH5tI6sIYspeMKeXMSXl

  • Cool, wird die MathEx sogar für was benutzt :D
    Hab ich ja doch was sinnvolles in die Welt gesetzt ;)