diff options
Diffstat (limited to 'challenge-072')
| -rw-r--r-- | challenge-072/lubos-kolouch/perl/ch-1.pl | 20 | ||||
| -rw-r--r-- | challenge-072/lubos-kolouch/perl/ch-2.pl | 13 | ||||
| -rw-r--r-- | challenge-072/lubos-kolouch/python/ch-1.py | 17 | ||||
| -rw-r--r-- | challenge-072/lubos-kolouch/python/ch-2.py | 13 |
4 files changed, 63 insertions, 0 deletions
diff --git a/challenge-072/lubos-kolouch/perl/ch-1.pl b/challenge-072/lubos-kolouch/perl/ch-1.pl new file mode 100644 index 0000000000..b0193d7141 --- /dev/null +++ b/challenge-072/lubos-kolouch/perl/ch-1.pl @@ -0,0 +1,20 @@ +use strict; +use warnings; + +sub trailing_zeros { + my ($n) = @_; + my $count = 0; + my $i = 5; + while ( $n / $i >= 1 ) { + $count += int( $n / $i ); + $i *= 5; + } + return $count; +} + +# Test cases: +print trailing_zeros(10); # Output: 2 +print "\n"; +print trailing_zeros(7); # Output: 1 +print "\n"; +print trailing_zeros(4); # Output: 0 diff --git a/challenge-072/lubos-kolouch/perl/ch-2.pl b/challenge-072/lubos-kolouch/perl/ch-2.pl new file mode 100644 index 0000000000..ddd57cb59d --- /dev/null +++ b/challenge-072/lubos-kolouch/perl/ch-2.pl @@ -0,0 +1,13 @@ +use strict; +use warnings; + +sub display_lines { + my ( $file_name, $a, $b ) = @_; + open my $file, '<', $file_name or die "Could not open '$file_name': $!"; + my @lines = <$file>; + print @lines[ $a - 1 .. $b - 1 ]; + close $file; +} + +# Suppose 'input.txt' is a file in the same directory with content as described in the problem +display_lines( 'input.txt', 4, 12 ); diff --git a/challenge-072/lubos-kolouch/python/ch-1.py b/challenge-072/lubos-kolouch/python/ch-1.py new file mode 100644 index 0000000000..c61b1f14bc --- /dev/null +++ b/challenge-072/lubos-kolouch/python/ch-1.py @@ -0,0 +1,17 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + + +def trailing_zeros(n: int) -> int: + count = 0 + i = 5 + while n // i >= 1: + count += n // i + i *= 5 + return count + + +# Test cases: +print(trailing_zeros(10)) # Output: 2 +print(trailing_zeros(7)) # Output: 1 +print(trailing_zeros(4)) # Output: 0 diff --git a/challenge-072/lubos-kolouch/python/ch-2.py b/challenge-072/lubos-kolouch/python/ch-2.py new file mode 100644 index 0000000000..5525686a22 --- /dev/null +++ b/challenge-072/lubos-kolouch/python/ch-2.py @@ -0,0 +1,13 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + + +def display_lines(file_name: str, a: int, b: int) -> None: + with open(file_name, "r") as file: + lines = file.readlines() + for line in lines[a - 1 : b]: + print(line.strip()) + + +# Suppose 'input.txt' is a file in the same directory with content as described in the problem +display_lines("input.txt", 4, 12) |
