Rosetta Code

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

Re: Rosetta Code

29 Jan 2014, 10:22

Dutch national flag problem

edited:
thanks @Tomoe_uehara and @Afterlemon at #ahkscript
for making the code right.
:)
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

30 Jan 2014, 12:06

kon wrote:Van der Corput sequence
GUI/Maximum window dimensions (I just used the example from the SysGet docs for this one)
Awww I had a Van der Corput code here! Shouldn't have postponed it... :lol:
( but your code is smaller 8-) )

Glad to see so much effort from you guys in contributing to this! :)
AFAIK, these were my contributions in the past:
  • Hailstone Sequence
  • Price Fraction
  • Number Reversal Game
  • String Repetition
  • Dot Product
  • The N-Queens Problem
  • Missing Permutations
  • HQ9+ Interpreter
(all in AHK 1.0)
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
joedf
Posts: 7696
Joined: 29 Sep 2013, 17:08
Facebook: J0EDF
Google: +joedf
GitHub: joedf
Location: Canada
Contact:

Re: Rosetta Code

30 Jan 2014, 13:06

Nice! :D
User avatar
MasterFocus
Posts: 146
Joined: 01 Oct 2013, 09:47
GitHub: MasterFocus
Location: Rio de Janeiro - RJ - Brasil
Contact:

Re: Rosetta Code

31 Jan 2014, 12:13

@AlphaBravo: For the Kaprekar thing, "under 10000" should be "until 10000".
(if you use 9999 as the limit, it says "under 9999", which is incorrect)
Also, you're doing StrLen(Num) when I suppose it should be StrLen(NumSqr).

Here's another approach (which, just out of curiosity, works for AHK 1.0 as well):

Code: Select all

Kaprekar(L) {
	Loop, % L + ( C := 0 )
		Loop % StrLen( S := (N := A_Index)**2 ) {
			B:=(B:=SubStr(S,1+A_Index))? B: 0
			If !B&((A:=SubStr(S,1,A_Index))<>1)
				Break
			If ( N == A+B ) {
				R .= ", " N , C++
				Break
			}
		}
	Return C " Kaprekar numbers in [1-" L "]:`n" SubStr(R,3)
}
No need to check if A is zero or blank, because it will never be.
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
AlphaBravo
Posts: 476
Joined: 29 Sep 2013, 22:59

Re: Rosetta Code

31 Jan 2014, 20:49

@MasterFocus, nice condensed version
MasterFocus wrote:Also, you're doing StrLen(Num) when I suppose it should be StrLen(NumSqr).
I disagree, while the initial thought sounds like you need to split NumSqr at every possible scenario, it is not entirely correct as
Kaprekar_numbers wrote:2223 is a Kaprekar number, as 2223 * 2223 = 4941729, 4941729 may be split to 494 and 1729, and 494 + 1729 = 2223.
so the sum of the split will never be greater than the original number i.e. you would try 4,941729, 49,41729, 494,1729 and 4941,729 but never 49417,29 or 494172,9 as obviously the sum of the last two splits is over the original number.
and the reason why I try lower splits like x,yyyy is because I didn't want to check to see if the number looks like x,0yyy where zeros does not count when adding x+0yyy (does this make sense?)
thanks for looking up my code though.
AB
User avatar
fischgeek
Posts: 432
Joined: 29 Jan 2014, 21:39

Re: Rosetta Code

31 Jan 2014, 21:36

You guys are far smarter than I can hope to be. :shock:
User avatar
MasterFocus
Posts: 146
Joined: 01 Oct 2013, 09:47
GitHub: MasterFocus
Location: Rio de Janeiro - RJ - Brasil
Contact:

Re: Rosetta Code

01 Feb 2014, 10:59

Thank for the feedback, AlphaBravo.
Interesting point, I didn't think about that.
Oh, the x,0yyy not considering 0yyy as yyy can be solved by simply doing what I did: B := SubStr(...) + 0
I will tweak my code (perhaps make it a bit more readable) and edit the task 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
fischgeek
Posts: 432
Joined: 29 Jan 2014, 21:39

Re: Rosetta Code

01 Feb 2014, 20:16

I think the go-fish one would be fun. But, I'm confused on what they mean by not making the AI too smart. Isn't go-fish just luck of the draw?
kon
Posts: 1756
Joined: 29 Sep 2013, 17:11

Re: Rosetta Code

01 Feb 2014, 20:42

@fischgeek I guess the strategy would probably be in memorizing the cards that had already come into play and then optimizing moves based on the stats.
That's the first problem that I've seen where the solutions are all so long that they are on their own pages. :shock:

@AlphaBravo I know what you mean about it being addictive. ;)

Modular inverse
User avatar
AlphaBravo
Posts: 476
Joined: 29 Sep 2013, 22:59

Re: Rosetta Code

02 Feb 2014, 13:56

Twelve Statments looked like a fun one, but it keeps crashing on me, is it just me or does statement #2 depend on statement #7 and vise versa - creating a circular reference?

@kon I think you and I need a break :lol:
kon
Posts: 1756
Joined: 29 Sep 2013, 17:11

Re: Rosetta Code

02 Feb 2014, 14:00

AlphaBravo wrote:Twelve Statments looked like a fun one, but it keeps crashing on me, is it just me or does statement #2 depend on statement #7 and vise versa - creating a circular reference?
Yeah, I looked at that problem and it made my head hurt. :P
AlphaBravo wrote:@kon I think you and I need a break :lol:
Just... one... more.

Edit: Nice RegEx in S-Expressions BTW.
User avatar
joedf
Posts: 7696
Joined: 29 Sep 2013, 17:08
Facebook: J0EDF
Google: +joedf
GitHub: joedf
Location: Canada
Contact:

Re: Rosetta Code

02 Feb 2014, 14:53

yeah... i sorta gave up on "twelve statments" too :P

Code: Select all

/* 
1.  This is a numbered list of twelve statements.
2.  Exactly 3 of the last 6 statements are true.
3.  Exactly 2 of the even-numbered statements are true.
4.  If statement 5 is true, then statements 6 and 7 are both true.
5.  The 3 preceding statements are all false.
6.  Exactly 4 of the odd-numbered statements are true.
7.  Either statement 2 or 3 is true, but not both.
8.  If statement 7 is true, then 5 and 6 are both true.
9.  Exactly 3 of the first 6 statements are true.
10.  The next two statements are both true.
11.  Exactly 1 of statements 7, 8 and 9 are true.
12.  Exactly 4 of the preceding statements are true.

Solution: 1 3 4 6 7 11
*/

; 0 = false, 1 = true

/*
; 1.  This is a numbered list of twelve statements.
s:=[0,0,0,0,0,0,0,0,0,0,0,0]
	s[1]:=1 ;should be true?

; 2.  Exactly 3 of the last 6 statements are true.
if (s[7]+s[8]+s[9]+s[10]+s[11]+s[12]==3)
	s[2]:=1

; 3.  Exactly 2 of the even-numbered statements are true.
if (s[2]+s[4]+s[6]+s[8]+s[10]+s[12]==2)
	s[3]:=1

; 4.  If statement 5 is true, then statements 6 and 7 are both true.
if (s[5]) && (s[6]+s[7]==2)
	s[4]:=1

; 5.  The 3 preceding statements are all false.
if !(s[2]+s[3]+s[4]) ; if (s[2]+s[3]+s[4]==0)
	s[5]:=1

; 6.  Exactly 4 of the odd-numbered statements are true.
if (s[1]+s[3]+s[5]+s[7]+s[9]+s[11]==4)
	s[6]:=1

; 7.  Either statement 2 or 3 is true, but not both.
if (s[2]+s[3]==1)
	s[7]:=1

; 8.  If statement 7 is true, then 5 and 6 are both true.
if (s[7]) && (s[5]+s[6]==2)
	s[8]:=1

; 9.  Exactly 3 of the first 6 statements are true.
if (s[1]+s[2]+s[3]+s[4]+s[5]+s[6]==3)
	s[9]:=1

; 10.  The next two statements are both true.
if (s[11]+s[12]==2)
	s[10]:=1

; 11.  Exactly 1 of statements 7, 8 and 9 are true.
if (s[7]+s[8]+s[9]==1)
	s[11]:=1

; 12.  Exactly 4 of the preceding statements are true.
if (s[1]+s[2]+s[3]+s[4]+s[5]+s[6]+s[7]+s[8]+s[9]+s[10]+s[11]==4)
	s[12]:=1
*/
User avatar
AlphaBravo
Posts: 476
Joined: 29 Sep 2013, 22:59

Re: Rosetta Code

02 Feb 2014, 16:47

I was thinking something like

Code: Select all

loop, 12
    res.= state%A_Index%()
MsgBox % res
return

State1(){
	return 1
}
State2(){
	return (State7()+State8()+State9()+State10()+State11()+State12() = 3) ? 1 : 0
}
State3(){
	return (State2()+State4()+State6()+State8()+State10()+State12() = 2) ? 1 : 0
}
State4(){
	return (State5() && State6() && State7()) ? 1 : 0
}
State5(){
	return (!State2() && !State3() && !State4()) ? 1 : 0
}
State6(){
	return (State1()+State3()+State5()+State7()+State9()+State11() = 4) ? 1 : 0
}
State7(){
	return !(State2()&&State3()) ? 1 : 0
}
State8(){
	return (State7() && State5() && State6()) ? 1 : 0
}
State9(){
	return (State1()+State2()+State3()+State4()+State5()+State6() = 3) ? 1 : 0
}
State10(){
	return (State11() && State12()) ? 1 : 0
}
State11(){
	return (State7()+State8()+State9() = 1) ? 1 : 0
}
State12(){
	return (State1()+State2()+State3()+State4()+State5()+State6()+State7()+State8()+State9()+State10()+State11() = 4) ? 1 : 0 
}
but as I said earlier it is creating a circular refrence
User avatar
joedf
Posts: 7696
Joined: 29 Sep 2013, 17:08
Facebook: J0EDF
Google: +joedf
GitHub: joedf
Location: Canada
Contact:

Re: Rosetta Code

02 Feb 2014, 17:49

haha nice...

Return to “Offtopic”

Who is online

Users browsing this forum: No registered users and 12 guests