Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

Challenge: translate rosettacode - Was promoting autohotkey


  • Please log in to reply
55 replies to this topic
tinku99
  • Members
  • 560 posts
  • Last active: Feb 08 2015 12:54 AM
  • Joined: 03 Aug 2007
I think autohotkey is terribly underrepresented on major websites comparing programming languages. So, I added a few autohotkey examples on rosettacode here:AutoHotkey_Originated.
from the site:

Rosetta Code is a programming chrestomathy site. The idea is to present solutions to the same task in as many different languages.

If you believe it, help me prove that autohotkey is as usefull as the most popular languages by translating:
Tasks_not_implemented_in_AutoHotkey
Here are the translated tasks

Edit:
If you contribute, edit your user page on rosettacode with something like:
{{mylangbegin}}
{{mylang|AutoHotkey| proficiency level here }}
{{mylangend}}
so you show up in the AutoHotkey_User list

Edit2:
AutoHotkey is now ranked in the top 10 of the most popular languages.

Edit3:
slipped to 14.

Edit4:
back to top 10. May 16, 2010.

tinku99
  • Members
  • 560 posts
  • Last active: Feb 08 2015 12:54 AM
  • Joined: 03 Aug 2007
If you are interested in improving your coding skills, try translating the rosettacode tasks in autohotkey.

Here are some already done.

bump

sinkfaze
  • Moderators
  • 6367 posts
  • Last active: Nov 30 2018 08:50 PM
  • Joined: 18 Mar 2008
I can't post it to the Wiki from where I'm at but if someone else would like to here's a solution we can post for 99 bottles of beer, or if someone sees a more optimal solution please go for it:

x=100
Loop, 99 {

  if (x - A_Index - 1 > 1)
	FileAppend
	, % x - A_Index " bottles of beer on the wall,`n" x - A_Index " bottles of beer,`nTake one down and pass it around,`n" x - A_Index - 1 " bottles of beer on the wall.`n`n"
	, Output.txt
  else if (x - A_Index - 1 = 1)
	FileAppend
	, % x - A_Index " bottles of beer on the wall,`n" x - A_Index " bottles of beer,`nTake one down and pass it around,`n" x - A_Index - 1 " bottle of beer on the wall.`n`n"
	, Output.txt
  else if (x - A_Index - 1 = 0)
	FileAppend
	, % x - A_Index " bottle of beer on the wall,`n" x - A_Index " bottle of beer,`nTake one down and pass it around,`nNo more bottles of beer on the wall.`n"
	, Output.txt

}


sinkfaze
  • Moderators
  • 6367 posts
  • Last active: Nov 30 2018 08:50 PM
  • Joined: 18 Mar 2008
Also (again I am unable to post to the Wiki), here's a solution to the 100 doors problem if someone would like to review it for optimization or just post it to the Wiki:

Loop, 100
  Door%A_Index% := "closed"

Loop, 100 {
  x := A_Index
  y := A_Index
  While (x <= 100)
  {
    CurrentDoor := Door%x%
    If CurrentDoor contains closed
    {
      Door%x% := "open"
      x += y
    }
    else if CurrentDoor contains open
    {
      Door%x% := "closed"
       x += y
     }
  }
}

Loop, 100 {
	CurrentDoor := Door%A_Index%
	If CurrentDoor contains open
		Res .= "Door" A_Index "`n"
}

MsgBox % "The following doors are still open.`n`n" Res


tinku99
  • Members
  • 560 posts
  • Last active: Feb 08 2015 12:54 AM
  • Joined: 03 Aug 2007
Thanks sinkfaze,
I posted them both with minor changes: 99 bottles, 100 doors.
If you want to further modify what i posted, start a new thread in the ahk forums, for that task.

Frankie
  • Members
  • 2930 posts
  • Last active: Feb 05 2015 02:49 PM
  • Joined: 02 Nov 2008
If were going for all the puzzles I did an easy one:
Loop, 100

{

  If (Mod(A_Index, 15) = 0)

    Output .= "FizzBuzz`n"

  Else If (Mod(A_Index, 3) = 0)

    Output .= "Fizz`n"

  Else If (Mod(A_Index, 5) = 0)

    Output .= "Buzz`n"

  Else

    Output .= "`n"

}

Msgbox % Output
Someone else can post it to the wiki. I don't know how to work wikipedia. Also is there a better way to display it than the msgbox? I didn't want to add a gui with an editbox to to the code because thats to much code.
aboutscriptappsscripts
Request Video Tutorials Here or View Current Tutorials on YouTube
Any code ⇈ above ⇈ requires AutoHotkey_L to run

tinku99
  • Members
  • 560 posts
  • Last active: Feb 08 2015 12:54 AM
  • Joined: 03 Aug 2007

Also is there a better way to display it than the msgbox? I didn't want to add a gui with an editbox to to the code because thats to much code.

You can either use consolesend. example
or do this: example
FileDelete, output.txt
FileAppend, %output% output.txt
run, cmd /k type Output.txt

I don't know how to work wikipedia.

just click edit, and paste this in the proper alphabetic position.
=={{header|AutoHotkey}}==
<lang AutoHotkey>
...autohotkey code here...
</lang>


Frankie
  • Members
  • 2930 posts
  • Last active: Feb 05 2015 02:49 PM
  • Joined: 02 Nov 2008
Thanks. Its added with the command prompt edit. Link
aboutscriptappsscripts
Request Video Tutorials Here or View Current Tutorials on YouTube
Any code ⇈ above ⇈ requires AutoHotkey_L to run

jaco0646
  • Moderators
  • 3165 posts
  • Last active: Apr 01 2014 01:46 AM
  • Joined: 07 Oct 2006
Here's my solution to Happy Number. I like the idea of posting solutions here first to let others look them over for bugs or optimizations before submitting them on Rosetta Code. Plus I've never had any luck with recursion before. :p
EDIT: updated code
MsgBox,% Happy()
return

Happy() {
 static in:=1,out:="",int:=1,index:=1
 Loop,Parse,int
  num += A_LoopField**2
 If (num=1) OR (index++ > 9) {
  out .= num=1 ? in "`n":""
  int := ++in
  index := 1
 }
 Else int := num
 StringReplace,out,out,`n,`n,UseErrorLevel
 If (ErrorLevel < 8)
  Happy()
 Return, out
}


Krogdor
  • Members
  • 1391 posts
  • Last active: Jun 08 2011 05:31 AM
  • Joined: 18 Apr 2008
Just curious, how do you make a task disappear from the list of uncompleted tasks for a given language? I had hoped it would do it automatically after you put the given language onto a task page, but after posting an AHK solution for the Ackermann function, the task still appears on AHK's uncompleted task page...

jaco0646
  • Moderators
  • 3165 posts
  • Last active: Apr 01 2014 01:46 AM
  • Joined: 07 Oct 2006
At the bottom of the list it says it updates every 4 hours.

Krogdor
  • Members
  • 1391 posts
  • Last active: Jun 08 2011 05:31 AM
  • Joined: 18 Apr 2008
Oh, hehe...
I knew that.

tinku99
  • Members
  • 560 posts
  • Last active: Feb 08 2015 12:54 AM
  • Joined: 03 Aug 2007

Here's my solution to Happy Number. I like the idea of posting solutions here first to let others look them over for bugs or optimizations before submitting them on Rosetta Code.

your ahk Happy Number seems to work.

A few suggestions for improvement:
I don't think you have to worry about optimizing too much. Readability is more important IMO.
Consider taking out SetBatchLines.

Also, I would modify the happy() function to accept a number and decide if its happy. Try translating the python example.

I think it would be good to also have a dedicated thread for each rosettacode task posted. It would be easier for people to find, improve, and discuss it later.

sinkfaze
  • Moderators
  • 6367 posts
  • Last active: Nov 30 2018 08:50 PM
  • Joined: 18 Mar 2008
Here is my solution to the Bogosort task, this looks like an AHK equivalent of the Bogosort algorithm:

Lost = 123456789
Loop {
  Seed = 123456789
  Found := ""
  Loop, 9 {
    Random, No, 1, % 10 - A_Index
    Found .= SubStr(Seed,No,1)
    Seed := SubStr(Seed,1,No-1) . SubStr(Seed,No+1)
  }
  if (Lost = Found)
  {
    MsgBox % "We have a match!`n`nLost: " Lost "`nFound: " Found
    break
  }
}

Sorry, at work again and cannot post to the Wiki (but I can do everything else :? ).

sinkfaze
  • Moderators
  • 6367 posts
  • Last active: Nov 30 2018 08:50 PM
  • Joined: 18 Mar 2008
Here's another one for the bubble sort algorithm if someone would like to double-check it:

Seed = 123456789
Loop 9 { 
  Random, No, 1, % 10 - A_Index
  Number .= SubStr(Seed,No,1)
  Seed := SubStr(Seed,1,No-1) . SubStr(Seed,No+1)
}
Lost := Number
Loop {

  if Lost <> 123456789
  {
    Loop 8 {
      if (SubStr(Lost,A_Index,1) > SubStr(Lost,A_Index+1,1))
        Lost := SubStr(Lost,1,A_Index-1) . SubStr(Lost,A_Index+1,1) . SubStr(Lost,A_Index,1) . SubStr(Lost,A_Index+2)
    }
  }
  else
  {
    MsgBox % "You've successfully bubble sorted the number!`n`nStarting number: " Number "`nLost: " Lost
    break
  }
}