RosettaCode Sammelthread

  • Art: Neu-Implementierung
    Task: http://rosettacode.org/wiki/Loops/Nested
    Beteiligte: Christoph54
    Skript:

    Spoiler anzeigen
    [autoit]

    Local $Array[20][20] ; declare array
    ; fill array:
    For $row = 0 To 19
    For $collumn = 0 To 19
    $Array[$row][$collumn] = Random(1, 20, 1)
    Next
    Next
    ; search 20:
    For $row = 0 To 19
    For $collumn = 0 To 19
    ConsoleWrite($Array[$row][$collumn] & @TAB)
    If $Array[$row][$collumn] = 20 Then ExitLoop 2
    Next
    ConsoleWrite(@LF)
    Next

    [/autoit]

    LG
    Christoph :)

  • Art: Neu-Implementierung
    Task: http://rosettacode.org/wiki/Mouse_position
    Beteiligte: PainTain
    Skript:

    Spoiler anzeigen
    [autoit]

    Opt("MouseCoordMode", 0)

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

    $aPos = MouseGetPos()
    ConsoleWrite("X: " & $aPos[0] & @CRLF & "Y: " & $aPos[1] & @CRLF)

    [/autoit]

    There's a joke that C has the speed and efficieny of assembly language combined with readability of....assembly language. In other words, it's just a glorified assembly language. - Teh Interwebz

    C makes it easy to shoot yourself in the foot; C++ makes it harder, but when you do, you blow off your whole leg. - Bjarne Stroustrup
    Genie zu sein, bedeutet für mich, alles zu tun, was ich will. - Klaus Kinski


  • Hast du das Skript mal ausgeführt?
    Hatte haargenau das gleiche geschrieben, allerdings kamen seltsame Ergebnisse raus (zumindest für mich, hätte ja 512, 256, 128, 64, 32, 16, 8, 4, 2, 0 erwartet =/).

    There's a joke that C has the speed and efficieny of assembly language combined with readability of....assembly language. In other words, it's just a glorified assembly language. - Teh Interwebz

    C makes it easy to shoot yourself in the foot; C++ makes it harder, but when you do, you blow off your whole leg. - Bjarne Stroustrup
    Genie zu sein, bedeutet für mich, alles zu tun, was ich will. - Klaus Kinski

  • Hä, wieso? 2/2 ist 1. 1/2 ist 0.5. 0.5/2 sind 0.25. Das hört eigentlich nicht wirklich auf. Theoretisch müsste es unendlich laufen. Bei mir hört es bei -4,x•10^324 auf.

    Das was du dir wünschst könnte man mit einer Integerschleife, also Int-Rechnungen erzwungen mit Floor() erreichen. Dann ist 2/2 aber immer noch 1 :P

    So willst du es haben:

    [autoit]

    Local $i = 1024

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

    While $i > 1
    ConsoleWrite($i & @LF)
    $i = Floor($i/2)
    WEnd
    ConsoleWrite(0)

    [/autoit]
  • Hä, wieso? 2/2 ist 1. 1/2 ist 0.5. 0.5/2 sind 0.25. Das hört eigentlich nicht wirklich auf. Theoretisch müsste es unendlich laufen. Bei mir hört es bei -4,x•10^324 auf.


    Okay bin grad ein wenig verwirred, harte Woche :S
    Jedenfalls:
    Art: Neu-Implementierung
    Task: http://rosettacode.org/wiki/Empty_string
    Beteiligte: PainTain
    Skript:

    Spoiler anzeigen
    [autoit]

    $sEmptyString = ""

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

    If $sEmptyString <> "" Then
    MsgBox(0, "Rosetta Code", "String is not empty!")
    Else
    MsgBox(0, "Rosetta Code", "String is empty!")
    EndIf

    [/autoit]

    Mfg

    There's a joke that C has the speed and efficieny of assembly language combined with readability of....assembly language. In other words, it's just a glorified assembly language. - Teh Interwebz

    C makes it easy to shoot yourself in the foot; C++ makes it harder, but when you do, you blow off your whole leg. - Bjarne Stroustrup
    Genie zu sein, bedeutet für mich, alles zu tun, was ich will. - Klaus Kinski

  • Art: Neu-Implementierung
    Task: http://rosettacode.org/wiki/Sockets
    Beteiligte: James1337
    Skript:

    Spoiler anzeigen
    [autoit]

    TCPStartup()

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

    Local $IPAddr = TCPNameToIP("localhost")
    Local $Port = 256

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

    Local $Socket = TCPConnect($IPAddr, $Port)
    TCPSend($Socket, "hello socket world")
    TCPCloseSocket($Socket)

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

    TCPShutdown()

    [/autoit]
  • Art: Neu-Implementierung
    Task: http://rosettacode.org/wiki/Luhn_test_of_credit_card_numbers
    Beteiligte: James1337
    Skript:

    Spoiler anzeigen
    [autoit]

    ConsoleWrite(LuhnTest("49927398716") & @CRLF)
    ConsoleWrite(LuhnTest("49927398717") & @CRLF)
    ConsoleWrite(LuhnTest("1234567812345678") & @CRLF)
    ConsoleWrite(LuhnTest("1234567812345670") & @CRLF)

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

    Func LuhnTest($CreditCardNumber)
    Local $a, $i, $n, $d, $s1 = 0, $s2 = 0
    $a = StringSplit($CreditCardNumber, "")
    For $i = 1 To $a[0]
    $n = $a[0]-$i+1
    $d = $a[$i] ; digit number $n in the reversed digits
    If (Mod($n, 2) = 0) Then ; even
    ; because 18 mod 9 = 0 and we want to get 9 instead
    $s2 += Mod($d*2, 9) + 9*(Mod($d*2, 9) = 0)
    Else ; odd
    $s1 += $d
    EndIf
    Next
    Return (Mod($s1+$s2, 10) = 0)
    EndFunc

    [/autoit]
  • Art: Neu-Implementierung
    Task: http://rosettacode.org/wiki/Mad_Libs
    Beteiligte: James1337
    Skript:

    Spoiler anzeigen
    [autoit]

    Local $Story
    $Story = "<name> went for a walk in the park. <he or she>" & @CRLF
    $Story &= "found a <noun>. <name> decided to take it home." & @CRLF
    MadLibs($Story)

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

    Func MadLibs($Story)
    Local $r, $i, $w
    $r = StringRegExp($Story, "<(.+?)>", 3)
    If (Not @error) Then
    For $i = 0 To UBound($r)-1
    If (StringInStr($Story, "<" & $r[$i] & ">") = 0) Then ContinueLoop ; already replaced
    $w = InputBox("Mad Libs", $r[$i] & "?")
    If @error Then ExitLoop
    $Story = StringReplace($Story, "<" & $r[$i] & ">", $w)
    Next
    EndIf
    Return MsgBox(0, "Mad Libs", $Story)
    EndFunc

    [/autoit]
  • Art: Neu-Implementierung
    Task: http://rosettacode.org/wiki/MD5
    Beteiligte: Alcros
    Skript:

    Spoiler anzeigen
    [autoit]

    #include <Crypt.au3>

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

    Local $sString = "Hello. This is a text."

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

    _Crypt_Startup()
    MsgBox(0,"MD5-Hash of $sString",_Crypt_HashData($sString,$CALG_MD5))
    _Crypt_Shutdown()

    [/autoit]
  • Art: Neu-Implementierung
    Task: http://rosettacode.org/wiki/Linear_congruential_generator
    Beteiligte: James1337
    Skript:

    Spoiler anzeigen
    [autoit]

    _BSD_init()
    ConsoleWrite("BSD (seed = 0):" & @CRLF)
    For $i = 1 To 10
    ConsoleWrite(_BSD_rand() & @CRLF)
    Next
    ConsoleWrite(@CRLF & "Microsoft (seed = 0):" & @CRLF)
    _Microsoft_init()
    For $i = 1 To 10
    ConsoleWrite(_Microsoft_rand() & @CRLF)
    Next

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

    Func _BSD_init($seed=0)
    LCG("r", $seed)
    LCG("a", 1103515245)
    LCG("c", 12345)
    LCG("m", 2^31)
    EndFunc
    Func _BSD_rand()
    Return LCG()
    EndFunc

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

    Func _Microsoft_init($seed=0)
    LCG("r", $seed)
    LCG("a", 214013)
    LCG("c", 2531011)
    LCG("m", 2^31)
    EndFunc
    Func _Microsoft_rand()
    Return Int(LCG() / 2^16)
    EndFunc

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

    Func LCG($0="", $1=0)
    Local Static $r = 0, $a = 0, $c = 0, $m = 0
    Switch $0
    Case "r"
    $r = $1
    Case "a"
    $a = $1
    Case "c"
    $c = $1
    Case "m"
    $m = $1
    EndSwitch
    If ($0 <> "") Then Return 0
    $r = Mod($a * $r + $c, $m)
    Return $r
    EndFunc ; LCG() by James1337

    [/autoit]

    Ausgabe:

    Spoiler anzeigen

    Problem(e): _BSD_rand() liefert falsche Werte, wurde aber meines Wissens nach richtig implementiert.