Rosetta Code
Re: Rosetta Code
Recommends AHK Studio
- smorgasbord
- Posts: 493
- Joined: 30 Sep 2013, 09:34
Re: Rosetta Code
Dutch national flag problem
edited:
thanks @Tomoe_uehara and @Afterlemon at #ahkscript
for making the code right.
edited:
thanks @Tomoe_uehara and @Afterlemon at #ahkscript
for making the code right.
John ... you working ?
- MasterFocus
- Posts: 146
- Joined: 01 Oct 2013, 09:47
- Location: Rio de Janeiro - RJ - Brasil
- Contact:
Re: Rosetta Code
Awww I had a Van der Corput code here! Shouldn't have postponed it...kon wrote:Van der Corput sequence
GUI/Maximum window dimensions (I just used the example from the SysGet docs for this one)
( 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
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.
Re: Rosetta Code
Nice!
Windows 10 x64 Professional, Intel i5-8500, NVIDIA GTX 1060 6GB, 2x16GB Kingston FURY Beast - DDR4 3200 MHz | [About Me] | [About the AHK Foundation] | [Courses on AutoHotkey]
[ASPDM - StdLib Distribution] | [Qonsole - Quake-like console emulator] | [LibCon - Autohotkey Console Library]
- AlphaBravo
- Posts: 586
- Joined: 29 Sep 2013, 22:59
- MasterFocus
- Posts: 146
- Joined: 01 Oct 2013, 09:47
- Location: Rio de Janeiro - RJ - Brasil
- Contact:
Re: Rosetta Code
@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):
No need to check if A is zero or blank, because it will never be.
(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)
}
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.
- AlphaBravo
- Posts: 586
- Joined: 29 Sep 2013, 22:59
Re: Rosetta Code
@MasterFocus, nice condensed version
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
I disagree, while the initial thought sounds like you need to split NumSqr at every possible scenario, it is not entirely correct asMasterFocus wrote:Also, you're doing StrLen(Num) when I suppose it should be StrLen(NumSqr).
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.Kaprekar_numbers wrote:2223 is a Kaprekar number, as 2223 * 2223 = 4941729, 4941729 may be split to 494 and 1729, and 494 + 1729 = 2223.
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
You guys are far smarter than I can hope to be.
- MasterFocus
- Posts: 146
- Joined: 01 Oct 2013, 09:47
- Location: Rio de Janeiro - RJ - Brasil
- Contact:
Re: Rosetta Code
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.
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.
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.
- AlphaBravo
- Posts: 586
- Joined: 29 Sep 2013, 22:59
Re: Rosetta Code
this is becoming addictive
Decision tables
Find first and last set bit of a long integer
FASTA format
Topswops
S-Expressions
Set
Decision tables
Find first and last set bit of a long integer
FASTA format
Topswops
S-Expressions
Set
Re: Rosetta Code
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
@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
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
- AlphaBravo
- Posts: 586
- Joined: 29 Sep 2013, 22:59
Re: Rosetta Code
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
@kon I think you and I need a break
Re: Rosetta Code
Yeah, I looked at that problem and it made my head hurt.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?
Just... one... more.AlphaBravo wrote:@kon I think you and I need a break
Edit: Nice RegEx in S-Expressions BTW.
Re: Rosetta Code
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]:=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
*/
Windows 10 x64 Professional, Intel i5-8500, NVIDIA GTX 1060 6GB, 2x16GB Kingston FURY Beast - DDR4 3200 MHz | [About Me] | [About the AHK Foundation] | [Courses on AutoHotkey]
[ASPDM - StdLib Distribution] | [Qonsole - Quake-like console emulator] | [LibCon - Autohotkey Console Library]
- AlphaBravo
- Posts: 586
- Joined: 29 Sep 2013, 22:59
Re: Rosetta Code
I was thinking something like but as I said earlier it is creating a circular refrence
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
}
Re: Rosetta Code
haha nice...
Windows 10 x64 Professional, Intel i5-8500, NVIDIA GTX 1060 6GB, 2x16GB Kingston FURY Beast - DDR4 3200 MHz | [About Me] | [About the AHK Foundation] | [Courses on AutoHotkey]
[ASPDM - StdLib Distribution] | [Qonsole - Quake-like console emulator] | [LibCon - Autohotkey Console Library]
Return to “Off-topic Discussion”
Who is online
Users browsing this forum: No registered users and 70 guests