From c2713a3b64e57e84181576dcbf37700b29e8ff65 Mon Sep 17 00:00:00 2001 From: E7-87-83 Date: Thu, 13 Jan 2022 16:37:08 +0800 Subject: CY's challenge: Task 1 in 10 languages; Progress: Day 1 Afternoon --- challenge-147/cheok-yin-fung/README.md | 13 ++++++ challenge-147/cheok-yin-fung/julia/ch-1.jl | 67 ++++++++++++++++++++++++++++++ challenge-147/cheok-yin-fung/perl/ch-1.pl | 60 ++++++++++++++++++++++++++ 3 files changed, 140 insertions(+) create mode 100644 challenge-147/cheok-yin-fung/README.md create mode 100644 challenge-147/cheok-yin-fung/julia/ch-1.jl create mode 100644 challenge-147/cheok-yin-fung/perl/ch-1.pl diff --git a/challenge-147/cheok-yin-fung/README.md b/challenge-147/cheok-yin-fung/README.md new file mode 100644 index 0000000000..fb4db4e925 --- /dev/null +++ b/challenge-147/cheok-yin-fung/README.md @@ -0,0 +1,13 @@ +This is the beginning of the semester of my PG dip in IT; and I have finished all exams and assignments from the previous semester. Somehow today I want to try to play with programming languages. While Mohammad has said, having fun is important in learning, now I try to do the Task 1 in different programming languages which I am fluent at least at the "sightseeing purpose", within 4 days. + +Target list: +awk bash C++ +Java Node.js Julia +LISP PHP Perl Smalltalk +Befunge-93 (if I have that mentality) + +Script done (last update: Thursday, January 13, 2022 08:34:23 UTC): +1. Julia +2. Perl + + diff --git a/challenge-147/cheok-yin-fung/julia/ch-1.jl b/challenge-147/cheok-yin-fung/julia/ch-1.jl new file mode 100644 index 0000000000..166fd13389 --- /dev/null +++ b/challenge-147/cheok-yin-fung/julia/ch-1.jl @@ -0,0 +1,67 @@ +# The Weekly Challenge 147 +# Task 1 Truncatable Prime +# Thursday, January 13, 2022 PM03:18:00 + + +left_trun_primes = [2, 3, 5, 7] +primes = [2, 3, 5, 7] +index_ltp = [1, 5] + + + +lastelement(array) = array[length(array)] +x_no_less_than_sqrt_y(x, y) = x ≤ √y + + +function grep(func, array) + ans = [] + for variable in array + if func(variable) + push!(ans, variable) + end + end + return Tuple(ans) +end + + +function is_prime(int) + no_less_than_sqrt(x) = x_no_less_than_sqrt_y(x, int) + relatively_small_primes = grep(no_less_than_sqrt , primes) + for p in relatively_small_primes + if int % p == 0 + return false + end + end + return true +end + + +function append_arr_of_ltp(digits) + k = 0 + for d = 1:9 + for ind = index_ltp[digits-1]:(index_ltp[digits]-1) + new_num = parse(Int64, string(d) * string(left_trun_primes[ind])) + if is_prime(new_num) + push!(left_trun_primes, new_num) + k += 1 + end + end + end + push!(index_ltp, lastelement(index_ltp) + k + 1) +end + + +function append_arr_of_primes(min,max) + for num = min:max + if is_prime(num) + push!(primes, num) + end + end +end + + + +append_arr_of_ltp(2) +append_arr_of_primes(10,sqrt(999)) +append_arr_of_ltp(3) +println(left_trun_primes[1:20]) diff --git a/challenge-147/cheok-yin-fung/perl/ch-1.pl b/challenge-147/cheok-yin-fung/perl/ch-1.pl new file mode 100644 index 0000000000..ff93203336 --- /dev/null +++ b/challenge-147/cheok-yin-fung/perl/ch-1.pl @@ -0,0 +1,60 @@ +# The Weekly Challenge 147 +# Task 1 Truncatable Prime +# Thursday, January 13, 2022 PM04:18:51 HKT + +use v5.12.0; +use warnings; + +my @ltp = (); +my @recent_ltp = (2,3,5,7); +my @new_ltp = (); + +my @prime = (2,3,5,7); + +sub is_prime { + my $t = $_[0]; + for (my $k = 0; defined($prime[$k]) && $prime[$k] <= sqrt($t) ;$k++) { + return 0 if $t % $prime[$k] == 0; + } + return 1; +} + + + +sub append_arr_of_primes { + my $max = $_[0]; + my @relatively_small_primes = grep { $_ <= sqrt($max) } @prime; + HERE: for my $can ($relatively_small_primes[-1]+1..$max) { + for my $p (@relatively_small_primes) { + next HERE if $can % $p == 0 + } + push @prime, $can; + } +} + + + +sub append_arr_of_ltp { + my $target_size = $_[0]; + if ($target_size <= (scalar @ltp + scalar @recent_ltp)) { + push @ltp, @recent_ltp; + return; + } + for my $d (1..9) { + for my $num (@recent_ltp) { + my $new_num = $d . $num; + push @new_ltp, $new_num if is_prime($new_num); + } + } + push @ltp, @recent_ltp; + @recent_ltp = @new_ltp; + @new_ltp = (); + append_arr_of_ltp($target_size); +} + + + +append_arr_of_primes(1000); +append_arr_of_ltp(20); +say $_ for @ltp[0..19]; + -- cgit From 415b77f3f489715d7888de8794affe9afe8d1ffb Mon Sep 17 00:00:00 2001 From: E7-87-83 Date: Thu, 13 Jan 2022 16:38:23 +0800 Subject: Purpose --- challenge-147/cheok-yin-fung/README | 13 +++++++++++++ challenge-147/cheok-yin-fung/README.md | 13 ------------- 2 files changed, 13 insertions(+), 13 deletions(-) create mode 100644 challenge-147/cheok-yin-fung/README delete mode 100644 challenge-147/cheok-yin-fung/README.md diff --git a/challenge-147/cheok-yin-fung/README b/challenge-147/cheok-yin-fung/README new file mode 100644 index 0000000000..fb4db4e925 --- /dev/null +++ b/challenge-147/cheok-yin-fung/README @@ -0,0 +1,13 @@ +This is the beginning of the semester of my PG dip in IT; and I have finished all exams and assignments from the previous semester. Somehow today I want to try to play with programming languages. While Mohammad has said, having fun is important in learning, now I try to do the Task 1 in different programming languages which I am fluent at least at the "sightseeing purpose", within 4 days. + +Target list: +awk bash C++ +Java Node.js Julia +LISP PHP Perl Smalltalk +Befunge-93 (if I have that mentality) + +Script done (last update: Thursday, January 13, 2022 08:34:23 UTC): +1. Julia +2. Perl + + diff --git a/challenge-147/cheok-yin-fung/README.md b/challenge-147/cheok-yin-fung/README.md deleted file mode 100644 index fb4db4e925..0000000000 --- a/challenge-147/cheok-yin-fung/README.md +++ /dev/null @@ -1,13 +0,0 @@ -This is the beginning of the semester of my PG dip in IT; and I have finished all exams and assignments from the previous semester. Somehow today I want to try to play with programming languages. While Mohammad has said, having fun is important in learning, now I try to do the Task 1 in different programming languages which I am fluent at least at the "sightseeing purpose", within 4 days. - -Target list: -awk bash C++ -Java Node.js Julia -LISP PHP Perl Smalltalk -Befunge-93 (if I have that mentality) - -Script done (last update: Thursday, January 13, 2022 08:34:23 UTC): -1. Julia -2. Perl - - -- cgit From 1ce263c8f221f47a046997b665845dbe5680ed9e Mon Sep 17 00:00:00 2001 From: E7-87-83 Date: Thu, 13 Jan 2022 16:54:59 +0800 Subject: - --- challenge-147/cheok-yin-fung/README | 1 + 1 file changed, 1 insertion(+) create mode 100644 challenge-147/cheok-yin-fung/README diff --git a/challenge-147/cheok-yin-fung/README b/challenge-147/cheok-yin-fung/README new file mode 100644 index 0000000000..05c1883e53 --- /dev/null +++ b/challenge-147/cheok-yin-fung/README @@ -0,0 +1 @@ + Solutions by Cheok-Yin Fung. -- cgit From 70b4929f9c722f9b6a7e7566201e96c6df12fe25 Mon Sep 17 00:00:00 2001 From: E7-87-83 Date: Thu, 13 Jan 2022 17:35:47 +0800 Subject: typo --- challenge-068/cheok-yin-fung/smalltalk/ch-2.st | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/challenge-068/cheok-yin-fung/smalltalk/ch-2.st b/challenge-068/cheok-yin-fung/smalltalk/ch-2.st index f4010ea6b6..e8e7c12787 100644 --- a/challenge-068/cheok-yin-fung/smalltalk/ch-2.st +++ b/challenge-068/cheok-yin-fung/smalltalk/ch-2.st @@ -4,7 +4,7 @@ "Usage: gst -S ch-2.st" "written on 30th Jan 2021" "Smalltalk has built-in Linked List, -here is reventing the wheel." +here is reinventing the wheel." Object subclass: Node [ -- cgit From 33336454923f69e42c139f2ec03b35f6fb6abfa2 Mon Sep 17 00:00:00 2001 From: E7-87-83 Date: Thu, 13 Jan 2022 18:15:24 +0800 Subject: removing whitespace which does not match the Befunge-93 standard (80x25) --- challenge-140/cheok-yin-fung/befunge-93/ch-2.bf | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/challenge-140/cheok-yin-fung/befunge-93/ch-2.bf b/challenge-140/cheok-yin-fung/befunge-93/ch-2.bf index 1b1038980f..4c285f20ed 100644 --- a/challenge-140/cheok-yin-fung/befunge-93/ch-2.bf +++ b/challenge-140/cheok-yin-fung/befunge-93/ch-2.bf @@ -6,8 +6,8 @@ v Task 2 Multiplication Table (in befunge-93) v<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< <<<<<<<<<<<<<<<<<<<< v >>>>>>>>>> >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> 60g30g1-`| v ^<<<<<<<<<<<<<<<<^vp071p06+1g06<<<<<<<<<<<< <<<<<<<<<<<<<<<<< -v v<<<<<<<<<<<<<<<<<<<<<<<<<<<<< <<<<<<<<<<<<<< -v >>>>>>>>>>>>>>> 70g40g`| ^p07+1g07< +v v<<<<<<<<<<<<<<<<<<<<<<<<<<<<< <<<<<<<<<<<<<< +v >>>>>>>>>>>>>>> 70g40g`| ^p07+1g07< v >70g60g*80g20gp80g1+80p^ v < v> ^ -- cgit