September Morn Update
This commit is contained in:
parent
4e2d22a71d
commit
aac6731f2c
6856 changed files with 141342 additions and 21127 deletions
|
|
@ -0,0 +1,30 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
class Program
|
||||
{
|
||||
public static void Main() {
|
||||
var sequence = new[] { "A", "B", "C", "D" };
|
||||
foreach (var subset in Subsets(sequence.Length).Where(s => !IsContinuous(s))) {
|
||||
Console.WriteLine(string.Join(" ", subset.Select(i => sequence[i])));
|
||||
}
|
||||
}
|
||||
|
||||
static IEnumerable<List<int>> Subsets(int length) {
|
||||
int[] values = Enumerable.Range(0, length).ToArray();
|
||||
var stack = new Stack<int>(length);
|
||||
for (int i = 0; stack.Count > 0 || i < length; ) {
|
||||
if (i < length) {
|
||||
stack.Push(i++);
|
||||
yield return (from index in stack.Reverse() select values[index]).ToList();
|
||||
} else {
|
||||
i = stack.Pop() + 1;
|
||||
if (stack.Count > 0) i = stack.Pop() + 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static bool IsContinuous(List<int> list) => list[list.Count - 1] - list[0] + 1 == list.Count;
|
||||
|
||||
}
|
||||
|
|
@ -1,6 +1,7 @@
|
|||
my ($max, @current);
|
||||
sub non_continuous {
|
||||
my ($idx, $has_gap, $found) = @_;
|
||||
my ($idx, $has_gap) = @_;
|
||||
my $found;
|
||||
|
||||
for ($idx .. $max) {
|
||||
push @current, $_;
|
||||
|
|
@ -13,5 +14,5 @@ sub non_continuous {
|
|||
$found;
|
||||
}
|
||||
|
||||
$max = 20; # 1048365 sequences, 10 seconds-ish
|
||||
$max = 20;
|
||||
print "found ", non_continuous(1), " sequences\n";
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue