aboutsummaryrefslogtreecommitdiff
path: root/challenge-198
diff options
context:
space:
mode:
authorMohammad S Anwar <mohammad.anwar@yahoo.com>2023-01-02 21:03:27 +0000
committerMohammad S Anwar <mohammad.anwar@yahoo.com>2023-01-02 21:03:27 +0000
commit79335458f4f82deed9d4caca0f563fd7adfbb276 (patch)
tree9f22b050ef42f61cdef338bd3d4ff455f71e5128 /challenge-198
parent00cc4d779f1fdbdd6a22b1c029f2fbdc857ff132 (diff)
downloadperlweeklychallenge-club-79335458f4f82deed9d4caca0f563fd7adfbb276.tar.gz
perlweeklychallenge-club-79335458f4f82deed9d4caca0f563fd7adfbb276.tar.bz2
perlweeklychallenge-club-79335458f4f82deed9d4caca0f563fd7adfbb276.zip
- Added solutions by Robert DiCicco.
Diffstat (limited to 'challenge-198')
-rw-r--r--challenge-198/robert-dicicco/julia/ch-2.jl69
-rw-r--r--challenge-198/robert-dicicco/perl/ch-2.pl75
-rw-r--r--challenge-198/robert-dicicco/python/ch-2.py81
-rw-r--r--challenge-198/robert-dicicco/raku/ch-2.raku65
-rw-r--r--challenge-198/robert-dicicco/ruby/ch-2.rb73
-rw-r--r--challenge-198/ziameraj16/java/PrimeCount.java37
6 files changed, 400 insertions, 0 deletions
diff --git a/challenge-198/robert-dicicco/julia/ch-2.jl b/challenge-198/robert-dicicco/julia/ch-2.jl
new file mode 100644
index 0000000000..01b5fcc756
--- /dev/null
+++ b/challenge-198/robert-dicicco/julia/ch-2.jl
@@ -0,0 +1,69 @@
+#!/usr/bin/env julia
+
+#=
+
+AUTHOR: Robert DiCicco
+
+DATE : 2023-01-02
+
+Challenge 198 Prime Count ( Julia )
+
+=#
+
+using Printf
+
+using Primes
+
+
+arr = [10,15,1,25]
+
+
+for n in arr
+
+ cnt = 0
+
+ @printf("Input: \$n = %d\n",n)
+
+ for x in 1:n
+
+ if isprime(x)
+
+ cnt += 1
+
+ end
+
+ end
+
+ @printf("Output: %d\n\n",cnt)
+
+end
+
+#=
+
+julia .\PrimeCount.jl
+
+Input: $n = 10
+
+Output: 4
+
+
+Input: $n = 15
+
+Output: 6
+
+
+Input: $n = 1
+
+Output: 0
+
+
+Input: $n = 25
+
+Output: 9
+
+=#
diff --git a/challenge-198/robert-dicicco/perl/ch-2.pl b/challenge-198/robert-dicicco/perl/ch-2.pl
new file mode 100644
index 0000000000..d45956061a
--- /dev/null
+++ b/challenge-198/robert-dicicco/perl/ch-2.pl
@@ -0,0 +1,75 @@
+#!/usr/bin/env perl
+
+=begin
+
+AUTHOR: Robert DiCicco
+
+DATE : 2023-01-02
+
+Challenge 198 Prime Count ( Perl )
+
+=cut
+
+use strict;
+
+use warnings;
+
+use feature qw/say/;
+
+use ntheory qw/is_prime/;
+
+
+my @arr = (10,15,1,25);
+
+
+for my $x (0..scalar(@arr)-1) {
+
+ my $cnt = 0;
+
+ print "Input: \$n = $arr[$x]\n"; # find primes less than @arr[$x]
+
+ for my $n (0..$arr[$x]){
+
+ if(is_prime($n)) {
+
+ $cnt++;
+
+ }
+
+ }
+
+ print "Output: $cnt\n\n";
+
+}
+
+
+=begin
+
+perl .\PrimeCount.pl
+
+Input: $n = 10
+
+Output: 4
+
+
+Input: $n = 15
+
+Output: 6
+
+
+Input: $n = 1
+
+Output: 0
+
+
+Input: $n = 25
+
+Output: 9
+
+=cut
diff --git a/challenge-198/robert-dicicco/python/ch-2.py b/challenge-198/robert-dicicco/python/ch-2.py
new file mode 100644
index 0000000000..71d5718b18
--- /dev/null
+++ b/challenge-198/robert-dicicco/python/ch-2.py
@@ -0,0 +1,81 @@
+#!/usr/bin/env python
+
+'''
+
+AUTHOR: Robert DiCicco
+
+DATE : 2023-01-02
+
+Challenge 198 Prime Count ( Python )
+
+'''
+
+
+arr = [10,15,1,25]
+
+
+def isprime(num):
+
+ if num > 1: 
+
+        for n in range(2,num): 
+
+            if (num % n) == 0: 
+
+                return False
+
+ return True
+
+ else:
+
+ return False
+
+
+for n in arr:
+
+ cnt = 0
+
+ print(f"Input: $n = {n}")
+
+ for x in range(n):
+
+ if isprime(x):
+
+ #rint(x)
+
+ cnt += 1
+
+ print(f"Output: {cnt}\n")
+
+   
+
+'''
+
+python .\PrimeCount.py
+
+Input: $n = 10
+
+Output: 4
+
+
+Input: $n = 15
+
+Output: 6
+
+
+Input: $n = 1
+
+Output: 0
+
+
+Input: $n = 25
+
+Output: 9
+
+'''
diff --git a/challenge-198/robert-dicicco/raku/ch-2.raku b/challenge-198/robert-dicicco/raku/ch-2.raku
new file mode 100644
index 0000000000..fdda9118f9
--- /dev/null
+++ b/challenge-198/robert-dicicco/raku/ch-2.raku
@@ -0,0 +1,65 @@
+#!/usr/bin/env raku
+
+#`{
+
+AUTHOR: Robert DiCicco
+
+DATE : 2023-01-02
+
+Challenge 198 Prime Count ( Raku )
+
+}
+
+
+my @arr = [10,15,1,25];
+
+
+for (@arr) -> $n {
+
+ my $cnt = 0;
+
+ print "Input: \$n = $n\n"; # find primes less than @arr[$n]
+
+ for (0 .. $n - 1) -> $x {
+
+ if $x.is-prime {
+
+ $cnt++;
+
+ }
+
+ }
+
+ print "Output: $cnt\n\n";
+
+}
+
+#`{
+
+raku .\PrimeCount.rk
+
+Input: $n = 10
+
+Output: 4
+
+
+Input: $n = 15
+
+Output: 6
+
+
+Input: $n = 1
+
+Output: 0
+
+
+Input: $n = 25
+
+Output: 9
+
+}
diff --git a/challenge-198/robert-dicicco/ruby/ch-2.rb b/challenge-198/robert-dicicco/ruby/ch-2.rb
new file mode 100644
index 0000000000..81b9fb45a5
--- /dev/null
+++ b/challenge-198/robert-dicicco/ruby/ch-2.rb
@@ -0,0 +1,73 @@
+#!/usr/bin/env ruby
+
+=begin
+
+AUTHOR: Robert DiCicco
+
+DATE : 2023-01-02
+
+Challenge 198 Prime Count ( Ruby )
+
+=end
+
+
+require 'prime'
+
+arr = [10,15,1,25]
+
+
+arr.each do |n|
+
+ cnt = 0
+
+ puts("Input: $n = #{n}")
+
+ for x in 0..n-1 do
+
+ if Prime.prime?(x) #=> true
+
+ cnt += 1
+
+ end
+
+ end
+
+ puts("Output: #{cnt}")
+
+ puts(" ")
+
+end
+
+
+=begin
+
+ruby .\PrimeCount.rb
+
+Input: $n = 10
+
+Output: 4
+
+
+Input: $n = 15
+
+Output: 6
+
+
+Input: $n = 1
+
+Output: 0
+
+
+Input: $n = 25
+
+Output: 9
+
+
+=end
diff --git a/challenge-198/ziameraj16/java/PrimeCount.java b/challenge-198/ziameraj16/java/PrimeCount.java
new file mode 100644
index 0000000000..26e5d75b0f
--- /dev/null
+++ b/challenge-198/ziameraj16/java/PrimeCount.java
@@ -0,0 +1,37 @@
+import java.util.Scanner;
+
+public class PrimeCount {
+
+ public static void main(String[] args) {
+ Scanner scanner = new Scanner(System.in);
+ System.out.println("Enter a number");
+ final int i = Integer.parseInt(scanner.nextLine());
+ int numberOfPrimes = 1;
+ if (i == 1) {
+ System.out.println(0);
+ } else if (i == 2) {
+ System.out.println(1);
+ } else {
+ for (int j = 3 ; j <= i; j++) {
+ if (isPrime(j)) {
+ numberOfPrimes++;
+ }
+ }
+ System.out.println(numberOfPrimes);
+ }
+ }
+
+ private static boolean isPrime(int num) {
+ if (num % 2 == 0) {
+ return false;
+ }
+ int i = 3;
+ while (i < num / 2) {
+ if (num % i == 0) {
+ return false;
+ }
+ i = i + 2;
+ }
+ return true;
+ }
+}