User talk:Ledrug

From Rosetta Code

Levenshtein distance C code

I Just noticed that you posted a recursive C solution for Levenshtein distance. Could you maybe explain (here or in/near the example) what the variables mean in that solution? I tried to come up with a recursive solution in Java myself, but it didn't work out so well. If at all possible could you maybe just give some pseudocode for the recursive algorithm? --Mwn3d 20:25, 20 June 2011 (UTC)

The recursion function has 4 parameters: s, string 1; ls: length of s; t: string 2; lt length of t. Basically, <lang>function levenschtein(s, t)
   if length(s) = 0: return length(t)
   if length(t) = 0: return length(s)
   if s[0] = t[0]  : return levelschtein(s[1 .. end], t[1 .. end])
   len1 := levelschtein(s, t[1 .. end]) + 1
   len2 := levelschtein(s[1 .. end], t) + 1
   len3 := levelschtein(s[1 .. end], t[1 .. end]) + 1
   return min(len1, len2, len3)

</lang>where s[0] meaning first char in string s; s[1 .. end] meaning s without first char. (heh this reads just like the C code. I suck at pseudo code.) --Ledrug 20:39, 20 June 2011 (UTC)

Oh duh. C strings. Forgot about passing around lengths separately. So this says if either string is empty, return the length of the other string (because you just insert or delete all of the other string). If the first chars are the same, nothing needs to happen so just ignore them. Otherwise try deleting one char (len1), inserting one char (len2), or essentially making the first chars the same (as len3 but count the move this time), and return the minimum distance from those. OK I think I got it. Thanks for that. It's really close to what I was thinking of when I tried to do it, but this makes much more sense. I'll try to translate it soon. --Mwn3d 20:50, 20 June 2011 (UTC)
Any chance you might add this to the tasks talk page? I'll be adding a (memoized) version of this in the Python section. Thanks. --Paddy3118 21:45, 20 June 2011 (UTC)
But the wikipedia solution is the memoized version, though? --Ledrug 22:26, 20 June 2011 (UTC)
Hi, there are no recursive calls here. --Paddy3118 05:15, 21 June 2011 (UTC)
Yeah I know, I meant if you memoize the results and convert recursion to iteration, they are exactly the same algorithm. I guess recursive version expresses the idea better, maybe. --Ledrug 05:18, 21 June 2011 (UTC)

Hough transform C code

Rather than adding {{incorrect}}, it's probably more appropriate to just fix the code. Also, while I definitely appreciate the expertise and perspective I've seen you bringing to many areas across the wiki, calling code out as a 'shame', particularly in the page body itself, is inappropriate. Since the code implements the task, it's technically correct. If you'd like to raise suggested fixes (without implementing them yourself), you should raise them in the talk pages, as you've been doing elsewhere. --Michael Mol 01:10, 23 June 2011 (UTC)

Point 3 was minor, the key issue was the black artifact at bottom and the processing order. Yes I shouldn't called it a shame, sorry. I was looking at coding it, but I need to simple down the lib requirement first. --Ledrug 01:14, 23 June 2011 (UTC)

Welcome

Not going to drop the boilerplate greeting; I need to update it, I think. However, I've seen you as one of a few particularly active new users in the last few months, you've been getting a feel for the wiki and its habits, and it's pretty cool. Keep it up! :) --Michael Mol 01:11, 23 June 2011 (UTC)

Thanks! --Ledrug
You ever going to get around to populating your user page, perhaps with {{mylang}}? :P --Michael Mol 02:54, 13 August 2011 (UTC)

Deathstar

Your ascii based deathstar solution is truly excellent. :-)

Last Fridays

Hi, your C code for "Last Fridays" is quite complicated. Maybe some explanations about the calculation done (or comments in the code) would be a good idea, don't you think? Blue Prawn 21:13, 9 November 2011 (UTC)

There are only 5 statements in the code, one of which deals with command line args, two others calculate leap years. I'm not sure, what kind of comments would be helpful and not redundant? --Ledrug 01:26, 10 November 2011 (UTC)
Where did this line come from?:

<lang c>w = y * 365 + (y - 1) / 4 - (y - 1) / 100 + (y - 1) / 400 + 6;</lang>

I understand that it is math and what multiplication is, but I don't know how it is relevant. --Mwn3d 01:43, 10 November 2011 (UTC)
That's the number of days between Jan 0th of year y and some unspecified past date. All we need is that that number modulo 7 gives day of week of Jan 0th, y AD. --Ledrug 02:09, 10 November 2011 (UTC)
Is "Jan 0th" just Dec 31 of the previous year? Where did the formula come from? --Mwn3d 02:21, 10 November 2011 (UTC)
it is a formula that takes leap years into account: a year has 365 days, except every 4 years (y-1)/4, when it has 366, so those need to be added. but, every 100 years is not a leap year (y-1)/100, so those need to be subtracted again, and then every 400 years is a leap year again so (y-1)/400 needs to be added back. it is pretty straightforward once analyzed. i don't know what the +6 at the end is for though.--eMBee 03:22, 10 November 2011 (UTC)
Jan 0th is the day before Jan 1st, it doesn't quite matter what that means, as long as, say, Jan 0th + 10 days = Jan 10th. The "+6" to the number of days is so that the number modulo 7 gives the day of week, it just so happens that it's 6. --Ledrug 05:05, 10 November 2011 (UTC)

Galton

Could you please post the output image for your solution. Thanks. (See talk, my error). --Dgamey 03:31, 15 November 2011 (UTC)

AutoHotkey image

I'm interested in how you got the AutoHotkey image on Yin_and_yang to upload to Rosetta Code; when I tried it wouldn't work. In fact, even now when I download the file from imgur and attempt to upload it, it still fails, showing the "supported file types" in red. Perhaps it's the browser? I use Google Chrome... This would really be a help; I've had problems with it in the past. While we're on the topic, would it be OK to upload the large image as well? (Second Image in the imgur link.) If it's too large, I could simply run the AHK script again with a smaller width and height parameter. --Crazyfirex 03:20, 19 November 2011 (UTC)

I don't really know why one can or cannot upload an image, but I did convert your blobs from indexed mode to grayscale before uploading, maybe that has something to do with it. I have replaced the image with your bigger verseion now (I had javascript disabled the first time I followed the link, so didn't see it there at all). If you think it's too big, set a size parameter on it like this: [[file:yin-yang-ahk.png|right|150px]]. --Ledrug 03:28, 19 November 2011 (UTC)
Well, it's smaller than both the PicoLisp and ALGOL's ASCII outputs, and it doesn't disrupt the code, so I don't think anyone will object to the size. What tool did you use to convert them? Maybe I can use it in the future. In any case, thanks for uploading it. --Crazyfirex 03:40, 19 November 2011 (UTC)
I used GIMP to convert it. Imagemagick might work, too (however, if it did, there would be no reason for this conversion since MediaWiki uses it internally to scale images). --Ledrug 03:49, 19 November 2011 (UTC)
Well here we go again... I solved http://rosettacode.org/wiki/Colour_pinstripe/Display with AutoHotkey, and the wiki won't let me upload a screenshot. Interestingly enough, I didn't make the image with AHK, but with Prt Scr + Paint. Would you be so kind as to upload this? http://i.imgur.com/0qquS.png ...I feel so needy

Zebra puzzle

Cudos for catching this! :) I remembered to fix the one thing but forgot about the other... Cheers. WillNess 06:41, 3 December 2011 (UTC)