diff options
| author | Mohammad S Anwar <Mohammad.Anwar@yahoo.com> | 2023-03-08 19:42:40 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-03-08 19:42:40 +0000 |
| commit | eec30c1f4243a121d0dc433ce1590023ba9541c9 (patch) | |
| tree | ca80f807e16eba4ac2db48599f3178e8911ddf86 | |
| parent | 67ace03ee5af997e6bdb375ace179e308fbb2bfd (diff) | |
| parent | f904ee6db63dee40cdf1a0ea8ee1ec54403049a2 (diff) | |
| download | perlweeklychallenge-club-eec30c1f4243a121d0dc433ce1590023ba9541c9.tar.gz perlweeklychallenge-club-eec30c1f4243a121d0dc433ce1590023ba9541c9.tar.bz2 perlweeklychallenge-club-eec30c1f4243a121d0dc433ce1590023ba9541c9.zip | |
Merge pull request #7681 from pauloscustodio/master
Add Perl, C, C++ and Forth solutions
26 files changed, 1448 insertions, 0 deletions
diff --git a/challenge-203/paulo-custodio/Makefile b/challenge-203/paulo-custodio/Makefile new file mode 100644 index 0000000000..c3c762d746 --- /dev/null +++ b/challenge-203/paulo-custodio/Makefile @@ -0,0 +1,2 @@ +all: + perl ../../challenge-001/paulo-custodio/test.pl diff --git a/challenge-203/paulo-custodio/basic/ch-1.bas b/challenge-203/paulo-custodio/basic/ch-1.bas new file mode 100644 index 0000000000..bea5244b33 --- /dev/null +++ b/challenge-203/paulo-custodio/basic/ch-1.bas @@ -0,0 +1,67 @@ +' Challenge 203 +' +' Task 1: Special Quadruplets +' Submitted by: Mohammad S Anwar +' +' You are given an array of integers. +' +' Write a script to find out the total special quadruplets for the given array. +' +' Special Quadruplets are such that satisfies the following 2 rules. +' 1) nums[a] + nums[b] + nums[c] == nums[d] +' 2) a < b < c < d +' +' +' Example 1 +' +' Input: @nums = (1,2,3,6) +' Output: 1 +' +' Since the only special quadruplets found is +' $nums[0] + $nums[1] + $nums[2] == $nums[3]. +' +' Example 2 +' +' Input: @nums = (1,1,1,3,5) +' Output: 4 +' +' $nums[0] + $nums[1] + $nums[2] == $nums[3] +' $nums[0] + $nums[1] + $nums[3] == $nums[4] +' $nums[0] + $nums[2] + $nums[3] == $nums[4] +' $nums[1] + $nums[2] + $nums[3] == $nums[4] +' +' Example 3 +' +' Input: @nums = (3,3,6,4,5) +' Output: 0 + +function num_quadruplets(nums() as integer) as integer + dim count as integer, a as integer, b as integer, c as integer, d as integer + count=0 + for a=0 to ubound(nums)-3 + for b=a+1 to ubound(nums)-2 + for c=b+1 to ubound(nums)-1 + for d=c+1 to ubound(nums) + if nums(a)+nums(b)+nums(c)=nums(d) then + count=count+1 + end if + next + next + next + next + num_quadruplets=count +end function + +sub collect_args(nums() as integer) + dim i as integer + i=0 + do while command(i+1)<>"" + redim preserve nums(i) as integer + nums(i)=val(command(i+1)) + i=i+1 + loop +end sub + +dim nums() as integer +collect_args nums() +print num_quadruplets(nums()) diff --git a/challenge-203/paulo-custodio/basic/ch-2.bas b/challenge-203/paulo-custodio/basic/ch-2.bas new file mode 100644 index 0000000000..9a5efeb27e --- /dev/null +++ b/challenge-203/paulo-custodio/basic/ch-2.bas @@ -0,0 +1,82 @@ +' Challenge 203 +' +' Task 2: Copy Directory +' Submitted by: Julien Fiegehenn +' +' You are given path to two folders, $source and $target. +' +' Write a script that recursively copy the directory from $source to $target +' except any files. +' +' Example +' +' Input: $source = '/a/b/c' and $target = '/x/y' +' +' Source directory structure: +' +' ├── a +' │ └── b +' │ └── c +' │ ├── 1 +' │ │ └── 1.txt +' │ ├── 2 +' │ │ └── 2.txt +' │ ├── 3 +' │ │ └── 3.txt +' │ ├── 4 +' │ └── 5 +' │ └── 5.txt +' +' Target directory structure: +' +' ├── x +' │ └── y +' +' Expected Result: +' +' ├── x +' │ └── y +' | ├── 1 +' │ ├── 2 +' │ ├── 3 +' │ ├── 4 +' │ └── 5 + +# include "dir.bi" + +sub get_dirs(path as string, dirs() as string) + dim i as integer, d as string + i=0 + d=dir(path & "/*", fbDirectory) + do while d<>"" + if d<>"." and d<>".." then + redim preserve dirs(i) as string + dirs(i)=d + i=i+1 + end if + d=dir() + loop +end sub + +sub make_path(path as string) + dim p as integer + p=0 + do + p=instr(p+1, path, "/") + if p=0 then exit do + mkdir left(path,p-1) + loop + mkdir path +end sub + +sub copy_dirs(source as string, target as string) + dim dirs() as string, i as integer + + get_dirs source, dirs() + for i=0 to ubound(dirs) + make_path target & "/" & dirs(i) + copy_dirs source & "/" & dirs(i), target & "/" & dirs(i) + next +end sub + +copy_dirs command(1), command(2) diff --git a/challenge-203/paulo-custodio/c/ch-1.c b/challenge-203/paulo-custodio/c/ch-1.c new file mode 100644 index 0000000000..d4926a7d1a --- /dev/null +++ b/challenge-203/paulo-custodio/c/ch-1.c @@ -0,0 +1,61 @@ +/* +Challenge 203 + +Task 1: Special Quadruplets +Submitted by: Mohammad S Anwar + +You are given an array of integers. + +Write a script to find out the total special quadruplets for the given array. + +Special Quadruplets are such that satisfies the following 2 rules. +1) nums[a] + nums[b] + nums[c] == nums[d] +2) a < b < c < d + + +Example 1 + +Input: @nums = (1,2,3,6) +Output: 1 + +Since the only special quadruplets found is +$nums[0] + $nums[1] + $nums[2] == $nums[3]. + +Example 2 + +Input: @nums = (1,1,1,3,5) +Output: 4 + +$nums[0] + $nums[1] + $nums[2] == $nums[3] +$nums[0] + $nums[1] + $nums[3] == $nums[4] +$nums[0] + $nums[2] + $nums[3] == $nums[4] +$nums[1] + $nums[2] + $nums[3] == $nums[4] + +Example 3 + +Input: @nums = (3,3,6,4,5) +Output: 0 +*/ + +#include <stdio.h> +#include <stdlib.h> + +int num_quadruplets(int nums[], int nums_size) { + int count = 0; + for (int a = 0; a < nums_size - 3; a++) + for (int b = a + 1; b < nums_size - 2; b++) + for (int c = b + 1; c < nums_size - 1; c++) + for (int d = c + 1; d < nums_size; d++) + if (nums[a]+nums[b]+nums[c]==nums[d]) + count++; + return count; +} + +int main(int argc, char* argv[]) { + argv++; argc--; + int* nums = malloc(argc*sizeof(int)); + for (int i = 0; i < argc; i++) + nums[i] = atoi(argv[i]); + printf("%d\n", num_quadruplets(nums, argc)); + free(nums); +} diff --git a/challenge-203/paulo-custodio/c/ch-2.c b/challenge-203/paulo-custodio/c/ch-2.c new file mode 100644 index 0000000000..6a817bdbc2 --- /dev/null +++ b/challenge-203/paulo-custodio/c/ch-2.c @@ -0,0 +1,122 @@ +/* +Challenge 203 + +Task 2: Copy Directory +Submitted by: Julien Fiegehenn + +You are given path to two folders, $source and $target. + +Write a script that recursively copy the directory from $source to $target +except any files. + +Example + +Input: $source = '/a/b/c' and $target = '/x/y' + +Source directory structure: + +├── a +│ └── b +│ └── c +│ ├── 1 +│ │ └── 1.txt +│ ├── 2 +│ │ └── 2.txt +│ ├── 3 +│ │ └── 3.txt +│ ├── 4 +│ └── 5 +│ └── 5.txt + +Target directory structure: + +├── x +│ └── y + +Expected Result: + +├── x +│ └── y +| ├── 1 +│ ├── 2 +│ ├── 3 +│ ├── 4 +│ └── 5 +*/ + +#define MAX_PATH 1024 + +#include <assert.h> +#include <stdio.h> +#include <stdlib.h> +#include <sys/types.h> +#include <sys/stat.h> +#include <dirent.h> + +const char* cat_path(const char* dir, const char* file) { + static char path[MAX_PATH]; + assert(strlen(dir)+1+strlen(file)+1 < MAX_PATH); + + strcpy(path, dir); + strcat(path, "/"); + strcat(path, file); + return path; +} + +void os_mkdir(const char* path) { +#ifdef _WIN32 + mkdir(path); +#else + mkdir(path, 0777); +#endif +} + +void make_path(const char* path) { + char dir[MAX_PATH]; + const char* p = path; + const char* p0 = p; + + while ((p = strchr(p0, '/')) != NULL) { + strcpy(dir, path); + dir[p-path] = '\0'; + + os_mkdir(dir); + p0 = p + 1; + } + os_mkdir(path); +} + +void copy_dirs(const char* source, const char* target) { + DIR *dp; + struct dirent *ep; + dp = opendir(source); + if (dp != NULL) { + while ((ep = readdir(dp)) != NULL) { + if (strcmp(ep->d_name, ".") != 0 && strcmp(ep->d_name, "..") != 0) { + char source_file[MAX_PATH]; + strcpy(source_file, cat_path(source, ep->d_name)); + + struct stat statbuf; + if (stat(source_file, &statbuf) == 0) { + if ((statbuf.st_mode & S_IFMT) == S_IFDIR) { + char target_file[MAX_PATH]; + strcpy(target_file, cat_path(target, ep->d_name)); + + make_path(target_file); + copy_dirs(source_file, target_file); + } + } + } + } + closedir(dp); + } +} + +int main(int argc, char* argv[]) { + argv++; argc--; + if (argc != 2) + fputs("usage: ch-1 source target", stderr); + else { + copy_dirs(argv[0], argv[1]); + } +} diff --git a/challenge-203/paulo-custodio/cpp/ch-1.cpp b/challenge-203/paulo-custodio/cpp/ch-1.cpp new file mode 100644 index 0000000000..d49c659de7 --- /dev/null +++ b/challenge-203/paulo-custodio/cpp/ch-1.cpp @@ -0,0 +1,61 @@ +/* +Challenge 203 + +Task 1: Special Quadruplets +Submitted by: Mohammad S Anwar + +You are given an array of integers. + +Write a script to find out the total special quadruplets for the given array. + +Special Quadruplets are such that satisfies the following 2 rules. +1) nums[a] + nums[b] + nums[c] == nums[d] +2) a < b < c < d + + +Example 1 + +Input: @nums = (1,2,3,6) +Output: 1 + +Since the only special quadruplets found is +$nums[0] + $nums[1] + $nums[2] == $nums[3]. + +Example 2 + +Input: @nums = (1,1,1,3,5) +Output: 4 + +$nums[0] + $nums[1] + $nums[2] == $nums[3] +$nums[0] + $nums[1] + $nums[3] == $nums[4] +$nums[0] + $nums[2] + $nums[3] == $nums[4] +$nums[1] + $nums[2] + $nums[3] == $nums[4] + +Example 3 + +Input: @nums = (3,3,6,4,5) +Output: 0 +*/ + +#include <iostream> +#include <vector> + +int num_quadruplets(const std::vector<int>& nums) { + int count = 0; + if (nums.size() >= 4) + for (size_t a = 0; a < nums.size() - 3; a++) + for (size_t b = a + 1; b < nums.size() - 2; b++) + for (size_t c = b + 1; c < nums.size() - 1; c++) + for (size_t d = c + 1; d < nums.size(); d++) + if (nums[a]+nums[b]+nums[c]==nums[d]) + count++; + return count; +} + +int main(int argc, char* argv[]) { + argv++; argc--; + std::vector<int> nums; + for (int i = 0; i < argc; i++) + nums.push_back(atoi(argv[i])); + std:: cout << num_quadruplets(nums) << std::endl; +} diff --git a/challenge-203/paulo-custodio/cpp/ch-2.cpp b/challenge-203/paulo-custodio/cpp/ch-2.cpp new file mode 100644 index 0000000000..bef55b3d0d --- /dev/null +++ b/challenge-203/paulo-custodio/cpp/ch-2.cpp @@ -0,0 +1,69 @@ +/* +Challenge 203 + +Task 2: Copy Directory +Submitted by: Julien Fiegehenn + +You are given path to two folders, $source and $target. + +Write a script that recursively copy the directory from $source to $target +except any files. + +Example + +Input: $source = '/a/b/c' and $target = '/x/y' + +Source directory structure: + +├── a +│ └── b +│ └── c +│ ├── 1 +│ │ └── 1.txt +│ ├── 2 +│ │ └── 2.txt +│ ├── 3 +│ │ └── 3.txt +│ ├── 4 +│ └── 5 +│ └── 5.txt + +Target directory structure: + +├── x +│ └── y + +Expected Result: + +├── x +│ └── y +| ├── 1 +│ ├── 2 +│ ├── 3 +│ ├── 4 +│ └── 5 +*/ + +#include <iostream> +#include <filesystem> + +namespace fs = std::filesystem; + +void copy_dirs(const fs::path& source, const fs::path& target) { + for (auto& dir_entry : fs::directory_iterator(source)) { + if (dir_entry.is_directory()) { + fs::path target_dir = target / dir_entry.path().filename(); + fs::create_directories(target_dir); + copy_dirs(dir_entry, target_dir); + } + } +} + +int main(int argc, char* argv[]) { + argv++; argc--; + if (argc != 2) + std::cerr << "usage: ch-1 source target" << std::endl; + else { + copy_dirs(fs::path(argv[0]), fs::path(argv[1])); + } +} diff --git a/challenge-203/paulo-custodio/forth/ch-1.fs b/challenge-203/paulo-custodio/forth/ch-1.fs new file mode 100644 index 0000000000..1e91b0e685 --- /dev/null +++ b/challenge-203/paulo-custodio/forth/ch-1.fs @@ -0,0 +1,81 @@ +#! /usr/bin/env gforth + +\ Challenge 203 +\ +\ Task 1: Special Quadruplets +\ Submitted by: Mohammad S Anwar +\ +\ You are given an array of integers. +\ +\ Write a script to find out the total special quadruplets for the given array. +\ +\ Special Quadruplets are such that satisfies the following 2 rules. +\ 1) nums[a] + nums[b] + nums[c] == nums[d] +\ 2) a < b < c < d +\ +\ +\ Example 1 +\ +\ Input: @nums = (1,2,3,6) +\ Output: 1 +\ +\ Since the only special quadruplets found is +\ $nums[0] + $nums[1] + $nums[2] == $nums[3]. +\ +\ Example 2 +\ +\ Input: @nums = (1,1,1,3,5) +\ Output: 4 +\ +\ $nums[0] + $nums[1] + $nums[2] == $nums[3] +\ $nums[0] + $nums[1] + $nums[3] == $nums[4] +\ $nums[0] + $nums[2] + $nums[3] == $nums[4] +\ $nums[1] + $nums[2] + $nums[3] == $nums[4] +\ +\ Example 3 +\ +\ Input: @nums = (3,3,6,4,5) +\ Output: 0 + +CREATE nums 256 CELLS ALLOT +0 VALUE nums_size + +: nums[] ( i -- addr ) + CELLS nums + +; + +: collect_args ( -- ) + BEGIN NEXT-ARG DUP WHILE + 0 0 2SWAP >NUMBER 2DROP DROP + nums_size nums[] ! + nums_size 1+ TO nums_size + REPEAT + 2DROP +; + +: num_quadruplets ( -- n ) + 0 0 0 0 { a b c d } + 0 ( count ) + 0 TO a + BEGIN a nums_size 3 - < WHILE + a 1+ TO b + BEGIN b nums_size 2 - < WHILE + b 1+ TO c + BEGIN c nums_size 1- < WHILE + c 1+ TO d + BEGIN d nums_size < WHILE + a nums[] @ b nums[] @ + c nums[] @ + d nums[] @ = IF + 1+ + THEN + d 1+ to d + REPEAT + c 1+ TO c + REPEAT + b 1+ TO b + REPEAT + a 1+ TO a + REPEAT +; + +collect_args num_quadruplets . CR +BYE diff --git a/challenge-203/paulo-custodio/forth/ch-2.fs b/challenge-203/paulo-custodio/forth/ch-2.fs new file mode 100644 index 0000000000..d5a78799b1 --- /dev/null +++ b/challenge-203/paulo-custodio/forth/ch-2.fs @@ -0,0 +1,114 @@ +#! /usr/bin/env gforth + +\ Challenge 203 +\ +\ Task 2: Copy Directory +\ Submitted by: Julien Fiegehenn +\ +\ You are given path to two folders, $source and $target. +\ +\ Write a script that recursively copy the directory from $source to $target +\ except any files. +\ +\ Example +\ +\ Input: $source = '/a/b/c' and $target = '/x/y' +\ +\ Source directory structure: +\ +\ ├── a +\ │ └── b +\ │ └── c +\ │ ├── 1 +\ │ │ └── 1.txt +\ │ ├── 2 +\ │ │ └── 2.txt +\ │ ├── 3 +\ │ │ └── 3.txt +\ │ ├── 4 +\ │ └── 5 +\ │ └── 5.txt +\ +\ Target directory structure: +\ +\ ├── x +\ │ └── y +\ +\ Expected Result: +\ +\ ├── x +\ │ └── y +\ | ├── 1 +\ │ ├── 2 +\ │ ├── 3 +\ │ ├── 4 +\ │ └── 5 + +\ copy text to counted string +: copy_text { addr-from len addr-to -- } + addr-from addr-to 1+ len CMOVE + len addr-to C! +; + +\ append text to counted string +: cat_text { addr-cstr addr-from len-from -- } + addr-from addr-cstr COUNT + len-from CMOVE + addr-cstr C@ len-from + addr-cstr C! +; + +\ concat two paths +: cat_paths { target addr-path1 len-path1 addr-path2 len-path2 -- } + 0 target C! + target addr-path1 len-path1 cat_text + target S" /" cat_text + target addr-path2 len-path2 cat_text +; + +: is_dot_dot_dot { cstr -- f } + cstr COUNT S" ." COMPARE 0= + cstr COUNT S" .." COMPARE 0= OR +; + +: is_dir { cstr -- f } + cstr COUNT OPEN-DIR 0= IF \ ok + CLOSE-DIR THROW + TRUE + ELSE + DROP + FALSE + THEN +; + +\ copy dirs +: copy_dirs { source-addr target-addr -- } + source-addr COUNT OPEN-DIR THROW { dirid } + 256 ALLOCATE THROW { fname } + BEGIN fname 1+ 255 dirid READ-DIR THROW WHILE + fname C! + fname is_dot_dot_dot 0= IF + 256 ALLOCATE THROW { source-file } + source-file source-addr COUNT fname COUNT cat_paths + + 256 ALLOCATE THROW { target-file } + target-file target-addr COUNT fname COUNT cat_paths + + source-file is_dir IF + target-file COUNT [ 8 BASE ! 777 DECIMAL ] LITERAL + MKDIR-PARENTS THROW + THEN + + source-file FREE THROW + target-file FREE THROW + THEN + REPEAT + fname FREE THROW +; + +\ file names +CREATE source_dir 256 ALLOT +CREATE target_dir 256 ALLOT + +NEXT-ARG DUP 0= THROW source_dir copy_text +NEXT-ARG DUP 0= THROW target_dir copy_text +source_dir target_dir copy_dirs +BYE diff --git a/challenge-203/paulo-custodio/perl/ch-1.pl b/challenge-203/paulo-custodio/perl/ch-1.pl new file mode 100644 index 0000000000..053b82ffde --- /dev/null +++ b/challenge-203/paulo-custodio/perl/ch-1.pl @@ -0,0 +1,59 @@ +#!/usr/bin/perl + +# Challenge 203 +# +# Task 1: Special Quadruplets +# Submitted by: Mohammad S Anwar +# +# You are given an array of integers. +# +# Write a script to find out the total special quadruplets for the given array. +# +# Special Quadruplets are such that satisfies the following 2 rules. +# 1) nums[a] + nums[b] + nums[c] == nums[d] +# 2) a < b < c < d +# +# +# Example 1 +# +# Input: @nums = (1,2,3,6) +# Output: 1 +# +# Since the only special quadruplets found is +# $nums[0] + $nums[1] + $nums[2] == $nums[3]. +# +# Example 2 +# +# Input: @nums = (1,1,1,3,5) +# Output: 4 +# +# $nums[0] + $nums[1] + $nums[2] == $nums[3] +# $nums[0] + $nums[1] + $nums[3] == $nums[4] +# $nums[0] + $nums[2] + $nums[3] == $nums[4] +# $nums[1] + $nums[2] + $nums[3] == $nums[4] +# +# Example 3 +# +# Input: @nums = (3,3,6,4,5) +# Output: 0 + +use Modern::Perl; + +sub num_quadruplets { + my(@nums) = @_; + my $count = 0; + for my $a (0..$#nums-3) { + for my $b ($a+1..$#nums-2) { + for my $c ($b+1..$#nums-1) { + for my $d ($c+1..$#nums) { + if ($nums[$a]+$nums[$b]+$nums[$c]==$nums[$d]) { + $count++; + } + } + } + } + } + return $count; +} + +say num_quadruplets(@ARGV); diff --git a/challenge-203/paulo-custodio/perl/ch-2.pl b/challenge-203/paulo-custodio/perl/ch-2.pl new file mode 100644 index 0000000000..7c6ae8e339 --- /dev/null +++ b/challenge-203/paulo-custodio/perl/ch-2.pl @@ -0,0 +1,63 @@ +#!/usr/bin/perl + +# Challenge 203 +# +# Task 2: Copy Directory +# Submitted by: Julien Fiegehenn +# +# You are given path to two folders, $source and $target. +# +# Write a script that recursively copy the directory from $source to $target +# except any files. +# +# Example +# +# Input: $source = '/a/b/c' and $target = '/x/y' +# +# Source directory structure: +# +# ├── a +# │ └── b +# │ └── c +# │ ├── 1 +# │ │ └── 1.txt +# │ ├── 2 +# │ │ └── 2.txt +# │ ├── 3 +# │ │ └── 3.txt +# │ ├── 4 +# │ └── 5 +# │ └── 5.txt +# +# Target directory structure: +# +# ├── x +# │ └── y +# +# Expected Result: +# +# ├── x +# │ └── y +# | ├── 1 +# │ ├── 2 +# │ ├── 3 +# │ ├── 4 +# │ └── 5 + +use Modern::Perl; +use File::Find; +use Path::Tiny; + +sub copy_dirs { + my($source, $target) = @_; + my @dirs; + find(sub { + return unless -d $_; + (my $path = $File::Find::name) =~ s/^$source/$target/; + push @dirs, $path; + }, $source); + path($_)->mkpath for @dirs; +} + +@ARGV==2 or die "usage: ch-2.pl source target\n"; +copy_dirs(@ARGV); diff --git a/challenge-203/paulo-custodio/t/test-1.yaml b/challenge-203/paulo-custodio/t/test-1.yaml new file mode 100644 index 0000000000..ba74c95188 --- /dev/null +++ b/challenge-203/paulo-custodio/t/test-1.yaml @@ -0,0 +1,15 @@ +- setup: + cleanup: + args: 1 2 3 6 + input: + output: 1 +- setup: + cleanup: + args: 1 1 1 3 5 + input: + output: 4 +- setup: + cleanup: + args: 1 1 1 1 + input: + output: 0 diff --git a/challenge-203/paulo-custodio/t/test-2.yaml b/challenge-203/paulo-custodio/t/test-2.yaml new file mode 100644 index 0000000000..9db434b269 --- /dev/null +++ b/challenge-203/paulo-custodio/t/test-2.yaml @@ -0,0 +1,5 @@ +- setup: 0==system("mkdir -p a/b/c/1 a/b/c/2 a/b/c/3 a/b/c/4 a/b/c/5") && 0==system("touch a/b/c/1/1.txt a/b/c/2/2.txt a/b/c/3/3.txt a/b/c/5/5.txt") + cleanup: -d "x/y/1" && -d "x/y/2" && -d "x/y/3" && -d "x/y/4" && -d "x/y/5" && ! -f "x/y/1/1.txt" && ! -f "x/y/2/2.txt" && ! -f "x/y/3/3.txt" && ! -f "x/y/5/5.txt" && 0==system("rm -rf a x") + args: a/b/c x/y + input: + output: diff --git a/challenge-207/paulo-custodio/Makefile b/challenge-207/paulo-custodio/Makefile new file mode 100644 index 0000000000..c3c762d746 --- /dev/null +++ b/challenge-207/paulo-custodio/Makefile @@ -0,0 +1,2 @@ +all: + perl ../../challenge-001/paulo-custodio/test.pl diff --git a/challenge-207/paulo-custodio/basic/ch-1.bas b/challenge-207/paulo-custodio/basic/ch-1.bas new file mode 100644 index 0000000000..d5f8593713 --- /dev/null +++ b/challenge-207/paulo-custodio/basic/ch-1.bas @@ -0,0 +1,59 @@ +' Challenge 207 +' +' Task 1: Keyboard Word +' Submitted by: Mohammad S Anwar +' +' You are given an array of words. +' +' Write a script to print all the words in the given array that can be types +' using alphabet on only one row of the keyboard. +' +' Let us assume the keys are arranged as below: +' +' Row 1: qwertyuiop +' Row 2: asdfghjkl +' Row 3: zxcvbnm +' +' Example 1 +' +' Input: @words = ("Hello","Alaska","Dad","Peace") +' Output: ("Alaska","Dad") +' +' Example 2 +' +' Input: @array = ("OMG","Bye") +' Output: () + +function remove_char(byval s as string, c as string) as string + dim p as integer + + p=instr(s,c) + do while p>0 + s=left(s,p-1)+mid(s,p+1) + p=instr(s,c) + loop + remove_char=s +end function + +function can_type_word(k as string, byval s as string) as boolean + dim i as integer + for i=1 to len(k) + s=remove_char(s,mid(k,i,1)) + next + can_type_word=s="" +end function + +function can_type(s as string) as boolean + s=lcase(s) + can_type=can_type_word("qwertyuiop",s) or _ + can_type_word("asdfghjkl",s) or _ + can_type_word("zxcvbnm",s) +end function + +dim i as integer +i=1 +do while command(i)<>"" + if can_type(command(i)) then print command(i);" "; + i=i+1 +loop +print diff --git a/challenge-207/paulo-custodio/basic/ch-2.bas b/challenge-207/paulo-custodio/basic/ch-2.bas new file mode 100644 index 0000000000..2e2dfae944 --- /dev/null +++ b/challenge-207/paulo-custodio/basic/ch-2.bas @@ -0,0 +1,70 @@ +' Challenge 207 +' +' Task 2: H-Index +' Submitted by: Mohammad S Anwar +' +' You are given an array of integers containing citations a researc |
