Page 4 of 11

### Re: Rosetta Code

Posted: 29 Jan 2014, 00:16

### Re: Rosetta Code

Posted: 29 Jan 2014, 10:22
Dutch national flag problem

edited:
thanks @Tomoe_uehara and @Afterlemon at #ahkscript
for making the code right. ### Re: Rosetta Code

Posted: 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... ( but your code is smaller )

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)

### Re: Rosetta Code

Posted: 30 Jan 2014, 13:06
Nice! ### Re: Rosetta Code

Posted: 30 Jan 2014, 15:20

### Re: Rosetta Code

Posted: 30 Jan 2014, 21:55

### Re: Rosetta Code

Posted: 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.

### Re: Rosetta Code

Posted: 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

### Re: Rosetta Code

Posted: 31 Jan 2014, 21:03

### Re: Rosetta Code

Posted: 31 Jan 2014, 21:36
You guys are far smarter than I can hope to be. ### Re: Rosetta Code

Posted: 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.

### Re: Rosetta Code

Posted: 01 Feb 2014, 19:48
this is becoming addictive Decision tables
Find first and last set bit of a long integer
FASTA format
Topswops
S-Expressions
Set

### Re: Rosetta Code

Posted: 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?

### Re: Rosetta Code

Posted: 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. @AlphaBravo I know what you mean about it being addictive. Modular inverse

### Re: Rosetta Code

Posted: 02 Feb 2014, 13:35

### Re: Rosetta Code

Posted: 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 ### Re: Rosetta Code

Posted: 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. AlphaBravo wrote:@kon I think you and I need a break Just... one... more.

Edit: Nice RegEx in S-Expressions BTW.

### Re: Rosetta Code

Posted: 02 Feb 2014, 14:53
yeah... i sorta gave up on "twelve statments" too 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 ;should be true?

; 2.  Exactly 3 of the last 6 statements are true.
if (s+s+s+s+s+s==3)
s:=1

; 3.  Exactly 2 of the even-numbered statements are true.
if (s+s+s+s+s+s==2)
s:=1

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

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

; 6.  Exactly 4 of the odd-numbered statements are true.
if (s+s+s+s+s+s==4)
s:=1

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

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

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

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

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

; 12.  Exactly 4 of the preceding statements are true.
if (s+s+s+s+s+s+s+s+s+s+s==4)
s:=1
*/``````

### Re: Rosetta Code

Posted: 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

### Re: Rosetta Code

Posted: 02 Feb 2014, 17:49
haha nice...