Thread Variation/Kombination aufteilen und verteilt kalkulieren
(15 answers)
Opened by styx-cc at 2018-07-18 02:03
Ein paar Fehler ausgebessert und ein deutlich greifbareres Beispiel, man kann auf die Art und Weise z.B. die Uhrzeiten des Tages (auch zehntel oder 100stel Sekunden) in bliebig viele Teile gleichmäßig aufteilen:
Code (perl): (dl
)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 #!/usr/bin/perl use v5.10; use strict; use warnings; use Data::Dumper; my $series = [24, 60, 60]; # h:m:s my $permut = 1; $permut *= $_ for (@$series); my $chunks = 4; $chunks = $chunks < 1 ? 1 : $chunks; my $chunk_size = int($permut / $chunks); my $chunk_start = 0; my $chunk_end = $chunk_size; say join ' ', @$series; say "Permutations: $permut\tChunk size:\t$chunk_size\tChunks:\t$chunks"; my @chunk_ranges; while ($chunk_end <= $permut) { push @chunk_ranges, [ [$chunk_start, cpns($series, $chunk_start)], [$chunk_end-1, cpns($series, $chunk_end-1)] ]; $chunk_start += $chunk_size; $chunk_end += $chunk_size; } #last chunk_end equals amount of permutations-1 $chunk_ranges[-1]->[-1] = [$permut-1, cpns($series, $permut-1)]; print Dumper \@chunk_ranges; sub cpns { convert_positional_notation_systems(@_) }; sub convert_positional_notation_systems { my $bases = shift; my $quotient = shift; my $rest; my @result; for my $base (reverse @$bases) { $rest = $quotient % $base; $quotient = int($quotient / $base); push @result, $rest; last if $quotient == 0; } @result = reverse @result; return join ' ', @result; } Code: (dl
)
1 24 60 60 Last edited: 2020-06-01 05:44:06 +0200 (CEST) Pörl.
|