aboutsummaryrefslogtreecommitdiff
path: root/challenge-145/khalid
diff options
context:
space:
mode:
authorMohammad S Anwar <mohammad.anwar@yahoo.com>2022-01-03 02:33:32 +0000
committerMohammad S Anwar <mohammad.anwar@yahoo.com>2022-01-03 02:33:32 +0000
commitc4730c3acbe8610ed9cf8d3cc799d15d4bc0ae44 (patch)
tree5d6ae7b25fb683c7633e02ba2bab9fd5ea125047 /challenge-145/khalid
parent00f91e8d94badf473a1e379ccfdbfd9b09f43806 (diff)
downloadperlweeklychallenge-club-c4730c3acbe8610ed9cf8d3cc799d15d4bc0ae44.tar.gz
perlweeklychallenge-club-c4730c3acbe8610ed9cf8d3cc799d15d4bc0ae44.tar.bz2
perlweeklychallenge-club-c4730c3acbe8610ed9cf8d3cc799d15d4bc0ae44.zip
- Added solution by Mohammad Khalid Anwar.
Diffstat (limited to 'challenge-145/khalid')
-rw-r--r--challenge-145/khalid/cpp/ch-2.cpp210
-rw-r--r--challenge-145/khalid/perl/ch-1.pl13
2 files changed, 0 insertions, 223 deletions
diff --git a/challenge-145/khalid/cpp/ch-2.cpp b/challenge-145/khalid/cpp/ch-2.cpp
deleted file mode 100644
index 7d3b461178..0000000000
--- a/challenge-145/khalid/cpp/ch-2.cpp
+++ /dev/null
@@ -1,210 +0,0 @@
-// C++ program palindromic tree by khalid anwar
-#include "bits/stdc++.h"
-using namespace std;
-#define MAXN 1000
-
-struct Node
-{
-
- // store start and end indexes of current
- // Node inclusively
- int start, end;
-
-
- // stores length of substring
- int length;
-
-
- // stores insertion Node for all characters a-z
- int insertEdg[26];
-
-
- // stores the Maximum Palindromic Suffix Node for
- // the current Node
- int suffixEdg;
-
-};
-
-// two special dummy Nodes as explained above
- Node root1, root2;
-
-// stores Node information for constant time access
- Node tree[MAXN];
-
-// Keeps track the current Node while insertion
-int currNode;
-
-string s;
-
-int ptr;
-
-
-void
-insert (int idx)
-{
-
-//STEP 1//
-
- /* search for Node X such that s[idx] X S[idx]
- is maximum palindrome ending at position idx
- iterate down the suffix link of currNode to
- find X */
- int tmp = currNode;
-
-while (true)
-
- {
-
-int curLength = tree[tmp].length;
-
-if (idx - curLength >= 1 and s[idx] == s[idx - curLength - 1])
-
-break;
-
-tmp = tree[tmp].suffixEdg;
-
-}
-
-
- /* Now we have found X ....
- * X = string at Node tmp
- * Check : if s[idx] X s[idx] already exists or not*/
- if (tree[tmp].insertEdg[s[idx] - 'a'] != 0)
-
- {
-
- // s[idx] X s[idx] already exists in the tree
- currNode = tree[tmp].insertEdg[s[idx] - 'a'];
-
-return;
-
-}
-
-
- // creating new Node
- ptr++;
-
-
- // making new Node as child of X with
- // weight as s[idx]
- tree[tmp].insertEdg[s[idx] - 'a'] = ptr;
-
-
- // calculating length of new Node
- tree[ptr].length = tree[tmp].length + 2;
-
-
- // updating end point for new Node
- tree[ptr].end = idx;
-
-
- // updating the start for new Node
- tree[ptr].start = idx - tree[ptr].length + 1;
-
-
-
-//STEP 2//
-
- /* Setting the suffix edge for the newly created
- Node tree[ptr]. Finding some String Y such that
- s[idx] + Y + s[idx] is longest possible
- palindromic suffix for newly created Node. */
-
-tmp = tree[tmp].suffixEdg;
-
-
- // making new Node as current Node
- currNode = ptr;
-
-if (tree[currNode].length == 1)
-
- {
-
- // if new palindrome's length is 1
- // making its suffix link to be null string
- tree[currNode].suffixEdg = 2;
-
-return;
-
-}
-
-while (true)
-
- {
-
-int curLength = tree[tmp].length;
-
-if (idx - curLength >= 1 and s[idx] == s[idx - curLength - 1])
-
-break;
-
-tmp = tree[tmp].suffixEdg;
-
-}
-
-
- // Now we have found string Y
- // linking current Nodes suffix link with s[idx]+Y+s[idx]
- tree[currNode].suffixEdg = tree[tmp].insertEdg[s[idx] - 'a'];
-
-}
-
-
-
-// driver program
- int
-main ()
-{
-
- // initializing the tree
- root1.length = -1;
-
-root1.suffixEdg = 1;
-
-root2.length = 0;
-
-root2.suffixEdg = 1;
-
-
-tree[1] = root1;
-
-tree[2] = root2;
-
-ptr = 2;
-
-currNode = 1;
-
-
- // given string
- s = "challenge";
-
-int l = s.length ();
-
-
-for (int i = 0; i < l; i++)
-
-insert (i);
-
-
- // printing all of its distinct palindromic
- // substring
- cout << "All distinct palindromic substring for "
- <<s << " : \n";
-
-for (int i = 3; i <= ptr; i++)
-
- {
-
-cout << i - 2 << ") ";
-
-for (int j = tree[i].start; j <= tree[i].end; j++)
-
-cout << s[j];
-
-cout << endl;
-
-}
-
-return 0;
-
-}
diff --git a/challenge-145/khalid/perl/ch-1.pl b/challenge-145/khalid/perl/ch-1.pl
deleted file mode 100644
index 4ce825ed60..0000000000
--- a/challenge-145/khalid/perl/ch-1.pl
+++ /dev/null
@@ -1,13 +0,0 @@
-sub dotprod
-{
- my($vec_a, $vec_b) = @_;
- die "Vector size must be same \n" unless @$vec_a == @$vec_b;
- my $sum = 0;
- $sum += $vec_a->[$_] * $vec_b->[$_] for 0..$#$vec_a;
- return $sum;
-}
-
-my @vec_a = (1,2,3);
-my @vec_b = (4,5,6);
-
-print dotprod(\@vec_a,\@vec_b), "\n"; \ No newline at end of file