From 7398636a001a651201da43feefcdf55340aa91bd Mon Sep 17 00:00:00 2001 From: Paulo Custodio Date: Thu, 28 Oct 2021 11:01:52 +0100 Subject: Add solutions to task 1 of challenge 124 --- .gitignore | 2 ++ challenge-001/paulo-custodio/go.pl | 18 ++++++++++++- challenge-001/paulo-custodio/stats.pl | 3 +++ challenge-001/paulo-custodio/test.pl | 8 +++--- challenge-120/paulo-custodio/Makefile | 5 ++++ challenge-120/paulo-custodio/forth/ch-2.fs | 22 ---------------- challenge-124/paulo-custodio/Makefile | 5 ++++ challenge-124/paulo-custodio/ada/ch_1.adb | 28 ++++++++++++++++++++ challenge-124/paulo-custodio/awk/ch-1.awk | 26 +++++++++++++++++++ challenge-124/paulo-custodio/basic/ch-1.bas | 22 ++++++++++++++++ challenge-124/paulo-custodio/bc/ch-1.bc | 29 +++++++++++++++++++++ challenge-124/paulo-custodio/brainfuck/ch-1.bf | 1 + challenge-124/paulo-custodio/brainfuck/ch-1.pl | 36 ++++++++++++++++++++++++++ challenge-124/paulo-custodio/c/ch-1.c | 28 ++++++++++++++++++++ challenge-124/paulo-custodio/cpp/ch-1.cpp | 29 +++++++++++++++++++++ challenge-124/paulo-custodio/d/ch_1.d | 28 ++++++++++++++++++++ challenge-124/paulo-custodio/forth/ch-1.fs | 28 ++++++++++++++++++++ challenge-124/paulo-custodio/fortran/ch-1.f90 | 26 +++++++++++++++++++ challenge-124/paulo-custodio/lua/ch-1.lua | 26 +++++++++++++++++++ challenge-124/paulo-custodio/pascal/ch-1.pas | 27 +++++++++++++++++++ challenge-124/paulo-custodio/perl/ch-1.pl | 26 +++++++++++++++++++ challenge-124/paulo-custodio/python/ch-1.py | 26 +++++++++++++++++++ challenge-124/paulo-custodio/t/test-1.yaml | 22 ++++++++++++++++ 23 files changed, 444 insertions(+), 27 deletions(-) create mode 100644 challenge-120/paulo-custodio/Makefile create mode 100644 challenge-124/paulo-custodio/Makefile create mode 100644 challenge-124/paulo-custodio/ada/ch_1.adb create mode 100644 challenge-124/paulo-custodio/awk/ch-1.awk create mode 100644 challenge-124/paulo-custodio/basic/ch-1.bas create mode 100644 challenge-124/paulo-custodio/bc/ch-1.bc create mode 100644 challenge-124/paulo-custodio/brainfuck/ch-1.bf create mode 100644 challenge-124/paulo-custodio/brainfuck/ch-1.pl create mode 100644 challenge-124/paulo-custodio/c/ch-1.c create mode 100644 challenge-124/paulo-custodio/cpp/ch-1.cpp create mode 100644 challenge-124/paulo-custodio/d/ch_1.d create mode 100644 challenge-124/paulo-custodio/forth/ch-1.fs create mode 100644 challenge-124/paulo-custodio/fortran/ch-1.f90 create mode 100644 challenge-124/paulo-custodio/lua/ch-1.lua create mode 100644 challenge-124/paulo-custodio/pascal/ch-1.pas create mode 100644 challenge-124/paulo-custodio/perl/ch-1.pl create mode 100644 challenge-124/paulo-custodio/python/ch-1.py create mode 100644 challenge-124/paulo-custodio/t/test-1.yaml diff --git a/.gitignore b/.gitignore index 6f111fe0c2..ba8194b15c 100644 --- a/.gitignore +++ b/.gitignore @@ -13,6 +13,8 @@ *.bak ch-1 ch-2 +ch_1 +ch_2 go.mod go.sum tags diff --git a/challenge-001/paulo-custodio/go.pl b/challenge-001/paulo-custodio/go.pl index 97670bc755..13ad914edd 100644 --- a/challenge-001/paulo-custodio/go.pl +++ b/challenge-001/paulo-custodio/go.pl @@ -7,7 +7,23 @@ use Path::Tiny; or die "Usage: ",path($0)->basename," nr\n"; my $nr = sprintf("%03d", $ARGV[0]); -for my $dir (qw( ada awk basic c cpp d forth lua perl python t )) { +for my $dir (qw( + ada + awk + basic + bc + brainfuck + c + cpp + d + forth + fortran + lua + pascal + perl + python + t + )) { path("challenge-$nr/paulo-custodio/$dir")->mkpath; } path("challenge-$nr/paulo-custodio/README")->spew("Solution by Paulo Custodio\n"); diff --git a/challenge-001/paulo-custodio/stats.pl b/challenge-001/paulo-custodio/stats.pl index 1cb928a96a..bc344a2db3 100644 --- a/challenge-001/paulo-custodio/stats.pl +++ b/challenge-001/paulo-custodio/stats.pl @@ -12,11 +12,14 @@ our %LANG = ( awk => 'awk', basic => 'bas', bc => 'bc', + brainfuck=>'bf', c => 'c', cpp => 'cpp', d => 'd', forth => 'fs', + fortran => 'f90', lua => 'lua', + pascal => 'pas', perl => 'pl', python => 'py', ); diff --git a/challenge-001/paulo-custodio/test.pl b/challenge-001/paulo-custodio/test.pl index 4e2418c4ae..c8dc2b9f75 100644 --- a/challenge-001/paulo-custodio/test.pl +++ b/challenge-001/paulo-custodio/test.pl @@ -17,7 +17,7 @@ our %LANG = ( awk => 'awk', basic => 'bas', bc => 'bc', - brainfuck=>'bfpp', + brainfuck=>'bf', c => 'c', cpp => 'cpp', d => 'd', @@ -137,15 +137,15 @@ sub build { return "gawk -f $prog --"; } if (/^basic$/) { - run("fbc $prog -o $prog_wo_ext") if (!-f $exe || -M $exe > -M $prog); + run("fbc $prog") if (!-f $exe || -M $exe > -M $prog); return $exe; } if (/^bc$/) { return "bc -lq $prog"; } if (/^brainfuck$/) { - run("perl bfpp.pl <$prog_wo_ext.bfpp >$prog_wo_ext.bf"); - return "brainfuck $prog_wo_ext.bf"; + #run("perl bfpp.pl <$prog_wo_ext.bfpp >$prog_wo_ext.bf"); + return "bf $prog_wo_ext.bf"; } if (/^c$/) { run("gcc $prog -o $prog_wo_ext -lmpfr -lgmp") if (!-f $exe || -M $exe > -M $prog); diff --git a/challenge-120/paulo-custodio/Makefile b/challenge-120/paulo-custodio/Makefile new file mode 100644 index 0000000000..2cbe39ae87 --- /dev/null +++ b/challenge-120/paulo-custodio/Makefile @@ -0,0 +1,5 @@ +all: brainfuck/ch-1.bf + perl ./test.pl + +brainfuck/ch-1.bf: brainfuck/ch-1.bfpp bfpp.pl + perl bfpp.pl < $< > $@ diff --git a/challenge-120/paulo-custodio/forth/ch-2.fs b/challenge-120/paulo-custodio/forth/ch-2.fs index 078dbfbc19..6728e3b202 100644 --- a/challenge-120/paulo-custodio/forth/ch-2.fs +++ b/challenge-120/paulo-custodio/forth/ch-2.fs @@ -40,25 +40,3 @@ DUP 180 > IF 360 SWAP - THEN ; NEXT-ARG parse_time clock_angle . CR BYE - -\ #include -\ #include -\ #include -\ -\ -\ int clock_angle(int hh, int mm) { -\ int mm_angle = mm*360/60; -\ int hh_angle = (hh % 12)*360/12 + mm_angle/12; -\ int angle = abs(hh_angle - mm_angle); -\ if (angle > 180) { angle = 360 - angle; } -\ return angle; -\ } -\ -\ int main(int argc, char* argv[]) { -\ if (argc != 2) return EXIT_FAILURE; -\ int hh, mm; -\ if (!parse_time(argv[1], &hh, &mm)) return EXIT_FAILURE; -\ int angle = clock_angle(hh, mm); -\ printf("%d\n", angle); -\ } -\ diff --git a/challenge-124/paulo-custodio/Makefile b/challenge-124/paulo-custodio/Makefile new file mode 100644 index 0000000000..d2e3a9925f --- /dev/null +++ b/challenge-124/paulo-custodio/Makefile @@ -0,0 +1,5 @@ +all: brainfuck/ch-1.bf + perl ../../challenge-001/paulo-custodio/test.pl + +brainfuck/ch-1.bf: brainfuck/ch-1.pl + perl brainfuck/ch-1.pl > $@ diff --git a/challenge-124/paulo-custodio/ada/ch_1.adb b/challenge-124/paulo-custodio/ada/ch_1.adb new file mode 100644 index 0000000000..7ec0278e04 --- /dev/null +++ b/challenge-124/paulo-custodio/ada/ch_1.adb @@ -0,0 +1,28 @@ +-- TASK #1 > Happy Women Day +-- Submitted by: Mohammad S Anwar +-- Write a script to print the Venus Symbol, international gender +-- symbol for +-- women. Please feel free to use any character. + +with Ada.Text_IO; use Ada.Text_IO; + +procedure ch_1 is +begin + Put_Line(" ^^^^^"); + Put_Line(" ^ ^"); + Put_Line(" ^ ^"); + Put_Line(" ^ ^"); + Put_Line(" ^ ^"); + Put_Line(" ^ ^"); + Put_Line(" ^ ^"); + Put_Line(" ^ ^"); + Put_Line(" ^ ^"); + Put_Line(" ^ ^"); + Put_Line(" ^^^^^"); + Put_Line(" ^"); + Put_Line(" ^"); + Put_Line(" ^"); + Put_Line(" ^^^^^"); + Put_Line(" ^"); + Put_Line(" ^"); +end ch_1; diff --git a/challenge-124/paulo-custodio/awk/ch-1.awk b/challenge-124/paulo-custodio/awk/ch-1.awk new file mode 100644 index 0000000000..09c3c5f601 --- /dev/null +++ b/challenge-124/paulo-custodio/awk/ch-1.awk @@ -0,0 +1,26 @@ +#!/usr/bin/env gawk + +# TASK #1 > Happy Women Day +# Submitted by: Mohammad S Anwar +# Write a script to print the Venus Symbol, international gender symbol for +# women. Please feel free to use any character. + +BEGIN { + print " ^^^^^" + print " ^ ^" + print " ^ ^" + print " ^ ^" + print " ^ ^" + print " ^ ^" + print " ^ ^" + print " ^ ^" + print " ^ ^" + print " ^ ^" + print " ^^^^^" + print " ^" + print " ^" + print " ^" + print " ^^^^^" + print " ^" + print " ^" +} diff --git a/challenge-124/paulo-custodio/basic/ch-1.bas b/challenge-124/paulo-custodio/basic/ch-1.bas new file mode 100644 index 0000000000..86539c4cff --- /dev/null +++ b/challenge-124/paulo-custodio/basic/ch-1.bas @@ -0,0 +1,22 @@ +' TASK #1 > Happy Women Day +' Submitted by: Mohammad S Anwar +' Write a script to print the Venus Symbol, international gender symbol for +' women. Please feel free to use any character. + +print " ^^^^^" +print " ^ ^" +print " ^ ^" +print " ^ ^" +print " ^ ^" +print " ^ ^" +print " ^ ^" +print " ^ ^" +print " ^ ^" +print " ^ ^" +print " ^^^^^" +print " ^" +print " ^" +print " ^" +print " ^^^^^" +print " ^" +print " ^" diff --git a/challenge-124/paulo-custodio/bc/ch-1.bc b/challenge-124/paulo-custodio/bc/ch-1.bc new file mode 100644 index 0000000000..4242bd2443 --- /dev/null +++ b/challenge-124/paulo-custodio/bc/ch-1.bc @@ -0,0 +1,29 @@ +#!/usr/bin/bc -ql + +/* +TASK #1 > Happy Women Day +Submitted by: Mohammad S Anwar +Write a script to print the Venus Symbol, international gender symbol for +women. Please feel free to use any character. +*/ + +"\ + ^^^^^ + ^ ^ + ^ ^ + ^ ^ + ^ ^ + ^ ^ + ^ ^ + ^ ^ + ^ ^ + ^ ^ + ^^^^^ + ^ + ^ + ^ + ^^^^^ + ^ + ^\ +" +quit diff --git a/challenge-124/paulo-custodio/brainfuck/ch-1.bf b/challenge-124/paulo-custodio/brainfuck/ch-1.bf new file mode 100644 index 0000000000..d2567a41cf --- /dev/null +++ b/challenge-124/paulo-custodio/brainfuck/ch-1.bf @@ -0,0 +1 @@ +[-]++++++++++++++++++++++++++++++++.[-]++++++++++++++++++++++++++++++++.[-]++++++++++++++++++++++++++++++++.[-]++++++++++++++++++++++++++++++++.[-]++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.[-]++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.[-]++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.[-]++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.[-]++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.[-]++++++++++.[-]++++++++++++++++++++++++++++++++.[-]++++++++++++++++++++++++++++++++.[-]++++++++++++++++++++++++++++++++.[-]++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.[-]++++++++++++++++++++++++++++++++.[-]++++++++++++++++++++++++++++++++.[-]++++++++++++++++++++++++++++++++.[-]++++++++++++++++++++++++++++++++.[-]++++++++++++++++++++++++++++++++.[-]++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.[-]++++++++++.[-]++++++++++++++++++++++++++++++++.[-]++++++++++++++++++++++++++++++++.[-]++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.[-]++++++++++++++++++++++++++++++++.[-]++++++++++++++++++++++++++++++++.[-]++++++++++++++++++++++++++++++++.[-]++++++++++++++++++++++++++++++++.[-]++++++++++++++++++++++++++++++++.[-]++++++++++++++++++++++++++++++++.[-]++++++++++++++++++++++++++++++++.[-]++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.[-]++++++++++.[-]++++++++++++++++++++++++++++++++.[-]++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.[-]++++++++++++++++++++++++++++++++.[-]++++++++++++++++++++++++++++++++.[-]++++++++++++++++++++++++++++++++.[-]++++++++++++++++++++++++++++++++.[-]++++++++++++++++++++++++++++++++.[-]++++++++++++++++++++++++++++++++.[-]++++++++++++++++++++++++++++++++.[-]++++++++++++++++++++++++++++++++.[-]++++++++++++++++++++++++++++++++.[-]++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.[-]++++++++++.[-]++++++++++++++++++++++++++++++++.[-]++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.[-]++++++++++++++++++++++++++++++++.[-]++++++++++++++++++++++++++++++++.[-]++++++++++++++++++++++++++++++++.[-]++++++++++++++++++++++++++++++++.[-]++++++++++++++++++++++++++++++++.[-]++++++++++++++++++++++++++++++++.[-]++++++++++++++++++++++++++++++++.[-]++++++++++++++++++++++++++++++++.[-]++++++++++++++++++++++++++++++++.[-]++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.[-]++++++++++.[-]++++++++++++++++++++++++++++++++.[-]++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.[-]++++++++++++++++++++++++++++++++.[-]++++++++++++++++++++++++++++++++.[-]++++++++++++++++++++++++++++++++.[-]++++++++++++++++++++++++++++++++.[-]++++++++++++++++++++++++++++++++.[-]++++++++++++++++++++++++++++++++.[-]++++++++++++++++++++++++++++++++.[-]++++++++++++++++++++++++++++++++.[-]++++++++++++++++++++++++++++++++.[-]++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.[-]++++++++++.[-]++++++++++++++++++++++++++++++++.[-]++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.[-]++++++++++++++++++++++++++++++++.[-]++++++++++++++++++++++++++++++++.[-]++++++++++++++++++++++++++++++++.[-]++++++++++++++++++++++++++++++++.[-]++++++++++++++++++++++++++++++++.[-]++++++++++++++++++++++++++++++++.[-]++++++++++++++++++++++++++++++++.[-]++++++++++++++++++++++++++++++++.[-]++++++++++++++++++++++++++++++++.[-]++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.[-]++++++++++.[-]++++++++++++++++++++++++++++++++.[-]++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.[-]++++++++++++++++++++++++++++++++.[-]++++++++++++++++++++++++++++++++.[-]++++++++++++++++++++++++++++++++.[-]++++++++++++++++++++++++++++++++.[-]++++++++++++++++++++++++++++++++.[-]++++++++++++++++++++++++++++++++.[-]++++++++++++++++++++++++++++++++.[-]++++++++++++++++++++++++++++++++.[-]++++++++++++++++++++++++++++++++.[-]++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.[-]++++++++++.[-]++++++++++++++++++++++++++++++++.[-]++++++++++++++++++++++++++++++++.[-]++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.[-]++++++++++++++++++++++++++++++++.[-]++++++++++++++++++++++++++++++++.[-]++++++++++++++++++++++++++++++++.[-]++++++++++++++++++++++++++++++++.[-]++++++++++++++++++++++++++++++++.[-]++++++++++++++++++++++++++++++++.[-]++++++++++++++++++++++++++++++++.[-]++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.[-]++++++++++.[-]++++++++++++++++++++++++++++++++.[-]++++++++++++++++++++++++++++++++.[-]++++++++++++++++++++++++++++++++.[-]++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.[-]++++++++++++++++++++++++++++++++.[-]++++++++++++++++++++++++++++++++.[-]++++++++++++++++++++++++++++++++.[-]++++++++++++++++++++++++++++++++.[-]++++++++++++++++++++++++++++++++.[-]++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.[-]++++++++++.[-]++++++++++++++++++++++++++++++++.[-]++++++++++++++++++++++++++++++++.[-]++++++++++++++++++++++++++++++++.[-]++++++++++++++++++++++++++++++++.[-]++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.[-]++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.[-]++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.[-]++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.[-]++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.[-]++++++++++.[-]++++++++++++++++++++++++++++++++.[-]++++++++++++++++++++++++++++++++.[-]++++++++++++++++++++++++++++++++.[-]++++++++++++++++++++++++++++++++.[-]++++++++++++++++++++++++++++++++.[-]++++++++++++++++++++++++++++++++.[-]++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.[-]++++++++++.[-]++++++++++++++++++++++++++++++++.[-]++++++++++++++++++++++++++++++++.[-]++++++++++++++++++++++++++++++++.[-]++++++++++++++++++++++++++++++++.[-]++++++++++++++++++++++++++++++++.[-]++++++++++++++++++++++++++++++++.[-]++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.[-]++++++++++.[-]++++++++++++++++++++++++++++++++.[-]++++++++++++++++++++++++++++++++.[-]++++++++++++++++++++++++++++++++.[-]++++++++++++++++++++++++++++++++.[-]++++++++++++++++++++++++++++++++.[-]++++++++++++++++++++++++++++++++.[-]++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.[-]++++++++++.[-]++++++++++++++++++++++++++++++++.[-]++++++++++++++++++++++++++++++++.[-]++++++++++++++++++++++++++++++++.[-]++++++++++++++++++++++++++++++++.[-]++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.[-]++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.[-]++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.[-]++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.[-]++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.[-]++++++++++.[-]++++++++++++++++++++++++++++++++.[-]++++++++++++++++++++++++++++++++.[-]++++++++++++++++++++++++++++++++.[-]++++++++++++++++++++++++++++++++.[-]++++++++++++++++++++++++++++++++.[-]++++++++++++++++++++++++++++++++.[-]++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.[-]++++++++++.[-]++++++++++++++++++++++++++++++++.[-]++++++++++++++++++++++++++++++++.[-]++++++++++++++++++++++++++++++++.[-]++++++++++++++++++++++++++++++++.[-]++++++++++++++++++++++++++++++++.[-]++++++++++++++++++++++++++++++++.[-]++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.[-]++++++++++. \ No newline at end of file diff --git a/challenge-124/paulo-custodio/brainfuck/ch-1.pl b/challenge-124/paulo-custodio/brainfuck/ch-1.pl new file mode 100644 index 0000000000..264e25c4fd --- /dev/null +++ b/challenge-124/paulo-custodio/brainfuck/ch-1.pl @@ -0,0 +1,36 @@ +#!/usr/bin/env perl + +# TASK #1 > Happy Women Day +# Submitted by: Mohammad S Anwar +# Write a script to print the Venus Symbol, international gender symbol for +# women. Please feel free to use any character. + +# Output brainfuck program + +use Modern::Perl; + +my $text = <<'END'; + ^^^^^ + ^ ^ + ^ ^ + ^ ^ + ^ ^ + ^ ^ + ^ ^ + ^ ^ + ^ ^ + ^ ^ + ^^^^^ + ^ + ^ + ^ + ^^^^^ + ^ + ^ +END + +for (split //, $text) { + print "[-]"; # zero cell + print "+" x ord($_); # set cell to ASCII value of character + print "."; # output character +} diff --git a/challenge-124/paulo-custodio/c/ch-1.c b/challenge-124/paulo-custodio/c/ch-1.c new file mode 100644 index 0000000000..f88efc82bb --- /dev/null +++ b/challenge-124/paulo-custodio/c/ch-1.c @@ -0,0 +1,28 @@ +/* +TASK #1 > Happy Women Day +Submitted by: Mohammad S Anwar +Write a script to print the Venus Symbol, international gender symbol for +women. Please feel free to use any character. +*/ + +#include "stdio.h" + +int main() { + puts(" ^^^^^"); + puts(" ^ ^"); + puts(" ^ ^"); + puts(" ^ ^"); + puts(" ^ ^"); + puts(" ^ ^"); + puts(" ^ ^"); + puts(" ^ ^"); + puts(" ^ ^"); + puts(" ^ ^"); + puts(" ^^^^^"); + puts(" ^"); + puts(" ^"); + puts(" ^"); + puts(" ^^^^^"); + puts(" ^"); + puts(" ^"); +} diff --git a/challenge-124/paulo-custodio/cpp/ch-1.cpp b/challenge-124/paulo-custodio/cpp/ch-1.cpp new file mode 100644 index 0000000000..988476fdfc --- /dev/null +++ b/challenge-124/paulo-custodio/cpp/ch-1.cpp @@ -0,0 +1,29 @@ +/* +TASK #1 > Happy Women Day +Submitted by: Mohammad S Anwar +Write a script to print the Venus Symbol, international gender symbol for +women. Please feel free to use any character. +*/ + +#include +using namespace std; + +int main() { + cout << " ^^^^^" << endl; + cout << " ^ ^" << endl; + cout << " ^ ^" << endl; + cout << " ^ ^" << endl; + cout << " ^ ^" << endl; + cout << " ^ ^" << endl; + cout << " ^ ^" << endl; + cout << " ^ ^" << endl; + cout << " ^ ^" << endl; + cout << " ^ ^" << endl; + cout << " ^^^^^" << endl; + cout << " ^" << endl; + cout << " ^" << endl; + cout << " ^" << endl; + cout << " ^^^^^" << endl; + cout << " ^" << endl; + cout << " ^" << endl; +} diff --git a/challenge-124/paulo-custodio/d/ch_1.d b/challenge-124/paulo-custodio/d/ch_1.d new file mode 100644 index 0000000000..d9d5734676 --- /dev/null +++ b/challenge-124/paulo-custodio/d/ch_1.d @@ -0,0 +1,28 @@ +/* +TASK #1 > Happy Women Day +Submitted by: Mohammad S Anwar +Write a script to print the Venus Symbol, international gender symbol for +women. Please feel free to use any character. +*/ + +import std.stdio; + +void main() { + writeln(" ^^^^^"); + writeln(" ^ ^"); + writeln(" ^ ^"); + writeln(" ^ ^"); + writeln(" ^ ^"); + writeln(" ^ ^"); + writeln(" ^ ^"); + writeln(" ^ ^"); + writeln(" ^ ^"); + writeln(" ^ ^"); + writeln(" ^^^^^"); + writeln(" ^"); + writeln(" ^"); + writeln(" ^"); + writeln(" ^^^^^"); + writeln(" ^"); + writeln(" ^"); +} diff --git a/challenge-124/paulo-custodio/forth/ch-1.fs b/challenge-124/paulo-custodio/forth/ch-1.fs new file mode 100644 index 0000000000..1385d59b9e --- /dev/null +++ b/challenge-124/paulo-custodio/forth/ch-1.fs @@ -0,0 +1,28 @@ +#! /usr/bin/env gforth + +\ TASK #1 > Happy Women Day +\ Submitted by: Mohammad S Anwar +\ Write a script to print the Venus Symbol, international gender symbol for +\ women. Please feel free to use any character. + +: VENUS + ." ^^^^^" CR + ." ^ ^" CR + ." ^ ^" CR + ." ^ ^" CR + ." ^ ^" CR + ." ^ ^" CR + ." ^ ^" CR + ." ^ ^" CR + ." ^ ^" CR + ." ^ ^" CR + ." ^^^^^" CR + ." ^" CR + ." ^" CR + ." ^" CR + ." ^^^^^" CR + ." ^" CR + ." ^" CR +; + +VENUS BYE diff --git a/challenge-124/paulo-custodio/fortran/ch-1.f90 b/challenge-124/paulo-custodio/fortran/ch-1.f90 new file mode 100644 index 0000000000..8e5122303f --- /dev/null +++ b/challenge-124/paulo-custodio/fortran/ch-1.f90 @@ -0,0 +1,26 @@ +! TASK #1 > Happy Women Day +! Submitted by: Mohammad S Anwar +! Write a script to print the Venus Symbol, international gender symbol for +! women. Please feel free to use any character. + +program ch1 + implicit none + + print *, ' ^^^^^' + print *, ' ^ ^' + print *, ' ^ ^' + print *, ' ^ ^' + print *, ' ^ ^' + print *, ' ^ ^' + print *, ' ^ ^' + print *, ' ^ ^' + print *, ' ^ ^' + print *, ' ^ ^' + print *, ' ^^^^^' + print *, ' ^' + print *, ' ^' + print *, ' ^' + print *, ' ^^^^^' + print *, ' ^' + print *, ' ^' +end program ch1 diff --git a/challenge-124/paulo-custodio/lua/ch-1.lua b/challenge-124/paulo-custodio/lua/ch-1.lua new file mode 100644 index 0000000000..663a2fd5c3 --- /dev/null +++ b/challenge-124/paulo-custodio/lua/ch-1.lua @@ -0,0 +1,26 @@ +#!/usr/bin/env lua + +--[[ +TASK #1 > Happy Women Day +Submitted by: Mohammad S Anwar +Write a script to print the Venus Symbol, international gender symbol for +women. Please feel free to use any character. +--]] + +io.write(" ^^^^^\n") +io.write(" ^ ^\n") +io.write(" ^ ^\n") +io.write(" ^ ^\n") +io.write(" ^ ^\n") +io.write(" ^ ^\n") +io.write(" ^ ^\n") +io.write(" ^ ^\n") +io.write(" ^ ^\n") +io.write(" ^ ^\n") +io.write(" ^^^^^\n") +io.write(" ^\n") +io.write(" ^\n") +io.write(" ^\n") +io.write(" ^^^^^\n") +io.write(" ^\n") +io.write(" ^\n") diff --git a/challenge-124/paulo-custodio/pascal/ch-1.pas b/challenge-124/paulo-custodio/pascal/ch-1.pas new file mode 100644 index 0000000000..ae2ba8be09 --- /dev/null +++ b/challenge-124/paulo-custodio/pascal/ch-1.pas @@ -0,0 +1,27 @@ +(* +TASK #1 > Happy Women Day +Submitted by: Mohammad S Anwar +Write a script to print the Venus Symbol, international gender symbol for +women. Please feel free to use any character. +*) + +program ch2(input, output); +begin + WriteLn(' ^^^^^'); + WriteLn(' ^ ^'); + WriteLn(' ^ ^'); + WriteLn(' ^ ^'); + WriteLn(' ^ ^'); + WriteLn(' ^ ^'); + WriteLn(' ^ ^'); + WriteLn(' ^ ^'); + WriteLn(' ^ ^'); + WriteLn(' ^ ^'); + WriteLn(' ^^^^^'); + WriteLn(' ^'); + WriteLn(' ^'); + WriteLn(' ^'); + WriteLn(' ^^^^^'); + WriteLn(' ^'); + WriteLn(' ^'); +end. diff --git a/challenge-124/paulo-custodio/perl/ch-1.pl b/challenge-124/paulo-custodio/perl/ch-1.pl new file mode 100644 index 0000000000..2703d633cf --- /dev/null +++ b/challenge-124/paulo-custodio/perl/ch-1.pl @@ -0,0 +1,26 @@ +#!/usr/bin/env perl + +# TASK #1 > Happy Women Day +# Submitted by: Mohammad S Anwar +# Write a script to print the Venus Symbol, international gender symbol for +# women. Please feel free to use any character. + +print <<'END'; + ^^^^^ + ^ ^ + ^ ^ + ^ ^ + ^ ^ + ^ ^ + ^ ^ + ^ ^ + ^ ^ + ^ ^ + ^^^^^ + ^ + ^ + ^ + ^^^^^ + ^ + ^ +END diff --git a/challenge-124/paulo-custodio/python/ch-1.py b/challenge-124/paulo-custodio/python/ch-1.py new file mode 100644 index 0000000000..cdc2e8c261 --- /dev/null +++ b/challenge-124/paulo-custodio/python/ch-1.py @@ -0,0 +1,26 @@ +#!/usr/bin/env python3 + +# TASK #1 > Happy Women Day +# Submitted by: Mohammad S Anwar +# Write a script to print the Venus Symbol, international gender symbol for +# women. Please feel free to use any character. + +print("""\ + ^^^^^ + ^ ^ + ^ ^ + ^ ^ + ^ ^ + ^ ^ + ^ ^ + ^ ^ + ^ ^ + ^ ^ + ^^^^^ + ^ + ^ + ^ + ^^^^^ + ^ + ^\ +""") diff --git a/challenge-124/paulo-custodio/t/test-1.yaml b/challenge-124/paulo-custodio/t/test-1.yaml new file mode 100644 index 0000000000..cb6df79303 --- /dev/null +++ b/challenge-124/paulo-custodio/t/test-1.yaml @@ -0,0 +1,22 @@ +- setup: + cleanup: + args: + input: + output: | + | ^^^^^ + | ^ ^ + | ^ ^ + | ^ ^ + | ^ ^ + | ^ ^ + | ^ ^ + | ^ ^ + | ^ ^ + | ^ ^ + | ^^^^^ + | ^ + | ^ + | ^ + | ^^^^^ + | ^ + | ^ -- cgit From d08524c217257b3cc4c9c19b24ecf8720f63d8dd Mon Sep 17 00:00:00 2001 From: Paulo Custodio Date: Thu, 28 Oct 2021 18:03:55 +0100 Subject: Add solutions to challenges 123, 124 --- challenge-001/paulo-custodio/go.pl | 34 +++--- challenge-003/paulo-custodio/Makefile | 2 + challenge-003/paulo-custodio/perl/ch-1.pl | 13 +- challenge-003/paulo-custodio/perl/ch-2.pl | 4 +- challenge-003/paulo-custodio/test.pl | 4 - challenge-123/paulo-custodio/Makefile | 2 + challenge-123/paulo-custodio/awk/ch-1.awk | 74 ++++++++++++ challenge-123/paulo-custodio/basic/ch-1.bas | 159 +++++++++++++++++++++++++ challenge-123/paulo-custodio/bc/ch-1.bc | 64 ++++++++++ challenge-123/paulo-custodio/c/ch-1.c | 103 ++++++++++++++++ challenge-123/paulo-custodio/cpp/ch-1.cpp | 60 ++++++++++ challenge-123/paulo-custodio/forth/ch-1.fs | 99 +++++++++++++++ challenge-123/paulo-custodio/lua/ch-1.lua | 45 +++++++ challenge-123/paulo-custodio/perl/ch-1.pl | 46 +++++++ challenge-123/paulo-custodio/perl/ch-2.pl | 67 +++++++++++ challenge-123/paulo-custodio/python/ch-1.py | 45 +++++++ challenge-123/paulo-custodio/t/test-1.yaml | 25 ++++ challenge-123/paulo-custodio/t/test-2.yaml | 10 ++ challenge-124/paulo-custodio/ada/ch_1.adb | 34 +++--- challenge-124/paulo-custodio/awk/ch-1.awk | 34 +++--- challenge-124/paulo-custodio/brainfuck/ch-1.pl | 6 +- challenge-124/paulo-custodio/c/ch-1.c | 34 +++--- challenge-124/paulo-custodio/cpp/ch-1.cpp | 34 +++--- challenge-124/paulo-custodio/d/ch_1.d | 34 +++--- challenge-124/paulo-custodio/forth/ch-1.fs | 34 +++--- challenge-124/paulo-custodio/fortran/ch-1.f90 | 4 +- challenge-124/paulo-custodio/perl/ch-2.pl | 49 ++++++++ challenge-124/paulo-custodio/python/ch-2.py | 44 +++++++ challenge-124/paulo-custodio/t/test-1.yaml | 2 +- challenge-124/paulo-custodio/t/test-2.yaml | 14 +++ 30 files changed, 1036 insertions(+), 143 deletions(-) create mode 100644 challenge-003/paulo-custodio/Makefile delete mode 100644 challenge-003/paulo-custodio/test.pl create mode 100644 challenge-123/paulo-custodio/Makefile create mode 100644 challenge-123/paulo-custodio/awk/ch-1.awk create mode 100644 challenge-123/paulo-custodio/basic/ch-1.bas create mode 100644 challenge-123/paulo-custodio/bc/ch-1.bc create mode 100644 challenge-123/paulo-custodio/c/ch-1.c create mode 100644 challenge-123/paulo-custodio/cpp/ch-1.cpp create mode 100644 challenge-123/paulo-custodio/forth/ch-1.fs create mode 100644 challenge-123/paulo-custodio/lua/ch-1.lua create mode 100644 challenge-123/paulo-custodio/perl/ch-1.pl create mode 100644 challenge-123/paulo-custodio/perl/ch-2.pl create mode 100644 challenge-123/paulo-custodio/python/ch-1.py create mode 100644 challenge-123/paulo-custodio/t/test-1.yaml create mode 100644 challenge-123/paulo-custodio/t/test-2.yaml create mode 100644 challenge-124/paulo-custodio/perl/ch-2.pl create mode 100644 challenge-124/paulo-custodio/python/ch-2.py create mode 100644 challenge-124/paulo-custodio/t/test-2.yaml diff --git a/challenge-001/paulo-custodio/go.pl b/challenge-001/paulo-custodio/go.pl index 13ad914edd..d4639380d3 100644 --- a/challenge-001/paulo-custodio/go.pl +++ b/challenge-001/paulo-custodio/go.pl @@ -7,23 +7,23 @@ use Path::Tiny; or die "Usage: ",path($0)->basename," nr\n"; my $nr = sprintf("%03d", $ARGV[0]); -for my $dir (qw( - ada - awk - basic - bc - brainfuck - c - cpp - d - forth - fortran - lua - pascal - perl - python - t - )) { +for my $dir (qw( + ada + awk + basic + bc + brainfuck + c + cpp + d + forth + fortran + lua + pascal + perl + python + t + )) { path("challenge-$nr/paulo-custodio/$dir")->mkpath; } path("challenge-$nr/paulo-custodio/README")->spew("Solution by Paulo Custodio\n"); diff --git a/challenge-003/paulo-custodio/Makefile b/challenge-003/paulo-custodio/Makefile new file mode 100644 index 0000000000..6316089eb8 --- /dev/null +++ b/challenge-003/paulo-custodio/Makefile @@ -0,0 +1,2 @@ +all: + perl ../../challenge-001/paulo-custodio/test.pl diff --git a/challenge-003/paulo-custodio/perl/ch-1.pl b/challenge-003/paulo-custodio/perl/ch-1.pl index e1c2d5b0f8..afd712b149 100644 --- a/challenge-003/paulo-custodio/perl/ch-1.pl +++ b/challenge-003/paulo-custodio/perl/ch-1.pl @@ -7,17 +7,8 @@ # or equal to 5. They are also called Hamming/Regular/Ugly numbers. For more # information, please check this wikipedia. -use strict; -use warnings; -use 5.030; - -sub min { - my($min, @a) = @_; - for (@a) { - $min = $_ if $min > $_; - } - return $min; -} +use Modern::Perl; +use List::Util 'min'; # return an iterator to generate the sequence # the sequence is a merge of all multiples of 2, 3 and 5 diff --git a/challenge-003/paulo-custodio/perl/ch-2.pl b/challenge-003/paulo-custodio/perl/ch-2.pl index bb3afc06e2..83ab59311f 100644 --- a/challenge-003/paulo-custodio/perl/ch-2.pl +++ b/challenge-003/paulo-custodio/perl/ch-2.pl @@ -7,9 +7,7 @@ # the command line. The Pascal Triangle should have at least 3 rows. For more # information about Pascal Triangle, check this wikipedia page. -use strict; -use warnings; -use 5.030; +use Modern::Perl; my($rows) = @ARGV; diff --git a/challenge-003/paulo-custodio/test.pl b/challenge-003/paulo-custodio/test.pl deleted file mode 100644 index ba6c37260b..0000000000 --- a/challenge-003/paulo-custodio/test.pl +++ /dev/null @@ -1,4 +0,0 @@ -#!/usr/bin/env perl -use Modern::Perl; -use Test::More; -require '../../challenge-001/paulo-custodio/test.pl'; diff --git a/challenge-123/paulo-custodio/Makefile b/challenge-123/paulo-custodio/Makefile new file mode 100644 index 0000000000..6316089eb8 --- /dev/null +++ b/challenge-123/paulo-custodio/Makefile @@ -0,0 +1,2 @@ +all: + perl ../../challenge-001/paulo-custodio/test.pl diff --git a/challenge-123/paulo-custodio/awk/ch-1.awk b/challenge-123/paulo-custodio/awk/ch-1.awk new file mode 100644 index 0000000000..78dffcaa09 --- /dev/null +++ b/challenge-123/paulo-custodio/awk/ch-1.awk @@ -0,0 +1,74 @@ +#!/usr/bin/gawk + +# TASK #1 > Ugly Numbers +# Submitted by: Mohammad S Anwar +# You are given an integer $n >= 1. +# +# Write a script to find the $nth element of Ugly Numbers. +# +# Ugly numbers are those number whose prime factors are 2, 3 or 5. For example, +# the first 10 Ugly Numbers are 1, 2, 3, 4, 5, 6, 8, 9, 10, 12. +# +# Example +# Input: $n = 7 +# Output: 8 +# +# Input: $n = 10 +# Output: 12 + +function min(a, b) { + return (a Ugly Numbers +' Submitted by: Mohammad S Anwar +' You are given an integer $n >= 1. +' +' Write a script to find the $nth element of Ugly Numbers. +' +' Ugly numbers are those number whose prime factors are 2, 3 or 5. For example, +' the first 10 Ugly Numbers are 1, 2, 3, 4, 5, 6, 8, 9, 10, 12. +' +' Example +' Input: $n = 7 +' Output: 8 +' +' Input: $n = 10 +' Output: 12 + +' deque of integers +type ElemType + nValue as integer + pNext as ElemType ptr +end type + +type QType + pFront as ElemType ptr + pBack as ElemType ptr +end type + +function QEmpty(byref q as QType) as boolean + if q.pFront = 0 then + QEmpty = true + else + QEmpty = false + end if +end function + +function QFront(byref q as QType) as integer + QFront = q.pFront->nValue +end function + +function QBack(byref q as QType) as integer + QBack = q.pBack->nValue +end function + +sub QPushBack(byref q as QType, nValue as integer) + dim pElem as ElemType ptr + + pElem = callocate(1, sizeof(ElemType)) + pElem->nValue = nValue + + if q.pFront = 0 then + q.pFront = pElem + q.pBack = pElem + else + q.pBack->pNext = pElem + q.pBack = pElem + end if +end sub + +sub QPopBack(byref q as QType) + dim pElem as ElemType ptr + + if q.pFront = 0 then ' empty + elseif q.pFront = q.pBack then ' only one element + deallocate q.pFront + q.pFront = 0 + q.pBack = 0 + else ' more than one element + pElem = q.pFront + do while pElem->pNext <> q.pBack + pElem = pElem->pNext + loop + deallocate q.pBack + q.pBack = pElem + pElem->pNext = 0 + end if +end sub + +sub QPushFront(byref q as QType, nValue as integer) + dim pElem as ElemType ptr + + pElem = callocate(1, sizeof(ElemType)) + pElem->nValue = nValue + + if q.pFront = 0 then + q.pFront = pElem + q.pBack = pElem + else + pElem->pNext = q.pFront + q.pFront = pElem + end if +end sub + +sub QPopFront(byref q as QType) + dim pElem as ElemType ptr + + if q.pFront = 0 then ' empty + elseif q.pFront = q.pBack then ' only one element + deallocate q.pFront + q.pFront = 0 + q.pBack = 0 + else ' more than one element + pElem = q.pFront + q.pFront = pElem->pNext + deallocate pElem + end if +end sub + + +function min(a as integer, b as integer) as integer + if a < b then + min = a + else + min = b + end if +end function + +function min3(a as integer, b as integer, c as integer) as integer + min3 = min(a, min(b, c)) +end function + + +' Hamming generator +dim shared q2 as QType +dim shared q3 as QType +dim shared q5 as QType + +function next_hamming() as integer + dim n as integer + + ' init queues at start + if QEmpty(q2) then + QPushBack q2, 1 + QPushBack q3, 1 + QPushBack q5, 1 + end if + + ' get the smallest of the queue heads + n = min3(QFront(q2), QFront(q3), QFront(q5)) + + ' shift used multiples + if n = QFront(q2) then QPopFront q2 + if n = QFront(q3) then QPopFront q3 + if n = QFront(q5) then QPopFront q5 + + ' push next multiples + QPushBack q2, 2*n + QPushBack q3, 3*n + QPushBack q5, 5*n + + next_hamming = n +end function + +' main +dim i as integer +for i=1 to val(command(1)) + print next_hamming() +next i diff --git a/challenge-123/paulo-custodio/bc/ch-1.bc b/challenge-123/paulo-custodio/bc/ch-1.bc new file mode 100644 index 0000000000..3199ef0684 --- /dev/null +++ b/challenge-123/paulo-custodio/bc/ch-1.bc @@ -0,0 +1,64 @@ +#!/usr/bin/bc -ql + +/* +TASK #1 > Ugly Numbers +Submitted by: Mohammad S Anwar +You are given an integer $n >= 1. + +Write a script to find the $nth element of Ugly Numbers. + +Ugly numbers are those number whose prime factors are 2, 3 or 5. For example, +the first 10 Ugly Numbers are 1, 2, 3, 4, 5, 6, 8, 9, 10, 12. + +Example +Input: $n = 7 +Output: 8 + +Input: $n = 10 +Output: 12 +*/ + +scale = 0 + +num = read() + +define min(a,b) { + if (a < b) { return a; } else { return b; } +} + +define min3(a,b,c) { + return min(a,min(b,c)); +} + +q2[0] = 1; q2size = 1 +q3[0] = 1; q3size = 1 +q5[0] = 1; q5size = 1 + +for (i = 0; i < num; i++) { + /* next hamming: get smallest of the queue heads */ + h = min3(q2[0], q3[0], q5[0]) + h + + /* shift used multiples */ + if (h == q2[0]) { + for (j = 1; j < q2size; j++) + q2[j-1] = q2[j] + q2size = q2size-1 + } + if (h == q3[0]) { + for (j = 1; j < q3size; j++) + q3[j-1] = q3[j] + q3size = q3size-1 + } + if (h == q5[0]) { + for (j = 1; j < q5size; j++) + q5[j-1] = q5[j] + q5size = q5size-1 + } + + /* push next multiples */ + q2[q2size] = 2*h; q2size = q2size+1 + q3[q3size] = 3*h; q3size = q3size+1 + q5[q5size] = 5*h; q5size = q5size+1 +} +quit diff --git a/challenge-123/paulo-custodio/c/ch-1.c b/challenge-123/paulo-custodio/c/ch-1.c new file mode 100644 index 0000000000..f814da939c --- /dev/null +++ b/challenge-123/paulo-custodio/c/ch-1.c @@ -0,0 +1,103 @@ +/* +TASK #1 > Ugly Numbers +Submitted by: Mohammad S Anwar +You are given an integer $n >= 1. + +Write a script to find the $nth element of Ugly Numbers. + +Ugly numbers are those number whose prime factors are 2, 3 or 5. For example, +the first 10 Ugly Numbers are 1, 2, 3, 4, 5, 6, 8, 9, 10, 12. + +Example +Input: $n = 7 +Output: 8 + +Input: $n = 10 +Output: 12 +*/ + +#include +#include +#include +#include + +// implement deque +#define Q_SIZE 100 + +typedef struct Q { + size_t front; + size_t back; + int data[Q_SIZE]; +} Q; + +bool q_empty(Q* q) { + return q->front == q->back; +} + +int q_front(Q* q) { + return q->data[q->front]; +} + +int q_back(Q* q) { + return q->data[(q->back + Q_SIZE - 1) % Q_SIZE]; +} + +void q_push_back(Q* q, int n) { + q->data[q->back] = n; + q->back = (q->back + 1) % Q_SIZE; +} + +void q_pop_back(Q* q) { + q->back = (q->back + Q_SIZE -1) % Q_SIZE; +} + +void q_push_front(Q* q, int n) { + q->front = (q->front + Q_SIZE - 1) % Q_SIZE; + q->data[q->front] = n; +} + +void q_pop_front(Q* q) { + q->front = (q->front +1) % Q_SIZE; +} + +int min(int a, int b) { + return a Ugly Numbers +Submitted by: Mohammad S Anwar +You are given an integer $n >= 1. + +Write a script to find the $nth element of Ugly Numbers. + +Ugly numbers are those number whose prime factors are 2, 3 or 5. For example, +the first 10 Ugly Numbers are 1, 2, 3, 4, 5, 6, 8, 9, 10, 12. + +Example +Input: $n = 7 +Output: 8 + +Input: $n = 10 +Output: 12 +*/ + +#include +#include +#include +#include + +int min3(int a, int b, int c) { + return std::min(a, std::min(b, c)); +} + +// hamming number generator +std::deque q2, q3, q5; + +int next_hamming() { + // init three queues with 1 + if (q2.empty()) { + q2.push_back(1); + q3.push_back(1); + q5.push_back(1); + } + + // get the smallest of the queue heads + int n = min3(q2.front(), q3.front(), q5.front()); + + // shift used multiples + if (n == q2.front()) q2.pop_front(); + if (n == q3.front()) q3.pop_front(); + if (n == q5.front()) q5.pop_front(); + + // push next multiples + q2.push_back(2*n); + q3.push_back(3*n); + q5.push_back(5*n); + + return n; +} + +int main(int argc, char* argv[]) { + if (argc == 2) { + for (int i = 0; i < atoi(argv[1]); i++) + std::cout << next_hamming() << std::endl; + } +} diff --git a/challenge-123/paulo-custodio/forth/ch-1.fs b/challenge-123/paulo-custodio/forth/ch-1.fs new file mode 100644 index 0000000000..b18ed9e892 --- /dev/null +++ b/challenge-123/paulo-custodio/forth/ch-1.fs @@ -0,0 +1,99 @@ +#! /usr/bin/env gforth + +\ TASK #1 > Ugly Numbers +\ Submitted by: Mohammad S Anwar +\ You are given an integer $n >= 1. +\ +\ Write a script to find the $nth element of Ugly Numbers. +\ +\ Ugly numbers are those number whose prime factors are 2, 3 or 5. For example, +\ the first 10 Ugly Numbers are 1, 2, 3, 4, 5, 6, 8, 9, 10, 12. +\ +\ Example +\ Input: $n = 7 +\ Output: 8 +\ +\ Input: $n = 10 +\ Output: 12 + +\ circular queue of integers +1024 CONSTANT Q_SIZE \ must be power of 2 + +: q.pFront ( q -- front-addr ) ; +: q.pBack ( q -- back-addr ) 1 CELLS + ; +: q.pData ( q -- data-addr ) 2 CELLS + ; +: e.empty ( q -- f ) DUP q.pFront @ Q_SIZE MOD + SWAP q.pBack @ Q_SIZE MOD = ; +: q.pElem ( q index - addr ) Q_SIZE MOD CELLS SWAP q.pData + ; + +: create_q ( -- ) + CREATE 0 , 0 , Q_SIZE ALLOT \ front back data...data +; + +: q.Front ( q -- front-elem ) + DUP q.pFront @ ( q index ) + q.pElem @ +; + +: q.Back ( q -- back-elem ) + DUP q.pBack @ 1- ( q index ) + q.pElem @ +; + +: q.PushBack ( q elem -- ) + OVER q.pBack @ ( q elem back ) + 2 PICK SWAP ( q elem q back ) + q.pElem ( q elem elem-addr ) + ! ( q ) + q.pBack 1 SWAP +! \ increment +; + +: q.PopBack ( q -- ) + q.pBack -1 SWAP +! +; + +: q.PushFront ( q elem -- ) + OVER q.pFront -1 SWAP +! \ decrement front + SWAP dup q.pFront @ q.pElem ! +; + +: q.PopFront ( q -- ) + q.pFront 1 SWAP +! +; + + +\ queue or powers of 2, 3 and 5 +create_q q2 q2 1 q.PushBack +create_q q3 q3 1 q.PushBack +create_q q5 q5 1 q.PushBack + + +\ generate the next hamming number +: next_hamming ( -- n ) + \ get the smallest of the queue heads + q2 q.Front q3 q.Front MIN q5 q.Front MIN ( n ) + + \ shift used multiples + q2 q.Front OVER = IF q2 q.PopFront THEN + q3 q.Front OVER = IF q3 q.PopFront THEN + q5 q.Front OVER = IF q5 q.PopFront THEN + + \ push next multiples + 2 OVER * q2 SWAP q.PushBack + 3 OVER * q3 SWAP q.PushBack + 5 OVER * q5 SWAP q.PushBack +; + + +\ generate sequence of hamming numbers +: hamming ( n -- ) + 0 ?DO + next_hamming . CR + LOOP +; + + +\ get command line argument, call hamming +NEXT-ARG S>NUMBER? 0= THROW DROP +hamming +BYE diff --git a/challenge-123/paulo-custodio/lua/ch-1.lua b/challenge-123/paulo-custodio/lua/ch-1.lua new file mode 100644 index 0000000000..b491dbf71a --- /dev/null +++ b/challenge-123/paulo-custodio/lua/ch-1.lua @@ -0,0 +1,45 @@ +#!/usr/bin/env lua + +--[[ +TASK #1 > Ugly Numbers +Submitted by: Mohammad S Anwar +You are given an integer $n >= 1. + +Write a script to find the $nth element of Ugly Numbers. + +Ugly numbers are those number whose prime factors are 2, 3 or 5. For example, +the first 10 Ugly Numbers are 1, 2, 3, 4, 5, 6, 8, 9, 10, 12. + +Example +Input: $n = 7 +Output: 8 + +Input: $n = 10 +Output: 12 +--]] + +-- sequence is a merge of all multiples of 2, 3 and 5 +seq2 = {1} +seq3 = {1} +seq5 = {1} + +function next_hamming() + -- get the smallest of the queue heads + local n = math.min(seq2[1], seq3[1], seq5[1]) + + -- shift used multiples + if n == seq2[1] then table.remove(seq2, 1); end + if n == seq3[1] then table.remove(seq3, 1); end + if n == seq5[1] then table.remove(seq5, 1); end + + -- push next multiples + table.insert(seq2, 2*n) + table.insert(seq3, 3*n) + table.insert(seq5, 5*n) + + return n +end + +for i=1,tonumber(arg[1]) do + io.write(next_hamming(), "\n") +end diff --git a/challenge-123/paulo-custodio/perl/ch-1.pl b/challenge-123/paulo-custodio/perl/ch-1.pl new file mode 100644 index 0000000000..3e4dd62d68 --- /dev/null +++ b/challenge-123/paulo-custodio/perl/ch-1.pl @@ -0,0 +1,46 @@ +#!/usr/bin/env perl + +# TASK #1 > Ugly Numbers +# Submitted by: Mohammad S Anwar +# You are given an integer $n >= 1. +# +# Write a script to find the $nth element of Ugly Numbers. +# +# Ugly numbers are those number whose prime factors are 2, 3 or 5. For example, +# the first 10 Ugly Numbers are 1, 2, 3, 4, 5, 6, 8, 9, 10, 12. +# +# Example +# Input: $n = 7 +# Output: 8 +# +# Input: $n = 10 +# Output: 12 + +use Modern::Perl; +use List::Util 'min'; + +# return an iterator to generate the sequence +# the sequence is a merge of all multiples of 2, 3 and 5 +sub hamming_gen { + # sequences of hamming numbers 2*n, 3*n, 5*n + my @seq = ([1], [1], [1]); + my @base = (2, 3, 5); + + return sub { + # get the smallest of the multiples + my $n = min($seq[0][0], $seq[1][0], $seq[2][0]); + for my $i (0..2) { + # shift used multiples + shift @{$seq[$i]} if $seq[$i][0] == $n; + # push next multiple + push @{$seq[$i]}, $n*$base[$i]; + } + return $n; + } +} + +my($n) = @ARGV; +my $hamming = hamming_gen(); +for (1 .. $n) { + say $hamming->(); +} diff --git a/challenge-123/paulo-custodio/perl/ch-2.pl b/challenge-123/paulo-custodio/perl/ch-2.pl new file mode 100644 index 0000000000..d3de33c77f --- /dev/null +++ b/challenge-123/paulo-custodio/perl/ch-2.pl @@ -0,0 +1,67 @@ +#!/usr/bin/env perl + +# TASK #2 > Square Points +# Submitted by: Mohammad S Anwar +# You are given coordinates of four points i.e. +# (x1, y1), (x2, y2), (x3, y3) and (x4, y4). +# +# Write a script to find out if the given four points form a square. +# +# Example +# Input: x1 = 10, y1 = 20 +# x2 = 20, y2 = 20 +# x3 = 20, y3 = 10 +# x4 = 10, y4 = 10 +# Output: 1 as the given coordinates form a square. +# +# Input: x1 = 12, y1 = 24 +# x2 = 16, y2 = 10 +# x3 = 20, y3 = 12 +# x4 = 18, y4 = 16 +# Output: 0 as the given coordinates doesn't form a square. + +use Modern::Perl; + +# point object +{ + package Point; + use Object::Tiny::RW qw( x y ); + + sub new { + my($class, $x, $y) = @_; + return bless {x=>$x, y=>$y}, $class; + } +} + +# square of distance between two points +sub dist_sq { + my($p, $q) = @_; + return ($p->x - $q->x) * ($p->x - $q->x) + + ($p->y - $q->y) * ($p->y - $q->y) +} + +# check if four points form a square +sub is_square { + my($p1, $p2, $p3, $p4) = @_; + + my $d2 = dist_sq($p1, $p2); + my $d3 = dist_sq($p1, $p3); + my $d4 = dist_sq($p1, $p4); + + return 0 if $d2 == 0 || $d3 == 0 || $d4 == 0; + + return 1 if $d2 == $d3 && 2 * $d2 == $d4 && + 2 * dist_sq($p2, $p4) == dist_sq($p2, $p3); + return 1 if $d3 == $d4 && 2 * $d3 == $d2 && + 2 * dist_sq($p3, $p2) == dist_sq($p3, $p4); + return 1 if $d2 == $d4 && 2 * $d2 == $d3 && + 2 * dist_sq($p2, $p3) == dist_sq($p2, $p4); + return 0; +} + +my $p1 = Point->new(splice(@ARGV, 0, 2)); +my $p2 = Point->new(splice(@ARGV, 0, 2)); +my $p3 = Point->new(splice(@ARGV, 0, 2)); +my $p4 = Point->new(splice(@ARGV, 0, 2)); + +say is_square($p1, $p2, $p3, $p4); diff --git a/challenge-123/paulo-custodio/python/ch-1.py b/challenge-123/paulo-custodio/python/ch-1.py new file mode 100644 index 0000000000..f736c76e1a --- /dev/null +++ b/challenge-123/paulo-custodio/python/ch-1.py @@ -0,0 +1,45 @@ +#!/usr/bin/env python + +# TASK #1 > Ugly Numbers +# Submitted by: Mohammad S Anwar +# You are given an integer $n >= 1. +# +# Write a script to find the $nth element of Ugly Numbers. +# +# Ugly numbers are those number whose prime factors are 2, 3 or 5. For example, +# the first 10 Ugly Numbers are 1, 2, 3, 4, 5, 6, 8, 9, 10, 12. +# +# Example +# Input: $n = 7 +# Output: 8 +# +# Input: $n = 10 +# Output: 12 + +import sys + +# return an iterator to generate the sequence +# the sequence is a merge of all multiples of 2, 3 and 5 +def hamming_gen(): + seq = [[1], [1], [1]] + base = [2, 3, 5] + + while True: + # get the smallest of the multiples + n = min(seq[0][0], seq[1][0], seq[2][0]) + + for i in range(0, 3): + # shift used multiples + if seq[i][0] == n: + seq[i].pop(0) + + # push next multiple + seq[i].append(n*base[i]) + + yield n + + +# main +iter = hamming_gen() +for i in range(0, int(sys.argv[1])): + print(next(iter)) diff --git a/challenge-123/paulo-custodio/t/test-1.yaml b/challenge-123/paulo-custodio/t/test-1.yaml new file mode 100644 index 0000000000..1bef1a5dee --- /dev/null +++ b/challenge-123/paulo-custodio/t/test-1.yaml @@ -0,0 +1,25 @@ +- setup: + cleanup: + args: 20 + input: + output: | + 1 + 2 + 3 + 4 + 5 + 6 + 8 + 9 + 10 + 12 + 15 + 16 + 18 + 20 + 24 + 25 + 27 + 30 + 32 + 36 diff --git a/challenge-123/paulo-custodio/t/test-2.yaml b/challenge-123/paulo-custodio/t/test-2.yaml new file mode 100644 index 0000000000..6ab926e8f5 --- /dev/null +++ b/challenge-123/paulo-custodio/t/test-2.yaml @@ -0,0 +1,10 @@ +- setup: + cleanup: + args: 10 20 20 20 20 10 10 10 + input: + output: 1 +- setup: + cleanup: + args: 12 24 16 10 20 12 18 16 + input: + output: 0 diff --git a/challenge-124/paulo-custodio/ada/ch_1.adb b/challenge-124/paulo-custodio/ada/ch_1.adb index 7ec0278e04..a0ffd94a23 100644 --- a/challenge-124/paulo-custodio/ada/ch_1.adb +++ b/challenge-124/paulo-custodio/ada/ch_1.adb @@ -8,21 +8,21 @@ with Ada.Text_IO; use Ada.Text_IO; procedure ch_1 is begin - Put_Line(" ^^^^^"); - Put_Line(" ^ ^"); - Put_Line(" ^ ^"); - Put_Line(" ^ ^"); - Put_Line(" ^ ^"); - Put_Line(" ^ ^"); - Put_Line(" ^ ^"); - Put_Line(" ^ ^"); - Put_Line(" ^ ^"); - Put_Line(" ^ ^"); - Put_Line(" ^^^^^"); - Put_Line(" ^"); - Put_Line(" ^"); - Put_Line(" ^"); - Put_Line(" ^^^^^"); - Put_Line(" ^"); - Put_Line(" ^"); + Put_Line(" ^^^^^"); + Put_Line(" ^ ^"); + Put_Line(" ^ ^"); + Put_Line(" ^ ^"); + Put_Line(" ^ ^"); + Put_Line(" ^ ^"); + Put_Line(" ^ ^"); + Put_Line(" ^ ^"); + Put_Line(" ^ ^"); + Put_Line(" ^ ^"); + Put_Line(" ^^^^^"); + Put_Line(" ^"); + Put_Line(" ^"); + Put_Line(" ^"); + Put_Line(" ^^^^^"); + Put_Line(" ^"); + Put_Line(" ^"); end ch_1; diff --git a/challenge-124/paulo-custodio/awk/ch-1.awk b/challenge-124/paulo-custodio/awk/ch-1.awk index 09c3c5f601..529c8253c6 100644 --- a/challenge-124/paulo-custodio/awk/ch-1.awk +++ b/challenge-124/paulo-custodio/awk/ch-1.awk @@ -6,21 +6,21 @@ # women. Please feel free to use any character. BEGIN { - print " ^^^^^" - print " ^ ^" - print " ^ ^" - print " ^ ^" - print " ^ ^" - print " ^ ^" - print " ^ ^" - print " ^ ^" - print " ^ ^" - print " ^ ^" - print " ^^^^^" - print " ^" - print " ^" - print " ^" - print " ^^^^^" - print " ^" - print " ^" + print " ^^^^^" + print " ^ ^" + print " ^ ^" + print " ^ ^" + print " ^ ^" + print " ^ ^" + print " ^ ^" + print " ^ ^" + print " ^ ^" + print " ^ ^" + print " ^^^^^" + print " ^" + print " ^" + print " ^" + print " ^^^^^" + print " ^" + print " ^" } diff --git a/challenge-124/paulo-custodio/brainfuck/ch-1.pl b/challenge-124/paulo-custodio/brainfuck/ch-1.pl index 264e25c4fd..949796633f 100644 --- a/challenge-124/paulo-custodio/brainfuck/ch-1.pl +++ b/challenge-124/paulo-custodio/brainfuck/ch-1.pl @@ -30,7 +30,7 @@ my $text = <<'END'; END for (split //, $text) { - print "[-]"; # zero cell - print "+" x ord($_); # set cell to ASCII value of character - print "."; # output character + print "[-]"; # zero cell + print "+" x ord($_); # set cell to ASCII value of character + print "."; # output character } diff --git a/challenge-124/paulo-custodio/c/ch-1.c b/challenge-124/paulo-custodio/c/ch-1.c index f88efc82bb..f20cb77616 100644 --- a/challenge-124/paulo-custodio/c/ch-1.c +++ b/challenge-124/paulo-custodio/c/ch-1.c @@ -8,21 +8,21 @@ women. Please feel free to use any character. #include "stdio.h" int main() { - puts(" ^^^^^"); - puts(" ^ ^"); - puts(" ^ ^"); - puts(" ^ ^"); - puts(" ^ ^"); - puts(" ^ ^"); - puts(" ^ ^"); - puts(" ^ ^"); - puts(" ^ ^"); - puts(" ^ ^"); - puts(" ^^^^^"); - puts(" ^"); - puts(" ^"); - puts(" ^"); - puts(" ^^^^^"); - puts(" ^"); - puts(" ^"); + puts(" ^^^^^"); + puts(" ^ ^"); + puts(" ^ ^"); + puts(" ^ ^"); + puts(" ^ ^"); + puts(" ^ ^"); + puts(" ^ ^"); + puts(" ^ ^"); + puts(" ^ ^"); + puts(" ^ ^"); + puts(" ^^^^^"); + puts(" ^"); + puts(" ^"); + puts(" ^"); + puts(" ^^^^^"); + puts(" ^"); + puts(" ^"); } diff --git a/challenge-124/paulo-custodio/cpp/ch-1.cpp b/challenge-124/paulo-custodio/cpp/ch-1.cpp index 988476fdfc..5bd8875f99 100644 --- a/challenge-124/paulo-custodio/cpp/ch-1.cpp +++ b/challenge-124/paulo-custodio/cpp/ch-1.cpp @@ -9,21 +9,21 @@ women. Please feel free to use any character. using namespace std; int main() { - cout << " ^^^^^" << endl; - cout << " ^ ^" << endl; - cout << " ^ ^" << endl; - cout << " ^ ^" << endl; - cout << " ^ ^" << endl; - cout << " ^ ^" << endl; - cout << " ^ ^" << endl; - cout << " ^ ^" << endl; - cout << " ^ ^" << endl; - cout << " ^ ^" << endl; - cout << " ^^^^^" << endl; - cout << " ^" << endl; - cout << " ^" << endl; - cout << " ^" << endl; - cout << " ^^^^^" << endl; - cout << " ^" << endl; - cout << " ^" << endl; + cout << " ^^^^^" << endl; + cout << " ^ ^" << endl; + cout << " ^ ^" << endl; + cout << " ^ ^" << endl; + cout << " ^ ^" << endl; + cout << " ^ ^" << endl; + cout << " ^ ^" << endl; + cout << " ^ ^" << endl; + cout << " ^ ^" << endl; + cout << " ^ ^" << endl; + cout << " ^^^^^" << endl; + cout << " ^" << endl; + cout << " ^" << endl; + cout << " ^" << endl; + cout << " ^^^^^" << endl; + cout << " ^" << endl; + cout << " ^" << endl; } diff --git a/challenge-124/paulo-custodio/d/ch_1.d b/challenge-124/paulo-custodio/d/ch_1.d index d9d5734676..8252770018 100644 --- a/challenge-124/paulo-custodio/d/ch_1.d +++ b/challenge-124/paulo-custodio/d/ch_1.d @@ -8,21 +8,21 @@ women. Please feel free to use any character. import std.stdio; void main() { - writeln(" ^^^^^"); - writeln(" ^ ^"); - writeln(" ^ ^"); - writeln(" ^ ^"); - writeln(" ^ ^"); - writeln(" ^ ^"); - writeln(" ^ ^"); - writeln(" ^ ^"); - writeln(" ^ ^"); - writeln(" ^ ^"); - writeln(" ^^^^^"); - writeln(" ^"); - writeln(" ^"); - writeln(" ^"); - writeln(" ^^^^^"); - writeln(" ^"); - writeln(" ^"); + writeln(" ^^^^^"); + writeln(" ^ ^"); + writeln(" ^ ^"); + writeln(" ^ ^"); + writeln(" ^ ^"); + writeln(" ^ ^"); + writeln(" ^ ^"); + writeln(" ^ ^"); + writeln(" ^ ^"); + writeln(" ^ ^"); + writeln(" ^^^^^"); + writeln(" ^"); + writeln(" ^"); + writeln(" ^"); + writeln(" ^^^^^"); + writeln(" ^"); + writeln(" ^"); } diff --git a/challenge-124/paulo-custodio/forth/ch-1.fs b/challenge-124/paulo-custodio/forth/ch-1.fs index 1385d59b9e..5f3c78cb56 100644 --- a/challenge-124/paulo-custodio/forth/ch-1.fs +++ b/challenge-124/paulo-custodio/forth/ch-1.fs @@ -6,23 +6,23 @@ \ women. Please feel free to use any character. : VENUS - ." ^^^^^" CR - ." ^ ^" CR - ." ^ ^" CR - ." ^ ^" CR - ." ^ ^" CR - ." ^ ^" CR - ." ^ ^" CR - ." ^ ^" CR - ." ^ ^" CR - ." ^ ^" CR - ." ^^^^^" CR - ." ^" CR - ." ^" CR - ." ^" CR - ." ^^^^^" CR - ." ^" CR - ." ^" CR + ." ^^^^^" CR + ." ^ ^" CR + ." ^ ^" CR + ." ^ ^" CR + ." ^ ^" CR + ." ^ ^" CR + ." ^ ^" CR + ." ^ ^" CR + ." ^ ^" CR + ." ^ ^" CR + ." ^^^^^" CR + ." ^" CR + ." ^" CR + ." ^" CR + ." ^^^^^" CR + ." ^" CR + ." ^" CR ; VENUS BYE diff --git a/challenge-124/paulo-custodio/fortran/ch-1.f90 b/challenge-124/paulo-custodio/fortran/ch-1.f90 index 8e5122303f..270f14c39c 100644 --- a/challenge-124/paulo-custodio/fortran/ch-1.f90 +++ b/challenge-124/paulo-custodio/fortran/ch-1.f90 @@ -4,8 +4,8 @@ ! women. Please feel free to use any character. program ch1 - implicit none - + implicit none + print *, ' ^^^^^' print *, ' ^ ^' print *, ' ^ ^' diff --git a/challenge-124/paulo-custodio/perl/ch-2.pl b/challenge-124/paulo-custodio/perl/ch-2.pl new file mode 100644 index 0000000000..cf3cf310f7 --- /dev/null +++ b/challenge-124/paulo-custodio/perl/ch-2.pl @@ -0,0 +1,49 @@ +#!/usr/bin/env perl + +# TASK #2 > Tug of War +# Submitted by: Mohammad S Anwar +# You are given a set of $n integers (n1, n2, n3, ….). +# +# Write a script to divide the set in two subsets of n/2 sizes each so that +# the difference of the sum of two subsets is the least. If $n is even then +# each subset must be of size $n/2 each. In case $n is odd then one subset +# must be ($n-1)/2 and other must be ($n+1)/2. +# +# Example +# Input: Set = (10, 20, 30, 40, 50, 60, 70, 80, 90, 100) +# Output: Subset 1 = (30, 40, 60, 70, 80) +# Subset 2 = (10, 20, 50, 90, 100) +# +# Input: Set = (10, -15, 20, 30, -25, 0, 5, 40, -5) +# Subset 1 = (30, 0, 5, -5) +# Subset 2 = (10, -15, 20, -25, 40) + +use Modern::Perl; +use Math::Combinatorics 'combine'; +use Array::Set 'set_diff'; +use List::Util 'sum'; + +my @set = @ARGV; +divide(@set); + + +sub divide { + my(@set) = @_; + my $goal = sum(@set)/2; + my $k = int(scalar(@set)/2); + my @cur_subset; + my $cur_dist = $goal*2; + + for (combine($k, @set)) { + my @subset = @$_; + my $dist = abs(sum(@subset)-$goal); + if ($dist < $cur_dist) { + @cur_subset = @subset; + $cur_dist = $dist; + } + } + + my @other_subset = @{set_diff(\@set, \@cur_subset)}; + say "(", join(", ", sort {$a<=>$b} @cur_subset), ")"; + say "(", join(", ", sort {$a<=>$b} @other_subset), ")"; +} diff --git a/challenge-124/paulo-custodio/python/ch-2.py b/challenge-124/paulo-custodio/python/ch-2.py new file mode 100644 index 0000000000..9643673641 --- /dev/null +++ b/challenge-124/paulo-custodio/python/ch-2.py @@ -0,0 +1,44 @@ +#!/usr/bin/env python3 + +# TASK #2 > Tug of War +# Submitted by: Mohammad S Anwar +# You are given a set of $n integers (n1, n2, n3, ...). +# +# Wr