diff options
| author | Lubos Kolouch <lubos@kolouch.net> | 2023-06-22 10:14:58 +0200 |
|---|---|---|
| committer | Lubos Kolouch <lubos@kolouch.net> | 2023-06-22 10:14:58 +0200 |
| commit | e9c3b9e2abb541a15fa9d8d1fb03bbedb3dcdb45 (patch) | |
| tree | addff219e6b90a82aed5edf127b84565ade6f741 /challenge-142 | |
| parent | c32a7945539af12079cea4f95120c8f71fd8ceb5 (diff) | |
| download | perlweeklychallenge-club-e9c3b9e2abb541a15fa9d8d1fb03bbedb3dcdb45.tar.gz perlweeklychallenge-club-e9c3b9e2abb541a15fa9d8d1fb03bbedb3dcdb45.tar.bz2 perlweeklychallenge-club-e9c3b9e2abb541a15fa9d8d1fb03bbedb3dcdb45.zip | |
feat(challenge-142/lubos-kolouch/perl,python,java/): Challenge 142 LK Perl Python Java
Diffstat (limited to 'challenge-142')
| -rw-r--r-- | challenge-142/lubos-kolouch/java/ch-1.java | 16 | ||||
| -rw-r--r-- | challenge-142/lubos-kolouch/java/ch-2.java | 25 | ||||
| -rw-r--r-- | challenge-142/lubos-kolouch/perl/ch-1.pl | 18 | ||||
| -rw-r--r-- | challenge-142/lubos-kolouch/perl/ch-2.pl | 20 | ||||
| -rw-r--r-- | challenge-142/lubos-kolouch/python/ch-1.py | 13 | ||||
| -rw-r--r-- | challenge-142/lubos-kolouch/python/ch-2.py | 25 |
6 files changed, 117 insertions, 0 deletions
diff --git a/challenge-142/lubos-kolouch/java/ch-1.java b/challenge-142/lubos-kolouch/java/ch-1.java new file mode 100644 index 0000000000..98298d5b3f --- /dev/null +++ b/challenge-142/lubos-kolouch/java/ch-1.java @@ -0,0 +1,16 @@ +public class Main { + static int countDivisorsWithLastDigit(int m, int n) { + int count = 0; + for (int i = 1; i <= m; i++) { + if (m % i == 0 && i % 10 == n) { + count++; + } + } + return count; + } + + public static void main(String[] args) { + System.out.println(countDivisorsWithLastDigit(24, 2)); + System.out.println(countDivisorsWithLastDigit(30, 5)); + } +} diff --git a/challenge-142/lubos-kolouch/java/ch-2.java b/challenge-142/lubos-kolouch/java/ch-2.java new file mode 100644 index 0000000000..8823bd7f9d --- /dev/null +++ b/challenge-142/lubos-kolouch/java/ch-2.java @@ -0,0 +1,25 @@ +import java.util.concurrent.*; + +public class SleepSort { + public static void main(String[] args) throws InterruptedException { + int[] nums = {3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5}; + ExecutorService executor = Executors.newCachedThreadPool(); + + CountDownLatch latch = new CountDownLatch(nums.length); + for (final int num : nums) { + executor.execute(() -> { + try { + TimeUnit.SECONDS.sleep(num); + System.out.print(num + " "); + } catch (InterruptedException e) { + Thread.currentThread().interrupt(); + } finally { + latch.countDown(); + } + }); + } + + latch.await(); + executor.shutdown(); + } +} diff --git a/challenge-142/lubos-kolouch/perl/ch-1.pl b/challenge-142/lubos-kolouch/perl/ch-1.pl new file mode 100644 index 0000000000..9992ead734 --- /dev/null +++ b/challenge-142/lubos-kolouch/perl/ch-1.pl @@ -0,0 +1,18 @@ +#!/usr/bin/perl +use strict; +use warnings; + +sub count_divisors_with_last_digit { + my ($m, $n) = @_; + my $count = 0; + for my $i (1 .. $m) { + if ($m % $i == 0 && $i % 10 == $n) { + $count++; + } + } + return $count; +} + +print count_divisors_with_last_digit(24, 2), "\n"; +print count_divisors_with_last_digit(30, 5), "\n"; + diff --git a/challenge-142/lubos-kolouch/perl/ch-2.pl b/challenge-142/lubos-kolouch/perl/ch-2.pl new file mode 100644 index 0000000000..14f4c65468 --- /dev/null +++ b/challenge-142/lubos-kolouch/perl/ch-2.pl @@ -0,0 +1,20 @@ +use strict; +use warnings; +use threads; + +sub sleep_sort { + my @numbers = @_; + my @threads; + + foreach my $number (@numbers) { + push @threads, threads->create(sub { + sleep $number; + print "$number "; + }); + } + + $_->join for @threads; +} + +sleep_sort(3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5); + diff --git a/challenge-142/lubos-kolouch/python/ch-1.py b/challenge-142/lubos-kolouch/python/ch-1.py new file mode 100644 index 0000000000..a1af972179 --- /dev/null +++ b/challenge-142/lubos-kolouch/python/ch-1.py @@ -0,0 +1,13 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +def count_divisors_with_last_digit(m, n): + count = 0 + for i in range(1, m + 1): + if m % i == 0 and i % 10 == n: + count += 1 + return count + + +print(count_divisors_with_last_digit(24, 2)) +print(count_divisors_with_last_digit(30, 5)) diff --git a/challenge-142/lubos-kolouch/python/ch-2.py b/challenge-142/lubos-kolouch/python/ch-2.py new file mode 100644 index 0000000000..fc7e601a16 --- /dev/null +++ b/challenge-142/lubos-kolouch/python/ch-2.py @@ -0,0 +1,25 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +import threading +import time + + +def sleep_sort_value(n): + time.sleep(n) + print(n, end=' ') + + +def sleep_sort(numbers): + threads = [] + + for n in numbers: + thread = threading.Thread(target=sleep_sort_value, args=(n,)) + thread.start() + threads.append(thread) + + for thread in threads: + thread.join() + + +sleep_sort([3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5]) |
