Rosetta Code

Talk about anything
User avatar
smorgasbord
Posts: 490
Joined: 30 Sep 2013, 09:34

Re: Rosetta Code

06 Apr 2014, 20:50

kon wrote:Joystick position
Keyboard input/Keypress check
Musical scale
Nth

It's a shame that when Sobriquet was banned (for reasons unknown to me) that his/her existing posts were deleted also. It seems he/she has contributed quite a lot to Rosetta Code.
+1
John ... you working ?
Zelio
Posts: 275
Joined: 30 Sep 2013, 00:45
Location: France

Re: Rosetta Code

06 Apr 2014, 21:43

I wonder why too, maybe a mistake and now nobody know the reason, he posted some smart contributions in this thread.
Also, if you are curious, go to http://www.autohotkey.com/board/topic/1 ... torg-down/
User avatar
nnnik
Posts: 4253
Joined: 30 Sep 2013, 01:01
Location: Germany

Re: Rosetta Code

06 Apr 2014, 23:45

It is possible that he posted into a topic that was about to be nuked.
Recommends AHK Studio
User avatar
joedf
Posts: 7247
Joined: 29 Sep 2013, 17:08
Facebook: J0EDF
Google: +joedf
GitHub: joedf
Location: Canada
Contact:

Re: Rosetta Code

07 Apr 2014, 00:45

Awww man! This is not good. :(
Image Image Image Image Image
Windows 10 x64 Professional, Intel i5-8500 @ 4.00 GHz, 2x8GB DDR4 3143 MHz, NVIDIA GTX 1060 6GB | [About Me] | [ASPDM - StdLib Distribution]
[Populate the AHK MiniCity!] | [Qonsole - Quake-like console emulator] | [LibCon - Autohotkey Console Library] | [About the AHK Foundation]
User avatar
MasterFocus
Posts: 146
Joined: 01 Oct 2013, 09:47
GitHub: MasterFocus
Location: Rio de Janeiro - RJ - Brasil
Contact:

Re: Rosetta Code

07 Apr 2014, 01:01

To everyone (and in case someone knows Sobriquet, please let him know):
Some procedures to automatically deal with spam are currently being tested. His account may have been "pruned" by accident.
That's most certainly what happened. If possible, we will revert the changes (restoring the posts and his account).
Antonio França - git.io | github.com | ahk4.net | sites.google.com
Member of the AHK community since 08/Apr/2009. Moderator since mid-2012.
Need help? Please post on the forum before sending me a PM.
just me
Posts: 6486
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: Rosetta Code

07 Apr 2014, 12:03

jNizM wrote:Added first Post:
- AutoHotkey examples needing attention
Langton's ant could be fixed by d := d + !(a%x%_%y%) - !!(a%x%_%y%)

Since I've been working on the problem, here's another solution (AHK 1.1) using some good ideas of the Aime code and CreateDIB() by SKAN:

Code: Select all

#NoEnv
SetBatchLines, -1
; Directions
Directions := {0: "North", 1: "East", 2: "South", 3: "West"}
; Initialize the plane (set all cells to white)
White := 0xFFFFFF
Plane := []
PW := PH := 100
Loop, % PH {
   I := A_Index
   Loop, % PW
      Plane[I, A_Index] := White
}
; Let it run
DI := D := 0 ; initial direction
X := Y := 50 ; initial coordinates
While (X > 0) && (X <= PW) && (Y > 0) && (Y <= PH) {
   D := (D + ((Plane[X, Y] ^= White) ? 1 : 3)) & 3
   If (D & 1)
      X += -(D = 3) + (D = 1)
   Else
      Y += -(D = 0) + (D = 2)
}
; Show the result
HBM := CreateDIB(Plane, PW, PH, 400, 400, 0)
Gui, Margin, 0, 0
Gui, Add, Text, x0 y0 w20 h440 Center 0x200, W
Gui, Add, Text, x20 y0 w400 h20 Center 0x200, N
Gui, Add, Picture, x20 y20 w400 h400 0x4E hwndHPIC ; SS_REALSIZECONTROL = 0x40 | SS_BITMAP = 0xE
DllCall("User32.dll\SendMessage", "Ptr", HPIC, "UInt", 0x172, "Ptr", 0, "Ptr", HBM) ; STM_SETIMAGE = 0x172
Gui, Add, Text, xp+5 yp h20 0x200 BackgroundTrans, % "Initial direction: " . Directions[DI]
Gui, Add, Text, x20 y420 w400 h20 Center 0x200, S
Gui, Add, Text, x420 y0 w20 h440 Center 0x200, E
Gui, Show, , Langton's ant (%PW%x%PH%)
Return

GuiClose:
ExitApp

CreateDIB(PixelArray, PAW, PAH, BMW := 0, BMH := 0, Gradient := 1) { ; SKAN, 01-Apr-2014 / array version by just me
   SLL := (PAW * 3) + (PAW & 1)
   VarSetCapacity(BMBITS, SLL * PAH, 0)
   P := &BMBITS
   Loop, % PAH {
      R := A_Index
      Loop, % PAW
         P := Numput(PixelArray[R, A_Index], P + 0, "UInt") - 1
      P += (PAW & 1)
   }
   HBM := DllCall("Gdi32.dll\CreateBitmap", "Int", PAW, "Int", PAH, "UInt", 1, "UInt", 24, "Ptr", 0, "UPtr")
   HBM := DllCall("User32.dll\CopyImage", "Ptr", HBM, "UInt", 0, "Int", 0, "Int", 0, "UInt", 0x2008, "UPtr")
   DllCall( "Gdi32.dll\SetBitmapBits", "Ptr", HBM, "UInt", SLL * PAH, "Ptr", &BMBITS)
   If (!Gradient)
      HBM := DllCall("User32.dll\CopyImage", "Ptr", HBM, "UInt", 0, "Int", 0, "Int", 0, "Int", 8, "UPtr")
   Return DllCall("User32.dll\CopyImage", "Ptr", HBM, "UInt", 0, "Int", BMW, "Int", BMH, "UInt", 0x200C, "UPtr")
} ; http://ahkscript.org/boards/viewtopic.php?f=6&t=3203
User avatar
jNizM
Posts: 2503
Joined: 30 Sep 2013, 01:33
GitHub: jNizM
Contact:

Re: Rosetta Code

08 Apr 2014, 00:47

Thx for your help and I uploaded your version

Fixed:
- Langton's ant (by just me)
[AHK] 1.1.30.03 x64 Unicode | [WIN] 10 Pro (Version 1903) x64 | [GitHub] Profile
Donations are appreciated if I could help you
just me
Posts: 6486
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: Rosetta Code

09 Apr 2014, 04:07

First-class functions

I believe that this should meet the requirements (but there might be better/easier solutions):

Code: Select all

#NoEnv
; Set the floating-point precision
SetFormat, Float, 0.15
; Super-global variables for function objects
Global F, G
; User-defined functions
Cube(X) {
   Return X ** 3
}
CubeRoot(X) {
   Return X ** (1/3)
}
; Function arrays, Sin/ASin and Cos/ACos are built-in
FuncArray1 := [Func("Sin"),  Func("Cos"),  Func("Cube")]
FuncArray2 := [Func("ASin"), Func("ACos"), Func("CubeRoot")]
; Compose
Compose(FN1, FN2) {
   Static FG := Func("ComposedFunction")
   F := FN1, G:= FN2
   Return FG
}
ComposedFunction(X) {
   Return F.(G.(X))
}
; Run
X := 0.5 + 0
Result := "Input:`n" . X . "`n`nOutput:"
For Index In FuncArray1
   Result .= "`n" . Compose(FuncArray1[Index], FuncArray2[Index]).(X)
MsgBox, 0, First-Class Functions, % Result
ExitApp
kon
Posts: 1756
Joined: 29 Sep 2013, 17:11

Re: Rosetta Code

16 Apr 2014, 23:58

Added First-class functions by just me.

Also added:
Emirp primes
Extensible prime generator
Hello world/Newbie

I've started to work on Polymorphism as a way to learn about classes. I would appreciate some feedback and corrections before I post it to Rosetta Code.
Polymorphism - Task Description wrote:Create two classes Point(x,y) and Circle(x,y,r) with a polymorphic function print, accessors for (x,y,r), copy constructor, assignment and destructor and every possible default constructors

Code: Select all

MyCircle := new Circle(4, 7, 9)
MyCircle2 := MyCircle.Clone()
MyCircle.SetX(2)
MyCircle.SetY(3)
MyCircle.Print()
MyCircle2.Print()
MyCircle.SetX(100), MyCircle.SetY(1000), MyCircle.SetR(10000) 
MsgBox, % MyCircle.GetX() "`n" MyCircle.GetY() "`n" MyCircle.GetR() "`n" 
return

class Point
{
	GetX()
	{
		return this.x
	}
	GetY()
	{
		return this.y
	}
	__New(x, y)
	{
		this.x := x
		this.y := y
	}
	Print()
	{
		MsgBox, % "Point`n`nx:`t" this.x "`ny:`t" this.y
	}
	SetX(aValue)
	{
		this.x := aValue
	}
	SetY(aValue)
	{
		this.y := aValue
	}
}

class Circle extends Point
{
	GetR()
	{
		return this.r
	}
	__New(x, y, r)
	{
		this.r := r
		base.__New(x, y)
	}
	Print()
	{
		MsgBox, % "Circle`n`nx:`t" this.x "`ny:`t" this.y "`nr:`t" this.r
	}
	SetR(aValue)
	{
		this.r := aValue
	}
}
Edit: When the task description says "assignment" and "accessors", does it require a method like GetX() and SetX() or can it just be done with MyCircle.x := 2.
just me
Posts: 6486
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: Rosetta Code

17 Apr 2014, 02:38

I think that you could add two versions. AHK doesn't support private/protected properties and thus doesn't need assignment and accessor methods. On the other hand, the code posted above is corresponding to many samples of other languages. Maybe you might add a Copy() method returning This.Clone() this code.
kon
Posts: 1756
Joined: 29 Sep 2013, 17:11

Re: Rosetta Code

18 Apr 2014, 13:45

@just me thanks for the input and taking the time to look it over. I've posted it to Rosetta Code. I added a copy method as you suggested and also used your explanation:
AHK doesn't support private/protected properties and thus doesn't need assignment and accessor methods.
Instead of writing two versions of the task, I both included the assignment and accessor methods, and demonstrated directly accessing the properties also.
Thanks again.
kon
Posts: 1756
Joined: 29 Sep 2013, 17:11

Re: Rosetta Code

19 Apr 2014, 17:18

These are pretty simple. IBAN is the only one that's more than a handful of lines.

Generate lower case ASCII alphabet
IBAN
Read a file character by character/UTF8
User avatar
joedf
Posts: 7247
Joined: 29 Sep 2013, 17:08
Facebook: J0EDF
Google: +joedf
GitHub: joedf
Location: Canada
Contact:

Re: Rosetta Code

04 May 2014, 13:30

good idea adding the machine code there!
Image Image Image Image Image
Windows 10 x64 Professional, Intel i5-8500 @ 4.00 GHz, 2x8GB DDR4 3143 MHz, NVIDIA GTX 1060 6GB | [About Me] | [ASPDM - StdLib Distribution]
[Populate the AHK MiniCity!] | [Qonsole - Quake-like console emulator] | [LibCon - Autohotkey Console Library] | [About the AHK Foundation]
kon
Posts: 1756
Joined: 29 Sep 2013, 17:11

Re: Rosetta Code

04 May 2014, 15:58

Thanks joedf!
That task is still just a draft task. There seems to be some skepticism on the talk page regarding the usefulness of MCode. But MCode has been a valuable and powerful tool for AutoHotkey users.
User avatar
joedf
Posts: 7247
Joined: 29 Sep 2013, 17:08
Facebook: J0EDF
Google: +joedf
GitHub: joedf
Location: Canada
Contact:

Re: Rosetta Code

04 May 2014, 16:07

Yeah, true.. There's two versions of the MCode() function that i know of..
Id say that the advantage of mcode is speed..
Image Image Image Image Image
Windows 10 x64 Professional, Intel i5-8500 @ 4.00 GHz, 2x8GB DDR4 3143 MHz, NVIDIA GTX 1060 6GB | [About Me] | [ASPDM - StdLib Distribution]
[Populate the AHK MiniCity!] | [Qonsole - Quake-like console emulator] | [LibCon - Autohotkey Console Library] | [About the AHK Foundation]
kon
Posts: 1756
Joined: 29 Sep 2013, 17:11

Re: Rosetta Code

04 May 2014, 16:16

joedf wrote:Id say that the advantage of mcode is speed..
Agreed. Plus you can include all the code in the script itself.
User avatar
nnnik
Posts: 4253
Joined: 30 Sep 2013, 01:01
Location: Germany

Re: Rosetta Code

05 May 2014, 01:36

joedf wrote:Yeah, true.. There's two versions of the MCode() function that i know of..
Id say that the advantage of mcode is speed..
You can also do low level tasks easier.
Recommends AHK Studio

Return to “Offtopic”

Who is online

Users browsing this forum: No registered users and 25 guests