diff options
-rwxr-xr-x | codechef/chefing.py | 6 | ||||
-rwxr-xr-x | codechef/depchef.py | 9 | ||||
-rwxr-xr-x | codechef/hmappy2.p6 | 5 | ||||
-rwxr-xr-x | thinkperl6/draft.p6 | 18 |
4 files changed, 30 insertions, 8 deletions
diff --git a/codechef/chefing.py b/codechef/chefing.py new file mode 100755 index 0000000..e3c71a1 --- /dev/null +++ b/codechef/chefing.py @@ -0,0 +1,6 @@ +#!/usr/bin/env python3 +from functools import reduce +from operator import and_ + +for _ in range(int(input())): + print(len(reduce(and_, (set(input()) for _ in range(int(input())))))) diff --git a/codechef/depchef.py b/codechef/depchef.py new file mode 100755 index 0000000..e4899a1 --- /dev/null +++ b/codechef/depchef.py @@ -0,0 +1,9 @@ +#!/usr/bin/env python3 +for _ in range(int(input())): + input() + a, d = ([int(i) for i in input().split()] for _ in range(2)) + a.extend((a[0], a[-1])) + try: + print(max(d for i, d in enumerate(d) if d > a[i-1] + a[i+1])) + except ValueError: + print(-1) diff --git a/codechef/hmappy2.p6 b/codechef/hmappy2.p6 new file mode 100755 index 0000000..cfe4cf5 --- /dev/null +++ b/codechef/hmappy2.p6 @@ -0,0 +1,5 @@ +#!/usr/bin/env perl6 +for ^get() { + my ($N, $A, $B, $K) = get.words.map: *.Int; + put $N div $A + $N div $B - $N div ($A lcm $B) * 2 < $K ?? 'Lose' !! 'Win'; +} diff --git a/thinkperl6/draft.p6 b/thinkperl6/draft.p6 index 9c85317..553009b 100755 --- a/thinkperl6/draft.p6 +++ b/thinkperl6/draft.p6 @@ -102,7 +102,7 @@ sub bubble-sort(@seq is copy) { $done = True; for ^@seq.end -> $i { if @seq[$i] > @seq[$i+1] { - @seq[$i, $i + 1] = @seq[$i + 1, $i]; + @seq[$i, $i + 1] .= reverse $done = False } } @@ -114,7 +114,7 @@ sub bubble-sort(@seq is copy) { sub select-sort(@seq is copy) { for ^@seq.end -> $i { for $i..@seq.end -> $j { - @seq[$i, $j] = @seq[$j, $i] if @seq[$i] > @seq[$j] + @seq[$i, $j] .= reverse if @seq[$i] > @seq[$j] } } @seq @@ -124,7 +124,7 @@ sub select-sort(@seq is copy) { sub insert-sort(@seq is copy) { for 1..@seq.end -> $i { loop (my $j = $i; $j and @seq[$j] < @seq[$j - 1]; $j--) { - @seq[$j, $j - 1] = @seq[$j - 1, $j] + @seq[$j, $j - 1] .= reverse } } @seq @@ -232,7 +232,7 @@ sub has-duplicates(@array) { @array.unique != @array } # Exercise 9.8 sub birthday-paradox(Int $n, Int $T) { - sum(map { has-duplicates map { Int(rand * 365.25) }, ^$n }, ^$T) / $T + sum(map { has-duplicates map { 365.25.rand.Int }, ^$n }, ^$T) / $T } #put birthday-paradox 23, 10000; @@ -240,9 +240,11 @@ sub birthday-paradox(Int $n, Int $T) { sub bisect(@a, $x, Int $low = 0, Int $high = @a.elems) { return unless $low < $high; my $mid = ($low + $high) div 2; - my $cmp = @a[$mid] cmp $x; - return $mid unless $cmp; - $cmp ~~ More ?? bisect @a, $x, $low, $mid !! bisect @a, $x, $mid+1, $high + given @a[$mid] cmp $x { + when Less { bisect @a, $x, $mid + 1, $high } + when Same { $mid } + when More { bisect @a, $x, $low, $mid } + } } # Exercise 9.11 @@ -293,4 +295,4 @@ sub rotations { } @result } -#.put for rotations; +.put for rotations; |