Rosetta Code

Talk about anything
User avatar
MasterFocus
Posts: 146
Joined: 01 Oct 2013, 09:47
GitHub: MasterFocus
Location: Rio de Janeiro - RJ - Brasil
Contact:

Re: Rosetta Code

18 Feb 2014, 00:55

I'm currently unable to access Rosetta Code (site seems to be down), but I managed to check the cache and download unixdict.txt.
Here's my take on this task (Anagrams). It's shorter, works for AHK 1.0 as well and seems to be faster:

Code: Select all

FileRead, Contents, unixdict.txt
Loop, Parse, Contents, % "`n", % "`r"
{ ; parsing each line of the file we just read
    Loop, Parse, A_LoopField ; parsing each letter/character of the current word
        Dummy .= "," A_LoopField
    Sort, Dummy, % "D," ; sorting those letters before removing the delimiters (comma)
    StringReplace, Dummy, Dummy, % ",", % "", All
    List .= "`n" Dummy " " A_LoopField , Dummy := ""
} ; at this point, we have a list where each line looks like <LETTERS><SPACE><WORD>
Count := 0, Contents := "", List := SubStr(List,2)
Sort, List
Loop, Parse, List, % "`n", % "`r"
{ ; now the list is sorted, parse it counting the consecutive lines with the same set of <LETTERS>
    Max := (Count > Max) ? Count : Max
    StringSplit, LinePart, A_LoopField, % " " ; (LinePart1 are the letters, LinePart2 is the word)
    If ( PreviousLinePart1 = LinePart1 )
        Count++ , WordList .= "," LinePart2
    Else
        var_Result .= ( Count <> Max ) ? "" ; don't append if the number of common words is too low
        : "`n" Count "`t" PreviousLinePart1 "`t" SubStr(WordList,2)
        , WordList := "" , Count := 0
    PreviousLinePart1 := LinePart1
}
List := "", var_Result := SubStr(var_Result,2)
Sort, var_Result, R N ; make the higher scores appear first
Loop, Parse, var_Result, % "`n", % "`r"
    If ( 1 == InStr(A_LoopField,Max) )
        var_Output .= "`n" A_LoopField
    Else ; output only those sets of letters that scored the maximum amount of common words
        Break
MsgBox, % ClipBoard := SubStr(var_Output,2) ; the result is also copied to the clipboard
I shall upload it later.
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.
User avatar
smorgasbord
Posts: 490
Joined: 30 Sep 2013, 09:34

Re: Rosetta Code

18 Feb 2014, 02:49

@masterfocus
Please post your codes so that ahk ranking improves.

rest up to you

:) 1579 Vs 1797 ;time comparisons

you win :o
John ... you working ?
User avatar
smorgasbord
Posts: 490
Joined: 30 Sep 2013, 09:34

Re: Rosetta Code

26 Feb 2014, 00:00

@sobriquet
1. What is the current AHK ranking?
2. I dont know if i should submit anagrams ( fixed ) code or not. what do you say? let say if i post it, master focus could change it and post his own ( it is better than mine in every which way).
John ... you working ?
User avatar
jNizM
Posts: 2663
Joined: 30 Sep 2013, 01:33
GitHub: jNizM
Contact:

Re: Rosetta Code

26 Feb 2014, 02:01

Code: Select all

1.  Tcl          781
...
18. WikiStubs‏‎    549
19. AutoHotkey   536
20. Unicon       536
[AHK] 1.1.32.00 x64 Unicode | [WIN] 10 Pro (Version 2004) x64 | [GitHub] Profile
Donations are appreciated if I could help you
User avatar
smorgasbord
Posts: 490
Joined: 30 Sep 2013, 09:34

Re: Rosetta Code

26 Feb 2014, 02:32

jNizM wrote:

Code: Select all

1.  Tcl          781
...
18. WikiStubs‏‎    549
19. AutoHotkey   536
20. Unicon       536
Thanks jNizM
John ... you working ?
User avatar
MasterFocus
Posts: 146
Joined: 01 Oct 2013, 09:47
GitHub: MasterFocus
Location: Rio de Janeiro - RJ - Brasil
Contact:

Re: Rosetta Code

26 Feb 2014, 03:01

Sorry for the late response, I've been quite busy (as usual).
Uploading now:
  • DNS query
  • Anagrams
@smorgasbord: People usually don't put a signature or something like "by nickname" in code uploaded to RosettaCode (like you did). It's kind of an etiquette. ;)
( unless you're uploading someone else's code, like this )

By the way, let me upload my code, which will show up at my contributions page. ;)
I know this is not a competition, but I promised I would upload it! I just needed some spare time. :mrgreen:
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.
User avatar
smorgasbord
Posts: 490
Joined: 30 Sep 2013, 09:34

Re: Rosetta Code

26 Feb 2014, 06:23

@Masterfocus
Okies :)
in future i wont. :)
John ... you working ?
User avatar
jNizM
Posts: 2663
Joined: 30 Sep 2013, 01:33
GitHub: jNizM
Contact:

Re: Rosetta Code

27 Feb 2014, 10:01

Added:
- CRC32

More about CRC32 in AutoHotkey:
- Hash from string, hex or file, HMAC, Salt
[AHK] 1.1.32.00 x64 Unicode | [WIN] 10 Pro (Version 2004) x64 | [GitHub] Profile
Donations are appreciated if I could help you
User avatar
smorgasbord
Posts: 490
Joined: 30 Sep 2013, 09:34

Re: Rosetta Code

28 Feb 2014, 04:49

done vampire numbers

requires formatting, functions and one minor tweak..

On mobile atm
John ... you working ?
User avatar
smorgasbord
Posts: 490
Joined: 30 Sep 2013, 09:34

Re: Rosetta Code

28 Feb 2014, 09:59

Vampire number
Sort function by the awesome @Geekdude @#ahkscript

@k0n: give me some time to make it smarter OR better ;)
John ... you working ?
User avatar
MasterFocus
Posts: 146
Joined: 01 Oct 2013, 09:47
GitHub: MasterFocus
Location: Rio de Janeiro - RJ - Brasil
Contact:

Re: Rosetta Code

01 Mar 2014, 17:39

Regarding Vampire Numbers, here's my attempt:

Code: Select all

#NoEnv
ListLines, Off
SetBatchLines -1

;********************
NumberLimit := 126030
CounterLimit := 25 ;; calculations stop when either limit is reached
AdditionalNumbers := "16758243290880,24959017348650,14593825548650"
;********************

CurrentCounter := 0
CurrentNumber := 10 ;; starting number

Loop  {
    if !Mod(A_Index,75) ;; informative tooltip (every 75 calculations, to avoid slowing down)
        ToolTip, % "Checking numbers...`nNumber: " CurrentNumber
            . "/" NumberLimit "`nFound: " CurrentCounter "/" CounterLimit
    if ( CurrentCounter >= CounterLimit ) || ( CurrentNumber >= NumberLimit )
        Break
    if Mod(StrLen(CurrentNumber),2)
        CurrentNumber *= 10
    else if ( ( CurrentResult := GetFangs(CurrentNumber) ) <> "" )
        Output .= "`n" CurrentNumber ":`t" CurrentResult, CurrentCounter++
    CurrentNumber++
}
ToolTip ;; hide informative tooltip

MsgBox % SubStr(Output,2)

Output := ""
Loop, Parse, AdditionalNumbers, % ","
{
    ToolTip, % "Getting fangs for " A_LoopField " ..." ;; informative tooltip
    Output .= "`n" A_LoopField ":`n`t" GetFangs(A_LoopField) "`n"
}
ToolTip ;; hide informative tooltip

MsgBox % SubStr(Output,2)
ExitApp

;----------------------------------------------------------------------------------

CharSorter(Input) { ;; required by GetFangs()
    Loop, Parse, Input
        Output .= A_LoopField "`n"
    Sort, Output
    StringReplace, Output, Output, % "`n",, All
    Return Output
}

;----------------------------------------------------------------------------------

GetFangs(CurrentNumber) { ;; requires CharSorter()
    ResultIndex := 1
    Length := StrLen(CurrentNumber)
    Power := (Length//2)-1
    if Mod(Length,2) OR !Power
        Return ""
    NumberLimit := Floor(Sqrt(CurrentNumber))
    Lower := 10 ** Power
    Loop, % NumberLimit - Lower {
        if !Mod(CurrentNumber,Lower) {
            FactorTwo := CurrentNumber//Lower
            if ( !Mod(Lower,10) && !Mod(FactorTwo,10) )
                Return ""
            Check := CharSorter( Lower . FactorTwo )
            if (CharSorter(CurrentNumber) = Check) && (StrLen(Lower) = StrLen(FactorTwo))
                Output .= "`n`t[" Lower "," FactorTwo "]"
        }
        Lower++
    }
    Return SubStr(Output,3) ;; 3 = 1+2 = 1 + lenght of the delimiters (`n and `t)
}
I modified the code submitted by smorgasbord (which also worked for AHK 1.0.*). :)
I removed some things (like GoTo) and used proper identation, variable names, etc. It is now easier to understand.
I didn't test the performance, but I suppose my version should be liiiiiiiiittle bit faster (if you remove the unnecessary tooltips). ;)
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.
User avatar
smorgasbord
Posts: 490
Joined: 30 Sep 2013, 09:34

Re: Rosetta Code

01 Mar 2014, 23:53

@Masterfocus
Cool :)
All Hail AHK!

if i remove my code and you post it again, AND if that helps in showing in your contributions page
I shall remove my code
what say?
John ... you working ?
User avatar
MasterFocus
Posts: 146
Joined: 01 Oct 2013, 09:47
GitHub: MasterFocus
Location: Rio de Janeiro - RJ - Brasil
Contact:

Re: Rosetta Code

02 Mar 2014, 00:23

You don't have to remove your code. I can submit mine and completely replace yours.
I'll do that by tomorrow.
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.
User avatar
smorgasbord
Posts: 490
Joined: 30 Sep 2013, 09:34

Re: Rosetta Code

02 Mar 2014, 00:52

@Masterfocus
Okies :)
No worries :)
John ... you working ?
User avatar
smorgasbord
Posts: 490
Joined: 30 Sep 2013, 09:34

Re: Rosetta Code

04 Mar 2014, 09:17

found another easier one :mrgreen:
Semiprime
All hail AHK!
John ... you working ?
User avatar
AlphaBravo
Posts: 492
Joined: 29 Sep 2013, 22:59

Re: Rosetta Code

04 Mar 2014, 11:30

@smorgasbord to shorten your code a little bit

Code: Select all

loop, 100
	list .= SemiPrime(A_Index) ? A_Index " " : ""
MsgBox % list

k := 1675
loop, 5
	list1 .= k " SemiPrime = " SemiPrime(k++) . "`n"
MsgBox % list1

SemiPrime(k) {
	loop, % (start := floor(sqrt(k))) - 1
		new .= mod(k, start) ? "" : (new ? "," : "") floor(start) "*" floor(k//start), start--
	return InStr(new,",") && InStr(new,"*") ? "" : new
}
User avatar
smorgasbord
Posts: 490
Joined: 30 Sep 2013, 09:34

Re: Rosetta Code

04 Mar 2014, 11:54

@AlphaBravo
Hel l yeah!

awesome!!
John ... you working ?
User avatar
MasterFocus
Posts: 146
Joined: 01 Oct 2013, 09:47
GitHub: MasterFocus
Location: Rio de Janeiro - RJ - Brasil
Contact:

Re: Rosetta Code

08 Mar 2014, 15:14

@Sobriquet:
About Minesweeper, please note: "Content is available under GNU Free Documentation License 1.2"
I see you state something regarding GPL, but all code submitted becomes available under GNU FDL 1.2.
About Brace Expansion, it doesn't work for AHK 1.0.* thanks to the =~ operator. You could add "works with AHK_L" or something.
I will submit my Vampire Numbers code now, as I promised. ;)
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.

Return to “Offtopic”

Who is online

Users browsing this forum: No registered users and 6 guests