RosettaCode Sammelthread

  • Sammelthread zum RosettaCode Wiki.

    Foruminterne Infos zu RC
    Bereits implementierte Aufgaben
    Aufgaben, die eine dringende Überarbeitung brauchen
    Nicht-implementierte Aufgaben

    Was hier gepostet werden kann:

    • Neu implementierte Beispiele
    • Überarbeitete Beispiele


    Wir sollten hier vor allem bei neu geschriebenen Beispielen diskutieren, ob diese perfekt sind und sie falls nötig verbessern. Danach können wir sie ins Wiki stellen ;)


    Ich beginne mal:

    Art: Neu-Implementierung
    Task: http://rosettacode.org/wiki/Arithmetic/Integer
    Beteiligte: minx
    Script:

    Spoiler anzeigen
    [autoit]

    $iA = InputBox("Integer Arithmetic", "a?")
    $iB = InputBox("Integer Arithmetic", "b?")

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

    MsgBox(0, "Integer Arithmetic", "Results are:" & @CRLF & _
    "a + b = " & $iA + $iB & @CRLF & _
    "a - b = " & $iA - $iB & @CRLF & _
    "a * b = " & $iA * $iB & @CRLF & _
    "a / b = " & Floor($iA / $iB) & ", remainder is " & Mod($iA, $iB))
    ;

    [/autoit]

    Einmal editiert, zuletzt von minx (15. Februar 2013 um 18:51)

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

    Spoiler anzeigen
    [autoit]

    $sString = InputBox("RepeatString Example", "This string will be repeated 5 times!")
    MsgBox(0, "_RepeatString Example", "Result: " & RepeatString($sString, 5))

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

    Func RepeatString($sString, $iHowOften) ;// Ich weiß, gibst schon in der String.au3 - UDF ;)
    Local $sResult = ""
    For $i = 1 To $iHowOften
    $sResult &= $sString
    Next
    Return $sResult
    EndFunc

    [/autoit]

    Spoiler anzeigen
    [autoit]

    #include <String.au3>

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

    $sString = InputBox("_StringRepeat Example", "This string will be repeated 5 times!")
    MsgBox(0, "_StringRepeat Example", "Result: " & _StringRepeat($sString, 5))

    [/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

    2 Mal editiert, zuletzt von PainTain (15. Februar 2013 um 19:55)

  • PainTain

    Ich finde, Standard UDFs sollten benutzt werden. Immerhin gehören sie ja zum Funktionsumfang der Sprache (siehe andere AutoIt-Beispiele).


    Okay habs umgeschrieben ;)

    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/Bitwise_operations
    Beteiligte: James1337
    Skript:

    Spoiler anzeigen
    [autoit]

    $a = 666
    $b = 42

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

    ConsoleWrite($a & " and " & $b & " = " & BitAND($a, $b) & @CRLF)
    ConsoleWrite($a & " or " & $b & " = " & BitOR($a, $b) & @CRLF)
    ConsoleWrite($a & " xor " & $b & " = " & BitXOR($a, $b) & @CRLF)
    ConsoleWrite("not " & $a & " = " & BitNOT($a) & @CRLF)
    ConsoleWrite($a & " << " & $b & " = " & BitShift($a, -$b) & @CRLF) ; negative numbers shift left
    ConsoleWrite($a & " >> " & $b & " = " & BitShift($a, $b) & @CRLF)
    ConsoleWrite($a & " <<< " & $b & " = " & BitRotate($a, $b) & @CRLF)
    ConsoleWrite($a & " >>> " & $b & " = " & BitRotate($a, -$b) & @CRLF) ; negative numbers rotate right

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

    Spoiler anzeigen
    [autoit]

    For $n = 1 To 10
    ConsoleWrite("Q(" & $n & ") = " & Q($n) & @CRLF)
    Next
    ConsoleWrite("Q(1000) = " & Q(1000) & @CRLF)

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

    Func Q($n)
    If ($n = 1) Or ($n = 2) Then
    Return 1
    EndIf
    Return Q($n - Q($n - 1)) + Q($n - Q($n - 2))
    EndFunc

    [/autoit]

    Problem(e): Ich musste das Skript abbrechen: >Exit code: 1 Time: 1468.340

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

    Spoiler anzeigen
    [autoit]

    Global $hMainSocket, $hNewSocket, $iMaxClients = 100, $iCurrentCLients = 0, $aClients[$iMaxClients], $sBuffer
    OnAutoItExitRegister("_ShutdownServer")
    TCPStartup()

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

    $hMainSocket = TCPListen("127.0.0.1", 12321)
    If @error Then Exit
    ConsoleWrite("Mainsocket: " & $hMainSocket & @LF)

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

    While True
    $hNewSocket = TCPAccept($hMainSocket)
    If $hNewSocket > 0 And $iCurrentCLients < $iMaxClients Then _AddClient($hNewSocket)

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

    For $i = 0 To $iMaxClients - 1
    If $aClients[$i] Then
    $sBuffer &= TCPRecv($aClients[$i], 2048)
    If @error Then _DelClient($i)
    EndIf
    Next

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

    If $sBuffer <> "" Then _ExecuteBuffer()
    WEnd

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

    Func _AddClient($hSocket)
    For $i = 0 To $iMaxClients - 1
    If Not $aClients[$i] Then
    $aClients[$i] = $hSocket
    ConsoleWrite("new client with socket " & $hSocket & @LF)
    $iCurrentCLients += 1
    Return 1
    EndIf
    Next
    TCPCloseSocket($hSocket)
    Return 0
    EndFunc ;==>_AddClient

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

    Func _DelClient($iNumber)
    $iCurrentCLients -= 1
    TCPCloseSocket($aClients[$iNumber])
    $aClients[$iNumber] = False
    ConsoleWrite("client on slot " & $iNumber & " disconnected" & @LF)
    EndFunc ;==>_DelClient

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

    Func _ExecuteBuffer()
    Local $aPakets = StringRegExp($sBuffer, "(.+)(?:\n|\r)", 3)
    If Not IsArray($aPakets) Then Return 0
    For $a = 0 To UBound($aPakets) - 1
    For $i = 0 To $iMaxClients - 1
    If $aClients[$i] Then TCPSend($aClients[$i], $aPakets[$a] & @LF)
    Next
    Next
    $sBuffer = ""
    Return UBound($aPakets)
    EndFunc ;==>_ExecuteBuffer

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

    Func _ShutdownServer()
    For $i = 0 To $iMaxClients - 1
    If $aClients[$i] Then TCPCloseSocket($aClients[$i])
    Next
    TCPCloseSocket($hMainSocket)
    TCPShutdown()
    Exit
    EndFunc ;==>_ShutdownServer

    [/autoit]

    Gibts nen Freiwilligen der meine Snippets, wenn sie okay sind hochläd? :D

    LG
    Christoph :)

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

    Spoiler anzeigen
    [autoit]

    #RequireAdmin
    ;# Workingdir
    FileDelete(@WorkingDir & "\input.txt")
    DirRemove(@WorkingDir & "\docs\")
    ;# Rootdir
    FileDelete(@HomeDrive & "\input.txt")
    DirRemove(@HomeDrive & "\docs\")

    [/autoit]


    Mfg

    P.S. BinDannMalWeg: Dein Create_a_File - Skript benötigt ein '#RequireAdmin' unter Vista/7 um auf '@HomeDrive' zu schreiben ;)

    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/File_size
    Beteiligte: PainTain
    Skript:

    Spoiler anzeigen
    [autoit]

    ;# Workingdir
    $sSizeWorkingDir = FileGetSize(@WorkingDir & "\input.txt")
    ;# Rootdir
    $sSizeRootDir = FileGetSize(@HomeDrive & "\input.txt")
    ;# Output
    MsgBox(0, "Result", "Size of 'input.txt' at working dir: " & $sSizeWorkingDir & @CRLF & "Size of 'input.txt' at root dir: " & $sSizeRootDir)

    [/autoit]


    Noch eins :D

    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/Read_a_file_line_by_line
    Beteiligte: PainTain
    Skript:

    Spoiler anzeigen
    [autoit]

    #include <File.au3>

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

    $hFile = FileOpen("input.txt")
    For $i = 1 To _FileCountLines("input.txt")
    ConsoleWrite(FileReadLine($hFile, $i))
    Next

    [/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