diff options
| author | Mohammad S Anwar <Mohammad.Anwar@yahoo.com> | 2023-04-03 00:49:44 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-04-03 00:49:44 +0100 |
| commit | aa5176240d16eb4742e8a527923b0b30ffa35b5f (patch) | |
| tree | c4fc76b765210032b36077b4ac2d61845f5f9dd3 | |
| parent | 468a1ad1c1c305b0e602644a3562b319c9dfde3e (diff) | |
| parent | a07ac0ca20938228084ca317d1961365373ded29 (diff) | |
| download | perlweeklychallenge-club-aa5176240d16eb4742e8a527923b0b30ffa35b5f.tar.gz perlweeklychallenge-club-aa5176240d16eb4742e8a527923b0b30ffa35b5f.tar.bz2 perlweeklychallenge-club-aa5176240d16eb4742e8a527923b0b30ffa35b5f.zip | |
Merge pull request #7827 from spadacciniweb/PWC-210
PWC-210
| -rw-r--r-- | challenge-210/spadacciniweb/go/ch-1.go | 47 | ||||
| -rw-r--r-- | challenge-210/spadacciniweb/perl/ch-1.pl | 33 | ||||
| -rw-r--r-- | challenge-210/spadacciniweb/python/ch-1.py | 33 | ||||
| -rw-r--r-- | challenge-210/spadacciniweb/ruby/ch-1.rb | 36 |
4 files changed, 149 insertions, 0 deletions
diff --git a/challenge-210/spadacciniweb/go/ch-1.go b/challenge-210/spadacciniweb/go/ch-1.go new file mode 100644 index 0000000000..128566a5e8 --- /dev/null +++ b/challenge-210/spadacciniweb/go/ch-1.go @@ -0,0 +1,47 @@ +/* +Task 1: Kill and Win +Submitted by: Mohammad S Anwar + +You are given a list of integers. +Write a script to get the maximum points. You are allowed to take out (kill) any integer and remove from the list. However if you do that then all integers exactly one-less or one-more would also be removed. Find out the total of integers removed. + +Example 1 +Input: @int = (2, 3, 1) +Output: 6 + +First we delete 2 and that would also delete 1 and 3. So the maximum points we get is 6. + +Example 2 +Input: @int = (1, 1, 2, 2, 2, 3) +Output: 11 + +First we delete 2 and that would also delete both the 1's and the 3. Now we have (2, 2). +Then we delete another 2 and followed by the third deletion of 2. So the maximum points we get is 11. +*/ + +package main + +import ( + "fmt" + "log" + "os" + "strconv" +) + +func main() { + arrStr := os.Args[1:] + if (len(arrStr) < 1) { + log.Fatal("input error") + } + + var tot int = 0 + for i := 0; i <= len(arrStr)-1; i++ { + value, err := strconv.Atoi(arrStr[i]) + if (err != nil) { + log.Fatal(err) + } + tot += value + } + + fmt.Printf("Output: %d\n",tot) +} diff --git a/challenge-210/spadacciniweb/perl/ch-1.pl b/challenge-210/spadacciniweb/perl/ch-1.pl new file mode 100644 index 0000000000..b308906e0f --- /dev/null +++ b/challenge-210/spadacciniweb/perl/ch-1.pl @@ -0,0 +1,33 @@ +#!/usr/bin/env perl + +# Task 1: Kill and Win +# Submitted by: Mohammad S Anwar +# +# You are given a list of integers. +# Write a script to get the maximum points. You are allowed to take out (kill) any integer and remove from the list. However if you do that then all integers exactly one-less or one-more would also be removed. Find out the total of integers removed. +# +# Example 1 +# Input: @int = (2, 3, 1) +# Output: 6 +# +# First we delete 2 and that would also delete 1 and 3. So the maximum points we get is 6. +# +# Example 2 +# Input: @int = (1, 1, 2, 2, 2, 3) +# Output: 11 +# +# First we delete 2 and that would also delete both the 1's and the 3. Now we have (2, 2). +# Then we delete another 2 and followed by the third deletion of 2. So the maximum points we get is 11. + +use strict; +use warnings; +use List::Util qw(sum); + +my @input = @ARGV; +die "Input error\n" + if scalar @input < 1 + or + (scalar map { $_ =~ /\D/ ? 1 : () } + @input) != 0; + +printf "%d\n", sum @input; diff --git a/challenge-210/spadacciniweb/python/ch-1.py b/challenge-210/spadacciniweb/python/ch-1.py new file mode 100644 index 0000000000..6503dc43ea --- /dev/null +++ b/challenge-210/spadacciniweb/python/ch-1.py @@ -0,0 +1,33 @@ +# Task 1: Kill and Win +# Submitted by: Mohammad S Anwar +# +# You are given a list of integers. +# +# Write a script to get the maximum points. You are allowed to take out (kill) any integer and remove from the list. However if you do that then all integers exactly one-less or one-more would also be removed. Find out the total of integers removed. +# +# Example 1 +# Input: @int = (2, 3, 1) +# Output: 6 +# +# First we delete 2 and that would also delete 1 and 3. So the maximum points we get is 6. +# +# Example 2 +# Input: @int = (1, 1, 2, 2, 2, 3) +# Output: 11 +# +# First we delete 2 and that would also delete both the 1's and the 3. Now we have (2, 2). +# Then we delete another 2 and followed by the third deletion of 2. So the maximum points we get is 11. + +import re +import sys + +if __name__ == "__main__": + input = sys.argv[1:] + if (len(input) < 1 + or + len(list(filter(lambda x: re.search(r'\D', x), input))) != 0): + sys.exit("Input error\n") + + input = list(map(int, input)) + print(sum(input)) + diff --git a/challenge-210/spadacciniweb/ruby/ch-1.rb b/challenge-210/spadacciniweb/ruby/ch-1.rb new file mode 100644 index 0000000000..7d14beda74 --- /dev/null +++ b/challenge-210/spadacciniweb/ruby/ch-1.rb @@ -0,0 +1,36 @@ +# Task 1: Kill and Win +# Submitted by: Mohammad S Anwar +# +# You are given a list of integers. +# +# Write a script to get the maximum points. You are allowed to take out (kill) any integer and remove from the list. However if you do that then all integers exactly one-less or one-more would also be removed. Find out the total of integers removed. +# +# Example 1 +# Input: @int = (2, 3, 1) +# Output: 6 +# +# First we delete 2 and that would also delete 1 and 3. So the maximum points we get is 6. +# +# Example 2 +# Input: @int = (1, 1, 2, 2, 2, 3) +# Output: 11 +# +# First we delete 2 and that would also delete both the 1's and the 3. Now we have (2, 2). +# Then we delete another 2 and followed by the third deletion of 2. So the maximum points we get is 11. + +def main(input) + if input.length < 1 \ + or \ + input.select{ |i| i[/\D/] }.length > 0 + then + puts "Input error" + exit(0) + end + + sum = 0 + input.each { |i| sum += i.to_i } + puts sum + +end + +main ARGV |
