aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--challenge-086/lubos-kolouch/perl/ch-1.pl11
-rw-r--r--challenge-086/lubos-kolouch/python/ch-1.py6
2 files changed, 6 insertions, 11 deletions
diff --git a/challenge-086/lubos-kolouch/perl/ch-1.pl b/challenge-086/lubos-kolouch/perl/ch-1.pl
index 0603c9b929..232ff30037 100644
--- a/challenge-086/lubos-kolouch/perl/ch-1.pl
+++ b/challenge-086/lubos-kolouch/perl/ch-1.pl
@@ -22,18 +22,15 @@ sub is_pair_difference {
# to avoid sorting and/or scanning through all pairs in the array
# or double nested loop,
- # I will convert the array to a hash, then check if the
- # corresponding key exists
+ # I will convert the array to a hash and check while creating it
my $arr = $$data{n};
my %h;
for (@$arr) {
- $h{$_} = 1;
- }
+ $h{$_} = 1;
- for my $x (keys %h) {
- return 1 if $h{$x + $$data{a}};
- }
+ return 1 if ($h{$_ + $$data{a}}) or ($h{$_ - $$data{a}});
+ }
return 0;
}
diff --git a/challenge-086/lubos-kolouch/python/ch-1.py b/challenge-086/lubos-kolouch/python/ch-1.py
index 0f284bf4c6..ffeda9b648 100644
--- a/challenge-086/lubos-kolouch/python/ch-1.py
+++ b/challenge-086/lubos-kolouch/python/ch-1.py
@@ -20,16 +20,14 @@ def is_pair_difference(n: list, a: int):
"""
# to avoid sorting and/or scanning through all pairs in the array
# or double nested loop,
- # I will convert the array to a hash, then check if the
- # corresponding key exists
+ # I will convert the array to a hash and check it on the fly
"""
hash_keys = {}
for number in n:
hash_keys[number] = 1
- for x in hash_keys:
- if hash_keys.get(x+a, 0):
+ if hash_keys.get(number+a, 0) or hash_keys.get(number-a, 0):
return 1
return 0