diff options
| author | Mohammad S Anwar <mohammad.anwar@yahoo.com> | 2022-12-27 13:35:57 +0000 |
|---|---|---|
| committer | Mohammad S Anwar <mohammad.anwar@yahoo.com> | 2022-12-27 13:35:57 +0000 |
| commit | 99783e7acaa3e8d3ac1a8564c69fac08ba45b080 (patch) | |
| tree | 0f59d67140d1a899296359c23320b349d8cffc73 /challenge-197 | |
| parent | 92ecd89aa4e88ab95c7b38c8d09b6f6a29856d7e (diff) | |
| download | perlweeklychallenge-club-99783e7acaa3e8d3ac1a8564c69fac08ba45b080.tar.gz perlweeklychallenge-club-99783e7acaa3e8d3ac1a8564c69fac08ba45b080.tar.bz2 perlweeklychallenge-club-99783e7acaa3e8d3ac1a8564c69fac08ba45b080.zip | |
- Added solutions by Feng Chang.
- Added blog post by Roger Bell_West.
- Added solutions by Mark Anderson.
- Added solutions by Thomas Kohler.
- Added solutions by David Ferrone.
- Added solutions by W. Luis Mochan.
- Added solutions by Carlos Oliveira.
- Added solutions by Robbie Hatley.
- Added solutions by Luca Ferrari.
- Added solutions by Stephen G. Lynn.
- Added solutions by Robert DiCicco.
Diffstat (limited to 'challenge-197')
| -rw-r--r-- | challenge-197/robert-dicicco/julia/ch-1.jl | 77 | ||||
| -rw-r--r-- | challenge-197/robert-dicicco/perl/ch-1.pl | 85 | ||||
| -rw-r--r-- | challenge-197/robert-dicicco/python/ch-1.py | 77 | ||||
| -rw-r--r-- | challenge-197/robert-dicicco/raku/ch-1.raku | 81 | ||||
| -rw-r--r-- | challenge-197/robert-dicicco/ruby/ch-1.rb | 79 | ||||
| -rw-r--r-- | challenge-197/ziameraj16/java/MoveZero.java | 22 |
6 files changed, 421 insertions, 0 deletions
diff --git a/challenge-197/robert-dicicco/julia/ch-1.jl b/challenge-197/robert-dicicco/julia/ch-1.jl new file mode 100644 index 0000000000..17a17ebe38 --- /dev/null +++ b/challenge-197/robert-dicicco/julia/ch-1.jl @@ -0,0 +1,77 @@ +#!/usr/bin/env julia + +#= + +AUTHOR: Robert DiCicco + +DATE : 2022-12-26 + +Challenge 197 Move Zero ( Julia ) + +=# + +using Printf + + + +lists = [[1, 0, 3, 0, 0, 5],[1, 6, 4],[0, 1, 0, 2, 0]] + + + +for list in lists + + i = 1 + + left = Int64[] + + right = Int64[] + + @printf("Input: @list = %s\n", list) + + while i <= length(list) + + if list[i] > 0 + + push!(left,list[i]) + + else + + push!(right, list[i]) + + end + + i += 1 + + end + + println("Output: ", cat(left,right,dims=1),"\n") + +end + + + +#= + +----------------------------------------------------- + +SAMPLE OUTPUT + +julia .\MoveZero.jl + +Input: @list = [1, 0, 3, 0, 0, 5] + +Output: [1, 3, 5, 0, 0, 0] + + + +Input: @list = [1, 6, 4] + +Output: [1, 6, 4] + + + +Input: @list = [0, 1, 0, 2, 0] + +Output: [1, 2, 0, 0, 0] + +=# diff --git a/challenge-197/robert-dicicco/perl/ch-1.pl b/challenge-197/robert-dicicco/perl/ch-1.pl new file mode 100644 index 0000000000..b3f1c32eb3 --- /dev/null +++ b/challenge-197/robert-dicicco/perl/ch-1.pl @@ -0,0 +1,85 @@ +#!/usr/bin/env perl + +=begin + +AUTHOR: Robert DiCicco + +DATE : 2022-12-26 + +Challenge 197 Move Zero ( Perl ) + +=cut + +use strict; + +use warnings; + +use feature qw/say/; + + + +my @lists = ([1, 0, 3, 0, 0, 5],[1, 6, 4],[0, 1, 0, 2, 0]); + + + +for my $list (@lists) { + + my $i = 0; + + my @left = (); + + my @right = (); + + print("Input: \@list = \(@$list\) \n"); + + while($i < scalar @$list){ + + if ($list->[$i] > 0){ + + push(@left, $list->[$i]); + + } else { + + push(@right, $list->[$i]); + + } + + $i++; + + } + + print("Output: "); + + say ("(@left @right)"); + + print("\n"); + +} + +=begin + +-------------------------------------------------- + +SAMPLE OUTPUT + + + +perl MoveZero.pl + +Input: @list = (1 0 3 0 0 5) + +Output: (1 3 5 0 0 0) + + + +Input: @list = (1 6 4) + +Output: (1 6 4 ) + + + +Input: @list = (0 1 0 2 0) + +Output: (1 2 0 0 0) + +=cut diff --git a/challenge-197/robert-dicicco/python/ch-1.py b/challenge-197/robert-dicicco/python/ch-1.py new file mode 100644 index 0000000000..d44a1a07ec --- /dev/null +++ b/challenge-197/robert-dicicco/python/ch-1.py @@ -0,0 +1,77 @@ +#!/usr/bin/env python + +''' + +AUTHOR: Robert DiCicco + +DATE : 2022-12-26 + +Challenge 197 Move Zero ( Python ) + +''' + +import array + + + +lists = [[1, 0, 3, 0, 0, 5],[1, 6, 4],[0, 1, 0, 2, 0]] + + + + + +for list in lists: + + i = 0 + + left = [] + + right = [] + + out = [] + + print(f"Input: @list = {list}") + + while i < len(list): + + if list[i] > 0: + + left.append(list[i]) + + else: + + right.append(list[i]) + + i += 1 + + out = left + right + + print(f"Output: {out}\n") + + + +''' + +----------------------------------------------- + +SAMPLE OUTPUT + +python .\MoveZero.py + +Input: @list = [1, 0, 3, 0, 0, 5] + +Output: [1, 3, 5, 0, 0, 0] + + + +Input: @list = [1, 6, 4] + +Output: [1, 6, 4] + + + +Input: @list = [0, 1, 0, 2, 0] + +Output: [1, 2, 0, 0, 0] + +''' diff --git a/challenge-197/robert-dicicco/raku/ch-1.raku b/challenge-197/robert-dicicco/raku/ch-1.raku new file mode 100644 index 0000000000..ee55ba61a8 --- /dev/null +++ b/challenge-197/robert-dicicco/raku/ch-1.raku @@ -0,0 +1,81 @@ +#!/usr/bin/env raku + +#`{ + +AUTHOR: Robert DiCicco + +DATE : 2022-12-26 + +Challenge 197 Move Zero ( Raku ) + +} + + + +use v6; + + + +my @lists = ([1, 0, 3, 0, 0, 5],[1, 6, 4],[0, 1, 0, 2, 0]); + + + +for (@lists) -> @list { + + my $i = 0; + + my @left = (); + + my @right = (); + + print("Input: \@list = \(" ~ @list ~ "\) \n"); + + while $i < @list.elems { + + if @list[$i] > 0 { + + @left.push: @list[$i]; + + } else { + + @right.push: @list[$i]; + + } + + + + $i++; + + } + + print("Output: (",@left," ",@right,")\n\n"); + +} + + + +#`{ + +-------------------------------------------------------- + +SAMPLE OUTPUT + +raku MoveZero.rk + +Input: @list = (1 0 3 0 0 5) + +Output: (1 3 5 0 0 0) + + + +Input: @list = (1 6 4) + +Output: (1 6 4 ) + + + +Input: @list = (0 1 0 2 0) + +Output: (1 2 0 0 0) + +} diff --git a/challenge-197/robert-dicicco/ruby/ch-1.rb b/challenge-197/robert-dicicco/ruby/ch-1.rb new file mode 100644 index 0000000000..9c926d5c5c --- /dev/null +++ b/challenge-197/robert-dicicco/ruby/ch-1.rb @@ -0,0 +1,79 @@ +#!/usr/bin/env ruby + +=begin + +AUTHOR: Robert DiCicco + +DATE : 2022-12-26 + +Challenge 197 Move Zero ( Ruby ) + +=end + + + + + +lists = [[1, 0, 3, 0, 0, 5],[1, 6, 4],[0, 1, 0, 2, 0]] + + + +lists.each do |list| + + i = 0 + + left = [] + + right = [] + + printf("Input: @list = %s\n",list) + + while i < list.length() + + if list[i] > 0 + + left.push(list[i]) + + else + + right.push(list[i]) + + end + + i += 1 + + end + + out = left + right + + puts("Output: (#{out}\n\n") + +end + + + +=begin + +------------------------------------------------------- + +SAMPLE OUTPUT + +ruby .\MoveZero.rb + +Input: @list = [1, 0, 3, 0, 0, 5] + +Output: ([1, 3, 5, 0, 0, 0] + + + +Input: @list = [1, 6, 4] + +Output: ([1, 6, 4] + + + +Input: @list = [0, 1, 0, 2, 0] + +Output: ([1, 2, 0, 0, 0] + +=end diff --git a/challenge-197/ziameraj16/java/MoveZero.java b/challenge-197/ziameraj16/java/MoveZero.java new file mode 100644 index 0000000000..8201dc2769 --- /dev/null +++ b/challenge-197/ziameraj16/java/MoveZero.java @@ -0,0 +1,22 @@ +import java.util.*; +import java.util.stream.Collectors; + +public class MoveZero { + + public static void main(String[] args) { + Scanner scanner = new Scanner(System.in); + System.out.println("Enter comma separated values"); + List<Integer> list = Arrays.stream(scanner.nextLine().split(",")).map(Integer::valueOf).collect(Collectors.toList()); + List<Integer> nonZeros = new ArrayList(); + List<Integer> zeros = new ArrayList(); + list.stream().forEach(integer -> { + if (integer == 0) { + zeros.add(0); + } else { + nonZeros.add(integer); + } + }); + nonZeros.addAll(zeros); + System.out.println(nonZeros); + } +} |
