AutoHotkey Community

It is currently May 27th, 2012, 5:56 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 417 posts ]  Go to page Previous  1 ... 22, 23, 24, 25, 26, 27, 28  Next
Author Message
PostPosted: June 7th, 2010, 4:10 am 
Offline

Joined: August 3rd, 2007, 8:01 am
Posts: 555
Location: Houston, TX
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.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: June 7th, 2010, 5:07 am 
Offline

Joined: October 18th, 2007, 9:21 pm
Posts: 343
Location: Saarland, Germany
@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!


Report this post
Top
 Profile  
Reply with quote  
 Post subject: paddy's objection
PostPosted: June 7th, 2010, 5:15 am 
Offline

Joined: August 3rd, 2007, 8:01 am
Posts: 555
Location: Houston, TX
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


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: June 7th, 2010, 5:31 am 
Offline

Joined: October 18th, 2007, 9:21 pm
Posts: 343
Location: Saarland, Germany
@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!


Report this post
Top
 Profile  
Reply with quote  
PostPosted: June 8th, 2010, 5:04 am 
Offline

Joined: August 3rd, 2007, 8:01 am
Posts: 555
Location: Houston, TX
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 ... 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


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 9th, 2010, 7:53 am 
Offline

Joined: April 8th, 2009, 8:23 pm
Posts: 3036
Location: Rio de Janeiro - RJ - Brasil
[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.
"
Image
Antonio França
My stuff: Google Profile


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: September 12th, 2010, 2:42 pm 
Offline

Joined: July 31st, 2008, 10:27 pm
Posts: 336
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)
}


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: September 12th, 2010, 7:13 pm 
Offline

Joined: February 14th, 2005, 4:05 pm
Posts: 4710
Location: Boulder, CO
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
}


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: September 12th, 2010, 7:39 pm 
Offline

Joined: July 31st, 2008, 10:27 pm
Posts: 336
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. :)


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: September 13th, 2010, 1:32 am 
Offline

Joined: July 31st, 2008, 10:27 pm
Posts: 336
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


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: September 14th, 2010, 3:28 pm 
Offline

Joined: October 7th, 2006, 4:50 pm
Posts: 3157
Location: MN, USA
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


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: September 14th, 2010, 4:35 pm 
Offline
User avatar

Joined: December 26th, 2005, 4:40 pm
Posts: 8776
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


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: September 18th, 2010, 3:05 pm 
Offline

Joined: July 31st, 2008, 10:27 pm
Posts: 336
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)


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: September 18th, 2010, 3:28 pm 
Offline
User avatar

Joined: November 2nd, 2008, 4:23 pm
Posts: 2906
Location: 127.0.0.1
What do you mean by 'no script listing'? I see all the completed tasks at the bottom of the page.

_________________
aboutscriptappsscripts
Any code ⇈ above ⇈ requires AutoHotkey_L to run


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: September 18th, 2010, 4:00 pm 
Offline

Joined: July 31st, 2008, 10:27 pm
Posts: 336
Sorry, it must be something on my end.


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 417 posts ]  Go to page Previous  1 ... 22, 23, 24, 25, 26, 27, 28  Next

All times are UTC [ DST ]


Who is online

Users browsing this forum: codybear and 4 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group