Page 6 of 11

Re: Rosetta Code

Posted: 09 Feb 2014, 03:07
by tomoe_uehara
Hmmh, I don't know how to submit to the page :P
http://rosettacode.org/wiki/Grayscale_image

Code: Select all

#SingleInstance, Force
#NoEnv
SetBatchLines, -1
OnExit, Exit
; Uncomment if Gdip.ahk is not in your standard library
;#Include, Gdip.ahk
If !pToken := Gdip_Startup(){
   MsgBox, 48, Gdiplus error!, Gdiplus failed to start. Please ensure you have Gdiplus on your system.
   ExitApp
}
if (Gdip_LibraryVersion() < 1.30)
{
	MsgBox, 48, Version error!, Please download the latest version of the gdi+ library
	ExitApp
}
URLDownloadToFile, http://rosettacode.org/mw/images/4/4e/BASIC256_greyscale_Mona_Lisa.jpg, %A_ScriptDir%\Before.jpg
Width := A_ScreenWidth, Height := A_ScreenHeight
Gui, 1: -Caption +E0x80000 +LastFound +OwnDialogs +Owner +AlwaysOnTop
Gui, 1: Show, NA
hwnd1 := WinExist()
hbm := CreateDIBSection(Width, Height)
hdc := CreateCompatibleDC()
obm := SelectObject(hdc, hbm)
G := Gdip_GraphicsFromHDC(hdc)
Gdip_SetSmoothingMode(G, 4)
File = %A_ScriptDir%\Before.jpg
Matrix = 0.2126|0.2126|0.2126|0|0|0.7152|0.7152|0.7152|0|0|0.0722|0.0722|0.0722|0|0|0|0|0|1|0|0|0|0|0|1
pBitmap := Gdip_CreateBitmapFromFile(File)
Gdip_GetDimensions(pBitmap, w, h)
Gdip_DrawImage(G, pBitmap, 0, 0, w, h, 0, 0, w, h)
Gdip_DrawImage(G, pBitmap, 0, h+10, w, h, 0, 0, w, h, Matrix)
Gdip_DisposeImage(pBitmap)
UpdateLayeredWindow(hwnd1, hdc, 0, 0, Width, Height)
return

ESC::
Exit:
Gdip_Shutdown(pToken)
ExitApp
Here's what I use to check AutoHotkey's rank

Code: Select all

File = %A_ScriptDir%\Rosetta.htm
UrlDownloadToFile, http://rosettacode.org/wiki/RC_POP.OUT, %File%
Loop, Read, %File%
{
    LineNumber = %A_Index%
    Loop, parse, A_LoopReadLine, `n
    {
        IfInString, A_LoopReadLine, rank:
	if Result is Space
	Result := A_LoopReadLine
	else
	Result := Result . "`n" . A_LoopReadLine
	IfInString, A_LoopReadLine, AutoHotkey
	ahk := A_LoopReadLine
    }
}
Gui, Add, Edit, w300 ReadOnly, %ahk%
Gui, Add, Edit, w300 h600 ReadOnly, %Result%
Gui, Show,, Rosetta Code Rank
FileDelete, %File%
return

Esc::
ExitApp

Re: Rosetta Code

Posted: 09 Feb 2014, 05:13
by smorgasbord
@Tomoe_uehara
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
=={{header|AutoHotkey}}==
<lang Autohotkey>


YOuR code in here.

</lang>
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Put it above the code seen in this
http://rosettacode.org/mw/index.php?tit ... &section=2

btw: last time i guess our ranking was above 19th .. AHK needs so many more codes to be top 10.

Re: Rosetta Code

Posted: 09 Feb 2014, 06:46
by xZomBie
Since this topic contains some links to Rosetta Code and sometimes codes in AHK, shouldn't it be moved to Scripts and Functions?

*OFFTOPIC: How can I set my account to an AutoHotkey user?

Re: Rosetta Code

Posted: 09 Feb 2014, 12:13
by kon
Added: Fractal tree

@tomoe_uehara,
In addition to what @smorgasbord said, when adding a new language example to a page you can either "edit" the whole page to add your new entry, or you can scroll down to the language closest to Autohotkey alphabetically and "edit" that by adding the AHK tags and code to that post.

If your code requires any additional libraries (like gdip), you should include a lib header which will add a link to the library's page.

If your code outputs text and the task requires you to show your output, you can use the <pre> tags.

Code: Select all

=={{header|AutoHotkey}}==
{{libheader|GDIP}}
<lang AutoHotkey>Your AHK code goes here</lang>
'''Output:'''
<pre>Any output text goes here</pre>
Change the "Summary" box to /* {{header|AutoHotkey}} */ Created AutoHotkey entry. This will show on the page history telling people what language tag you edited and briefly describes what you have done.

Edit: There's also the Editing Help page.

Re: Rosetta Code

Posted: 10 Feb 2014, 01:05
by just me
@kon:

Four bit adder

Code: Select all

GetFourBits(N) {
	if (N < 1 || N > 15)
		return -1
	return StrSplit(GetBin4(N))
}
Why should 0 be invalid?

Re: Rosetta Code

Posted: 10 Feb 2014, 01:17
by kon
Whoops! :oops:
Fixed. Thanks just me. :D

Re: Rosetta Code

Posted: 10 Feb 2014, 01:24
by joedf
Haha nice

Re: Rosetta Code

Posted: 11 Feb 2014, 11:56
by smorgasbord

Re: Rosetta Code

Posted: 12 Feb 2014, 10:02
by smorgasbord

Re: Rosetta Code

Posted: 12 Feb 2014, 18:01
by MasterFocus
@kon: The XOR operation, IIRC, can be achieved in AHK by result := foo ^ bar
@smorgasbord: Is the code for those tasks finished? It doesn't look like. It's hard to read (bad indentation) and I found things like Loop, 1 and Goto.

Also, who uploaded the AHK code for the Pi task? I guess a simple translation from Pascal could solve the task without requiring additional libraries.

Re: Rosetta Code

Posted: 12 Feb 2014, 20:17
by kon
MasterFocus wrote:@kon: The XOR operation, IIRC, can be achieved in AHK by result := foo ^ bar
Yes, ^ is the xor operator, but not, or and and are the only allowed "gates" for the task.
This "chip" can be realized using four 1-bit full adders. Each of these 1-bit full adders can be (made) with two half adders and an or gate. Finally a half adder can be made using a xor gate and an and gate. The xor gate can be made using two nots, two ands and one or.
MasterFocus wrote:@smorgasbord: Is the code for those tasks finished? It doesn't look like. It's hard to read (bad indentation) and I found things like Loop, 1 and Goto.
I have to agree. It's great that the tasks are being completed, but it needs major editing.

Re: Rosetta Code

Posted: 12 Feb 2014, 21:10
by smorgasbord
@MasterFocus
Thanks for reviewing the codes, and the suggestions as such.
:D
It cannot be improved otherwise.
btw: Are loop,1 and Goto commands not to be used in the codes?
Also for indentation i used pastebin.com's syntax highlighting, Bt will surely polish the codes further by asking for help at #ahkscript. The Channel rocks!!

@k0n
Thanks for cross checking, and saying the code is fine that the tasks are complete, 8-)
Point taken, will surely indent the codes better.

All hail AHK!

When will our rank be improved further, it is kind of stuck at 19th. :cry:

Re: Rosetta Code

Posted: 12 Feb 2014, 21:38
by kon
@smorgasbord -> http://ahkscript.org/boards/viewtopic.php?f=6&t=994

:D I did a bit of editing for "Anagrams/Deranged anagrams". Hope you don't mind.
There are more things that can be improved, like find an alternative to Loop, 1. And maybe instead of using stringsplit so much, use arrays or something else.
I didn't change the overall logic of your code. I just added indenting, and sometimes found some simpler ways to do bits of the intermediate code.
And yes, GoTo is generally frowned upon in most languages AFAIK.
Keep up the good work!

Re: Rosetta Code

Posted: 13 Feb 2014, 00:19
by MasterFocus
Loop, 1 is just dumb, since it's not looping at all.
I won't even go into the Goto discussion again...

@kon: Wow, I didn't even know about that thread.
Reminds me of my FloatToFraction() function: http://www.autohotkey.com/board/topic/8 ... tofraction
(which shouldn't be uploaded to Rosetta Code - conflicting licenses)

I have written code for the Pi task which doesn't require any libraries and should work for any AHK version (including 1.0.*).
I'll try to upload it before saturday.

Re: Rosetta Code

Posted: 13 Feb 2014, 03:01
by smorgasbord
i started to from scratch to make the rosetta code, also did not read any of the codes related to the same, though i surely asked masterfocus long time back about the thing, but this one i made from scratch. dont know if copied some used same logic.
kon wrote: :D I did a bit of editing for "Anagrams/Deranged anagrams". Hope you don't mind.
NEVER! not a bit. i jst wish ahk becomes top 10. :) you sir are surely better than me like 100 times. so no worries at all.
kon wrote:There are more things that can be improved, like find an alternative to Loop, 1. And maybe instead of using stringsplit so much, use arrays or something else.
I shall try to improve.
kon wrote:I didn't change the overall logic of your code. I just added indenting, and sometimes found some simpler ways to do bits of the intermediate code.
That is actually cool, because let say if someone sees that code, your code will appeal more than mine.
kon wrote:And yes, GoTo is generally frowned upon in most languages AFAIK.
Me only know AHK, period. :ugeek:
kon wrote:Keep up the good work!
Atleast you liked it that surely motivates me more.

All Hail AHK!

Re: Rosetta Code

Posted: 13 Feb 2014, 10:48
by MasterFocus
@Sobriquet: I see your point. I won't check the links now but I remember we have to set "in advance" a certain variable (Length), so I understand what you're saying. Perhaps someone should note this in that task's discussion?

Re: Rosetta Code

Posted: 13 Feb 2014, 19:26
by MasterFocus
@Sobriquet: Thanks for the feedback! I will add my version later.

I have solved DNS Query and will also upload the code later.

Re: Rosetta Code

Posted: 15 Feb 2014, 15:21
by kon
Added:
Plot coordinate pairs
Quickselect algorithm

Fixed:
Quaternion type - added functions as per the main task requirement, and fixed formating. :roll:

Re: Rosetta Code

Posted: 16 Feb 2014, 00:00
by smorgasbord
kon wrote: Fixed:
Quaternion type - added functions as per the main task requirement, and fixed formating. :roll:
it was me :)

Re: Rosetta Code

Posted: 17 Feb 2014, 11:52
by smorgasbord
FIXED:Anagrams
Dont wish to shake the titan i.e. Laszlo ( as the name appears in the link)
here is the code

Code: Select all

array := []
fileread, k, unixdict.txt
loop, parse, k, `n, `r
{
 a := RegExReplace(A_loopfield,".","$0`n")
 sort a
 a := RegExReplace(a,"`n","")
 list .= a " " A_loopfield "`n"
 }

sort list

loop, parse, list, `n, `r
	array[A_index] := A_loopfield
loop, parse, list, `n, `r
{
	StringSplit, o_t, A_loopfield, %A_space%
o := o_t1
break
}


loop, parse, list, `n, `r
{
	index := A_index+1
	StringSplit, o_t, A_loopfield, %A_space%
	if ( o = o_t1 )
	{
				list2 .= "`n" o_t1 "-" t  ","  o_t2
								loop,{
									new := Array[index]									
									StringSplit, n_t, new, %A_space%
												if ( o = n_t1)
															List2 := list2 . "," . n_t2 
												else
										           break
									index++
								        }										  
	}
			o := o_t1,  t := o_t2,
}

loop, parse, list2, `n
{
	StringSplit, comma, A_loopfield, `,
	list3 .= comma0 . " " . A_loopfield . "`n"
}
 sort list3, R 
 loop, parse, list3, `n, `r
{
	if ( A_loopfield != "" )
	StringSplit, end, A_loopfield, %A_space%
break
}

	loop, parse, list3, `n, `r
	{
		StringSplit, final, A_loopfield, %A_Space%
		if (final1 = end1)
			res .= final2 "`n"
		else
			break
	}
	clipboard := res
	MsgBox % res
exitapp
Edited, now clipboard contains the desired output