|
1 |
| -/*! |
| 1 | +/*! |
2 | 2 | * @author electricessence / https://github.com/electricessence/
|
3 | 3 | * Licensing: MIT https://github.com/electricessence/Genetic-Algorithm-Platform/blob/master/LICENSE.md
|
4 | 4 | */
|
5 | 5 |
|
| 6 | +using Open.Collections; |
6 | 7 | using System;
|
7 | 8 | using System.Collections.Generic;
|
8 | 9 | using System.Linq;
|
9 | 10 | using System.Threading;
|
10 |
| -using Open.Collections; |
11 | 11 |
|
12 | 12 | namespace Open.Arithmetic
|
13 | 13 | {
|
14 | 14 |
|
15 |
| - public static class Triangular |
16 |
| - { |
| 15 | + public static class Triangular |
| 16 | + { |
17 | 17 |
|
18 |
| - public static uint Forward(uint n) |
19 |
| - { |
20 |
| - return n * (n + 1) / 2; |
21 |
| - } |
| 18 | + public static uint Forward(uint n) |
| 19 | + { |
| 20 | + return n * (n + 1) / 2; |
| 21 | + } |
22 | 22 |
|
23 | 23 |
|
24 |
| - public static uint Reverse(uint n) |
25 |
| - { |
26 |
| - return (uint)(Math.Sqrt(8 * n + 1) - 1) / 2; |
27 |
| - } |
| 24 | + public static uint Reverse(uint n) |
| 25 | + { |
| 26 | + return (uint)(Math.Sqrt(8 * n + 1) - 1) / 2; |
| 27 | + } |
28 | 28 |
|
29 |
| - public static class Disperse |
30 |
| - { |
| 29 | + public static class Disperse |
| 30 | + { |
31 | 31 |
|
32 |
| - /** |
| 32 | + /** |
33 | 33 | * Increases the number an element based on it's index.
|
34 | 34 | * @param source
|
35 | 35 | * @returns {Enumerable<T>}
|
36 | 36 | */
|
37 |
| - public static IEnumerable<T> Increasing<T>(IEnumerable<T> source) |
38 |
| - { |
39 |
| - int i = 0; |
40 |
| - return source.SelectMany( |
41 |
| - c => Enumerable.Repeat(c, Interlocked.Increment(ref i))); |
42 |
| - } |
43 |
| - |
44 |
| - /** |
| 37 | + public static IEnumerable<T> Increasing<T>(IEnumerable<T> source) |
| 38 | + { |
| 39 | + int i = 0; |
| 40 | + return source.SelectMany( |
| 41 | + c => Enumerable.Repeat(c, Interlocked.Increment(ref i))); |
| 42 | + } |
| 43 | + |
| 44 | + /** |
45 | 45 | * Increases the count of each element for each index.
|
46 | 46 | * @param source
|
47 | 47 | * @returns {Enumerable<T>}
|
48 | 48 | */
|
49 |
| - public static IEnumerable<T> Decreasing<T>(IEnumerable<T> source) |
50 |
| - { |
51 |
| - var s = source.Memoize(); |
52 |
| - int i = 0; |
53 |
| - return s.SelectMany( |
54 |
| - c => s.Take(Interlocked.Increment(ref i))); |
55 |
| - } |
56 |
| - } |
57 |
| - } |
| 49 | + public static IEnumerable<T> Decreasing<T>(IEnumerable<T> source) |
| 50 | + { |
| 51 | + var s = source.Memoize(); |
| 52 | + int i = 0; |
| 53 | + return s.SelectMany( |
| 54 | + c => s.Take(Interlocked.Increment(ref i))); |
| 55 | + } |
| 56 | + } |
| 57 | + } |
58 | 58 |
|
59 | 59 | }
|
0 commit comments