 |
AutoHotkey Community Let's help each other out
|
| View previous topic :: View next topic |
| Author |
Message |
tinku99
Joined: 03 Aug 2007 Posts: 513 Location: Houston, TX
|
Posted: Mon Jun 07, 2010 3:10 am Post subject: bignum library and machine code |
|
|
| wolf_II wrote: | | I don't think your Multi Precision Library would be appropriate to submit to Rosetta Code, as it contains machine code compiled from C source code. | I don't think the machine code is an issue, since Laszlo provides the c source code. It would be trivial to compile it into a dll, and use that instead... machine code is machine code regardless of weather it is in a compile exe, dll, or text in an ahk file.
If Laszlo has no objection, I would like to use his long integer arithmetic library to solve rosettacode tasks including the arbitrary precision arithmetic task. |
|
| Back to top |
|
 |
wolf_II
Joined: 18 Oct 2007 Posts: 343 Location: Saarland, Germany
|
Posted: Mon Jun 07, 2010 4:07 am Post subject: |
|
|
@tinku99: Please have a look at my little discussion with Michael Mol (Mr. RosettaCode) about the task "Arbitrary-precision_integers_(included)" here. And I have to admit that the objection raised by Paddy3118 (Mr. QualityInsurance) didn't please me, but convinced me. This, naturally, does not mean MPL.ahk can't be used for other tasks.
Nicknames in brackets are included for followers, who might wonder who is who on RosettaCode.org.
While I'm at it, I also addressed Paddy3118 about CombSort here, which lead to the changes of the task description.
Also, the discussion on the german forum has produced a slightly improved Lucas-Lehmer test: (still not submitted):
| Code: | SetBatchLines, -1
M := 3, out := "Mersenne primes:`n"
While M < 32 {
a = 4
Loop, % M - 2
a := Mod(a*a - 2, 2**M - 1)
If a = 0
MsgBox, % out .= " M" M ","
M++
} |
The changes marked in red allow the code (a) to finish properly, and (b) to produce M31. _________________ Wolf
Schön wär's, wenn's schön wär! |
|
| Back to top |
|
 |
tinku99
Joined: 03 Aug 2007 Posts: 513 Location: Houston, TX
|
Posted: Mon Jun 07, 2010 4:15 am Post subject: paddy's objection |
|
|
| wolf_II wrote: | | @tinku99: Please have a look at my little discussion with Michael Mol (Mr. RosettaCode) about the task "Arbitrary-precision_integers_(included)" here. And I have to admit that the objection raised by Paddy3118 (Mr. QualityInsurance) didn't please me, but convinced me. | Paddy has come around: heresee the bottom of the "Use of external libraries" paragraph |
|
| Back to top |
|
 |
wolf_II
Joined: 18 Oct 2007 Posts: 343 Location: Saarland, Germany
|
Posted: Mon Jun 07, 2010 4:31 am Post subject: |
|
|
@tinku: That's great news. May I suggest not to link to the forum page itself please, (this particular page takes ages to load in Opera, maybe it's the code parser), but to host it on Autohotkey.net.
@Laszlo: Would you please reconsider your decision about hosting MPL.ahk, as there is growing interest in your library now?
EDIT: checked it right now, the page seems to load without problems, I had great problems with it in the past. (I am talking 10 minutes loading time.) _________________ Wolf
Schön wär's, wenn's schön wär! |
|
| Back to top |
|
 |
tinku99
Joined: 03 Aug 2007 Posts: 513 Location: Houston, TX
|
Posted: Tue Jun 08, 2010 4:04 am Post subject: Read_an_image_through_a_pipe |
|
|
fixed some bugs in bitmap_storage and updated read_ppm to read binary ppm images.
Also implemented this one, unsolved until now: http://rosettacode.org/wiki/Bitmap/Read_an_image_through_a_pipe#AutoHotkey | Code: | ppm := Run("cmd.exe /c convert lena50.jpg ppm:-")
; pipe in from imagemagick
img := ppm_read("", ppm) ;
x := img[4,4] ; get pixel(4,4)
y := img[24,24] ; get pixel(24,24)
msgbox % x.rgb() " " y.rgb()
img.write("lena50copy.ppm")
return
ppm_read(filename, ppmo=0) ; only ppm6 files supported
{
if !ppmo ; if image not already in memory, read from filename
fileread, ppmo, % filename
index := 1
pos := 1
loop, parse, ppmo, `n, `r
{
if (substr(A_LoopField, 1, 1) == "#")
continue
loop,
{
if !pos := regexmatch(ppmo, "\d+", pixel, pos)
break
bitmap%A_Index% := pixel
if (index == 4)
Break
pos := regexmatch(ppmo, "\s", x, pos)
index ++
}
}
type := bitmap1
width := bitmap2
height := bitmap3
maxcolor := bitmap4
bitmap := Bitmap(width, height, color(0,0,0))
index := 1
i := 1
j := 1
bits := pos
loop % width * height
{
bitmap[i, j, "r"] := numget(ppmo, 3 * A_Index + bits, "uchar")
bitmap[i, j, "g"] := numget(ppmo, 3 * A_Index + bits + 1, "uchar")
bitmap[i, j, "b"] := numget(ppmo, 3 * A_Index + bits + 2, "uchar")
if (j == width)
{
j := 1
i += 1
}
else
j++
}
return bitmap
}
#include bitmap_storage.ahk ; from http://rosettacode.org/wiki/Basic_bitmap_storage/AutoHotkey
#include run.ahk ; http://www.autohotkey.com/forum/viewtopic.php?t=16823 |
|
|
| Back to top |
|
 |
MasterFocus
Joined: 08 Apr 2009 Posts: 3035 Location: Rio de Janeiro - RJ - Brasil
|
Posted: Mon Aug 09, 2010 6:53 am Post subject: |
|
|
[1]
The code found in this topic can probably solve this task.
Someone should adapt and upload it.
[2]
Can this be solved via VarSetCapacity? _________________ "Read the manual. Read it again. Search the forum.
Try something before asking. Show what you've tried."
Antonio França
My stuff: Google Profile |
|
| Back to top |
|
 |
Morpheus
Joined: 31 Jul 2008 Posts: 277
|
Posted: Sun Sep 12, 2010 1:42 pm Post subject: |
|
|
My solution to http://rosettacode.org/wiki/Closest-pair_problem
Brute force method. I would prefer it if you guys would look it over, and then post it for me.
| Code: | ListofPoints = [0,-.3][1,1][1.5,2][2,2][3,3]
BruteForceClosestPair(ListofPoints)
ExitApp
BruteForceClosestPair(ListofPoints){
StringReplace, ListofPoints, ListofPoints, [,, A
StringSplit, p, ListofPoints, ]
p0--
If p0 < 2
MinDistance = Infinity
Else
{
MinDistance := Distance(p1,p2)
MinPoints := "[" . p1 . "," . p2 . "]"
i=1
While i < p0-1
{
i++
j:=i+1
While j <= p0
{
Distance := Distance(p%i%,p%j%)
if Distance < %MinDistance%
{
MinDistance := Distance
MinPoints := "[" . p%i% . "][" . p%j% . "]"
}
j++
}
}
}
MsgBox, %MinDistance%`n%MinPoints%
}
Distance(p1, p2) {
StringSplit, p1, p1, `,
StringSplit, p2, p2, `,
dx := abs(p11 - p21)
dy := abs(p12 - p22)
Return sqrt(dx*dx + dy*dy)
} |
|
|
| Back to top |
|
 |
Laszlo
Joined: 14 Feb 2005 Posts: 4710 Location: Boulder, CO
|
Posted: Sun Sep 12, 2010 6:13 pm Post subject: |
|
|
You could write it in a little more compact way: | Code: | Points = 0,-3|10,10|15,20|20,20|30,25
ClosestPair(D,I,J, Points)
MsgBox % "min distance: D(" I "," J ") = " sqrt(D)
ClosestPair(ByRef minD, ByRef minI, ByRef minJ, Points) {
StringSplit p, Points, |
minD := D2(p1,p2), minI := 1, minJ := 2
Loop % p0-1 {
i := A_Index
Loop % p0-i {
j := i+A_Index, d := D2(p%i%,p%j%)
If (minD > d)
minD := d, minI := i, minJ := j
}
}
}
D2(p1,p2) { ; squared distance
StringSplit p1, p1, `,
StringSplit p2, p2, `,
Return (p11-p21)**2 + (p12-p22)**2
} |
|
|
| Back to top |
|
 |
Morpheus
Joined: 31 Jul 2008 Posts: 277
|
Posted: Sun Sep 12, 2010 6:39 pm Post subject: |
|
|
Nice work Laszlo. I thought I might tackle a few of the easier ones for the practice. Then I can learn some more from you guys when you work your magic on my code. I hope that is OK, and that it will not be irritating to the masters.  |
|
| Back to top |
|
 |
Morpheus
Joined: 31 Jul 2008 Posts: 277
|
Posted: Mon Sep 13, 2010 12:32 am Post subject: |
|
|
My solution to http://rosettacode.org/wiki/GUI_component_interaction
I would prefer it if you guys would look it over, and then post it for me.
| Code: | Gui, Add, Button, w60, Increment
Gui, Add, Button, w60, Random
Gui, Add, Edit, x80 y20 w33 Limit4 Number vNumber, 0
Gui, Show, w120
Return
ButtonRandom:
MsgBox, 4,, Enter Random Number?
IfMsgBox Yes
{
Random, RandNum, 0, 9999
GuiControl,, Number, %RandNum%
}
Return
ButtonIncrement:
GuiControlGet, Number
Number++
If Number = 10000
Number = 0
GuiControl,, Number, %Number%
Return |
|
|
| Back to top |
|
 |
jaco0646
Joined: 07 Oct 2006 Posts: 3113 Location: MN, USA
|
Posted: Tue Sep 14, 2010 2:28 pm Post subject: |
|
|
This isn't better per se, but a little different way I would do it (same number of lines). | Code: | Gui, Add, Edit , w160 Number vNum, 0
Gui, Add, Button, w75 , Increment
Gui, Add, Button, wp x+10 , Random
Gui, Show
return
GuiClose:
ExitApp
ButtonRandom:
Gui, +OwnDialogs
MsgBox,36,,Enter Random Number?
IfMsgBox, No
return
Random, RandNum
GuiControl,,Num, %RandNum%
return
ButtonIncrement:
Gui, Submit, NoHide
GuiControl,,Num, % ++Num
return |
|
|
| Back to top |
|
 |
SKAN
Joined: 26 Dec 2005 Posts: 8688
|
Posted: Tue Sep 14, 2010 3:35 pm Post subject: |
|
|
| Code: | Gui, Add, Edit, x5 y5 w240 h20 Number Right vNumber, 0
Gui, Add, Button, x110 w60 h25 gGuiClose +Default, Increment
Gui, Add, Button, x+10 yp hp gGuiClose, Random
Gui, Show,, GUI component interaction
Return ; // end of auto-execute section //
GuiClose:
IfEqual, A_GuiControl,,ExitApp
IfEqual, A_GuiControl, Random, Random,Number
IfEqual, A_GuiControl, Random, MsgBox, 36,, Enter Random Number?
IfEqual, A_GuiControl, Random, IfMsgBox,Yes, GuiControl,,Number,%Number%
IfEqual, A_GuiControl, Increment, GuiControlGet, Number
IfEqual, A_GuiControl, Increment, GuiControl,, Number, % Number ? Number+1 : 1 |
|
|
| Back to top |
|
 |
Morpheus
Joined: 31 Jul 2008 Posts: 277
|
Posted: Sat Sep 18, 2010 2:05 pm Post subject: |
|
|
It would appear that there is a problem with the autohotkey page on rosetta code.
http://rosettacode.org/wiki/Category:AutoHotkey
There is no script listing for AHK.
| Quote: |
The server underwent software changes on Sunday, September 12th 2010. Please report any regressions you notice.
This notice will be removed in one from posting. --Michael Mol 22:25, 12 September 2010 (UTC) |
|
|
| Back to top |
|
 |
Frankie
Joined: 02 Nov 2008 Posts: 2850
|
Posted: Sat Sep 18, 2010 2:28 pm Post subject: |
|
|
What do you mean by 'no script listing'? I see all the completed tasks at the bottom of the page. _________________ aboutscript ⍟ apps ⍟ scripts
Any code ⇈ above ⇈ requires AutoHotkey_L to run |
|
| Back to top |
|
 |
Morpheus
Joined: 31 Jul 2008 Posts: 277
|
Posted: Sat Sep 18, 2010 3:00 pm Post subject: |
|
|
| Sorry, it must be something on my end. |
|
| Back to top |
|
 |
|
|
You can post new topics in this forum You can reply to topics in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|