File tree Expand file tree Collapse file tree 3 files changed +49
-3
lines changed Expand file tree Collapse file tree 3 files changed +49
-3
lines changed Original file line number Diff line number Diff line change @@ -7,13 +7,12 @@ namespace Algorithms.Tests.Numeric
7
7
{
8
8
public static class MillerRabinPrimalityTest
9
9
{
10
- [ Test ]
11
10
[ TestCase ( "7" , ExpectedResult = true ) ] // true
12
11
[ TestCase ( "47" , ExpectedResult = true ) ] // true
13
12
[ TestCase ( "247894109041876714378152933343208766493" , ExpectedResult = true ) ] // true
14
13
[ TestCase ( "315757551269487563269454472438030700351" , ExpectedResult = true ) ] // true
15
14
16
- [ TestCase ( "2476099" , ExpectedResult = false ) ] // false 19^5
15
+ [ TestCase ( "2476099" , ExpectedResult = false ) ] // false 19^5
17
16
// false 247894109041876714378152933343208766493*315757551269487563269454472438030700351
18
17
[ TestCase ( "78274436845194327170519855212507883195883737501141260366253362532531612139043" , ExpectedResult = false ) ]
19
18
public static bool MillerRabinPrimalityWork ( String testcase )
@@ -31,7 +30,6 @@ public static bool MillerRabinPrimalityWork(String testcase)
31
30
return result ;
32
31
}
33
32
34
- [ Test ]
35
33
[ TestCase ( "-2" ) ]
36
34
[ TestCase ( "0" ) ]
37
35
[ TestCase ( "3" ) ]
Original file line number Diff line number Diff line change @@ -27,8 +27,10 @@ public void First100ElementsCorrect()
27
27
} ;
28
28
29
29
var sequence = new KolakoskiSequence ( ) . Sequence . Take ( 100 ) ;
30
+ var sequence2 = new KolakoskiSequence2 ( ) . Sequence . Take ( 100 ) ;
30
31
31
32
sequence . Should ( ) . Equal ( expected ) ;
33
+ sequence2 . Should ( ) . Equal ( expected ) ;
32
34
}
33
35
}
34
36
}
Original file line number Diff line number Diff line change
1
+ using System . Collections . Generic ;
2
+ using System . Linq ;
3
+ using System . Numerics ;
4
+
5
+ namespace Algorithms . Sequences
6
+ {
7
+ /// <summary>
8
+ /// <para>
9
+ /// Kolakoski sequence; n-th element is the length of the n-th run in the sequence itself.
10
+ /// </para>
11
+ /// <para>
12
+ /// Wikipedia: https://en.wikipedia.org/wiki/Kolakoski_sequence.
13
+ /// </para>
14
+ /// <para>
15
+ /// OEIS: https://oeis.org/A000002.
16
+ /// </para>
17
+ /// </summary>
18
+ public class KolakoskiSequence2 : ISequence
19
+ {
20
+ /// <summary>
21
+ /// Gets Kolakoski sequence.
22
+ /// </summary>
23
+ public IEnumerable < BigInteger > Sequence
24
+ {
25
+ get
26
+ {
27
+ yield return 1 ;
28
+ yield return 2 ;
29
+ yield return 2 ;
30
+
31
+ var inner = new KolakoskiSequence2 ( ) . Sequence . Skip ( 2 ) ;
32
+ var nextElement = 1 ;
33
+ foreach ( var runLength in inner )
34
+ {
35
+ yield return nextElement ;
36
+ if ( runLength > 1 )
37
+ {
38
+ yield return nextElement ;
39
+ }
40
+
41
+ nextElement = 1 + nextElement % 2 ;
42
+ }
43
+ }
44
+ }
45
+ }
46
+ }
You can’t perform that action at this time.
0 commit comments