From 4011d5f9a24c4c4438f03dc0e942156148203539 Mon Sep 17 00:00:00 2001 From: Lubos Kolouch Date: Sun, 27 Oct 2019 09:58:38 +0100 Subject: Snake solution 1 --- challenge-031/lubos-kolouch/python/ch_1.py | 49 ++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 challenge-031/lubos-kolouch/python/ch_1.py diff --git a/challenge-031/lubos-kolouch/python/ch_1.py b/challenge-031/lubos-kolouch/python/ch_1.py new file mode 100644 index 0000000000..c507c163ec --- /dev/null +++ b/challenge-031/lubos-kolouch/python/ch_1.py @@ -0,0 +1,49 @@ +#!/usr/bin/env python3 +# -*- coding:utf-8 -*- + +import sys +import argparse +import pytest + +def get_args(): + parser = argparse.ArgumentParser(\ + description='Divisor check') + parser.add_argument(\ + '-n', + '--nominator', + type=int, + help='Nominator', + required=True) + parser.add_argument(\ + '-d', + '--denominator', + type=int, + help='Denominator', + required=True) + return parser.parse_args() + +def check_divide(nom,den): + try: + nom/den + except: + return("error") + + return "ok" + +def main(): + if sys.version_info[0] < 3: + print("ERROR: Python3 required.") + exit(1) + init_numbers = get_args() + print(check_divide(init_numbers.nominator, init_numbers.denominator)) + +def test_div(): + assert(check_divide(3,4)=="ok") + assert(check_divide(0,0)=="error") + assert(check_divide(1,0)=="error") + assert(check_divide(0,1)=="ok") + +main() + +test_div() +#EOF -- cgit From b943d00179cece6a1b38b501c442906971f5ec0b Mon Sep 17 00:00:00 2001 From: Lubos Kolouch Date: Sun, 27 Oct 2019 11:11:21 +0100 Subject: P5 solution Ch2 LK --- challenge-031/lubos-kolouch/perl5/ch-2.pl | 49 +++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 challenge-031/lubos-kolouch/perl5/ch-2.pl diff --git a/challenge-031/lubos-kolouch/perl5/ch-2.pl b/challenge-031/lubos-kolouch/perl5/ch-2.pl new file mode 100644 index 0000000000..67c505e3f5 --- /dev/null +++ b/challenge-031/lubos-kolouch/perl5/ch-2.pl @@ -0,0 +1,49 @@ +#!/usr/bin/env perl +#=============================================================================== +# +# FILE: ch-2.pl +# +# USAGE: ./ch-2.pl +# +# DESCRIPTION: https://perlweeklychallenge.org/blog/perl-weekly-challenge-031/ +# +# Create a script to demonstrate creating dynamic variable name, assign a value to the variable and finally print the variable. The variable name would be passed as command line argument. +# +# OPTIONS: --- +# REQUIREMENTS: --- +# BUGS: --- +# NOTES: --- +# AUTHOR: Lubos Kolouch +# ORGANIZATION: +# VERSION: 1.0 +# CREATED: 10/27/2019 10:03:56 AM +# REVISION: --- +#=============================================================================== + +use strict; +use warnings; +use feature qw/say/; +use Test::More; + +sub assing_variable { + my $var_name = shift; + no strict 'refs'; + + # it works, but I would not like to debug it... + ${$var_name} = "test"; + return 1; +} + +my $name = $ARGV[0] or die 'Usage: ch-2.pl name'; +assing_variable($name); + +# TESTS + +$name='bla'; +assing_variable($name); + +no strict 'refs'; +is($$name,'test'); + +done_testing(); + -- cgit