Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 58 additions & 0 deletions week-2/Python/Meron-Solomon.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
#Meron Solomon
from itertools import permutations

#this function prints out the permutation from string input
def printPermutation(My_String):
lst=[]
Hold_perm = permutations(My_String)#useing the Permutation library
for i in list(Hold_perm):#loop will go through the size of the string until it finishes plugginf in the permutation
hold_prem_2=(''.join(i))
lst.append(hold_prem_2)
print("\nOutput:\n")
print(lst)#printing out the permutation

#this function takes in a string and
def Palindrome_Machine(My_String):
#this if statement checks the string
if not My_String:
return My_String
String_length, a, b = len(My_String), 0, 0
#
String_Hold = [[True]*String_length, [False]*String_length]
#This loop goes through the given string and appends it
for c in range(String_length-1):
if My_String[c] == My_String[c+1]:
String_Hold[1][c] = True
a, b = c, c+1
#This loop takes in the string and converts it into the permuatation
for d in range(2, String_length):
for c in range(String_length-d):
Hold_return = c+d
y, z = d%2, c+d//2
String_Hold[y][z] = String_Hold[y][z] and My_String[c] == My_String[Hold_return]
if String_Hold[y][z] and Hold_return-c > b-a:
a, b = c, Hold_return
return My_String[a:b+1]


# this while loop runs endlessely until you press the number 3
#Enter 1 to turn string into Palindrome
#Enter 2 for string permutation
#First enter a number then you enter a string that you want to turn into a palindrome or permutations
while True:
i=input("\nEnter 1 to turn string into Palindrome\nEnter 2 for string permutation\n3 to exit\n")
i=int(i)
if i==1:
String_1 = input("\nEnter String-Palindrome\n")
print("\nOutput:\n")
print(Palindrome_Machine(String_1))

elif i==2:
String_2 = input("\nEnter String-Permutation\n")
printPermutation(String_2)

elif i==3:
break
else:
print("\nwrong")

19 changes: 19 additions & 0 deletions week-2/Python/READ_ME.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
Palindrome and Permutation README

Enter 1 to type in a String you want to turn into Palindrome:
EX:

Enter String-Palindrome
ababad
Output:
ababa

Enter 2 to type in a String you want to turn into Permutation:
EX:

Enter String-Permutation
abb
Output:
['abb', 'abb', 'bab', 'bba', 'bab', 'bba']

Enter 3 to exit:
Binary file not shown.
Binary file added week-4/Java/Meron-Solomon/bin/Link_list$Take_n.class
Binary file not shown.
Binary file added week-4/Java/Meron-Solomon/bin/Link_list.class
Binary file not shown.
Binary file added week-4/Java/Meron-Solomon/bin/Reverse.class
Binary file not shown.
178 changes: 178 additions & 0 deletions week-4/Java/Meron-Solomon/src/Link_list.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,178 @@

public class Link_list
{
class Take_n
{
int num;
Take_n next;

public Take_n(int num)
{
this.num = num;
}
}


void Release(Take_n top)
{
while (top != null)
{
System.out.print(top.num + " ");
top = top.next;
}
}

Take_n Rest_1, Rest_2, Final;
int Take_on;


void input_var(int num, int Test_Hold)
{
Take_n newnode = new Take_n(num);
if (Test_Hold == 1)
{
newnode.next = Rest_1;
Rest_1 = newnode;
}
else if (Test_Hold == 2)
{
newnode.next = Rest_2;
Rest_2 = newnode;
}
else
{
newnode.next = Final;
Final = newnode;
}

}


void compare_size(Take_n n, Take_n m)
{

if (n == null)
return;


compare_size(n.next, m.next);


int sum = n.num + m.num + Take_on;
Take_on = sum / 10;
sum = sum % 10;


input_var(sum, 3);

}

Take_n which_one;


void take_on_C(Take_n Rest_1)
{

if (Rest_1 != which_one)
{
take_on_C(Rest_1.next);
int sum = Take_on + Rest_1.num;
Take_on = sum / 10;
sum %= 10;


input_var(sum, 3);
}
}

int take_on(Take_n top)
{
int count = 0;
while (top != null)
{
count++;
top = top.next;
}
return count;
}


void add_on_there()
{

if (Rest_1 == null)
{
Final = Rest_2;
return;
}


if (Rest_2 == null)
{
Final = Rest_1;
return;
}

int size1 = take_on(Rest_1);
int size2 = take_on(Rest_2);


if (size1 == size2)
{
compare_size(Rest_1, Rest_2);
}
else
{

if (size1 < size2)
{
Take_n check = Rest_1;
Rest_1 = Rest_2;
Rest_2 = check;
}
int seperate = Math.abs(size1 - size2);


Take_n check = Rest_1;
while (seperate-- >= 0)
{
which_one = check;
check = check.next;
}


compare_size(which_one, Rest_2);


take_on_C(Rest_1);
}

if (Take_on > 0)
input_var(Take_on, 3);

}


public static void main(String args[])
{
Link_list Test_Hold = new Link_list();
Test_Hold.Rest_1 = null;
Test_Hold.Rest_2 = null;
Test_Hold.Final = null;
Test_Hold.Take_on = 0;
int Case_1[] = { 5, 6, 3 };
int Case_2[] = { 8, 4, 2 };


for (int i = Case_1.length - 1; i >= 0; --i)
Test_Hold.input_var(Case_1[i], 1);


for (int i = Case_2.length - 1; i >= 0; --i)
Test_Hold.input_var(Case_2[i], 2);

Test_Hold.add_on_there();

Test_Hold.Release(Test_Hold.Final);
}
}
119 changes: 119 additions & 0 deletions week-4/Java/Meron-Solomon/src/Reverse.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@

public class Reverse {
public Reverse(char Take_in, Reverse After_in)
{
Take = Take_in;
After = After_in;
}
public char Take;
public Reverse After;
}
class Function_check {


private static Reverse Switch_string(String hold_string)
{
Reverse top_on = null;
Reverse tester = null;

for (int i = 0; i < hold_string.length(); i++) {
char charact = hold_string.charAt(i);
Reverse node = new Reverse(charact, null);

if (top_on == null) {
top_on = node;
tester = top_on;
}
else {
tester.After = node;
tester = tester.After;
}
}
return top_on;
}


private static Reverse Reverse(Reverse top_on)
{
if (top_on == null)
return top_on;

Reverse Start_on = null;
Reverse last = null;
Reverse start_p = null;


Start_on = top_on;

while (top_on != null && top_on.Take != ' ') {

last = top_on;

top_on = top_on.After;
}

if (top_on == null) {
top_on = Start_on;
return top_on;
}

do {


Reverse tester = top_on.After;
top_on.After = Start_on;
Start_on = top_on;
top_on = tester;

Reverse prev = null;

start_p = top_on;


while (top_on != null && top_on.Take != ' ') {
prev = top_on;
top_on = top_on.After;
}


prev.After = Start_on;


Start_on = start_p;
if (top_on == null)
break;


} while (top_on != null);

top_on = start_p;


last.After = null;
return top_on;
}


private static void show_off(Reverse Header)
{
Reverse tester = Header;

while (tester != null) {
System.out.print(tester.Take);
tester = tester.After;
}
}


public static void main(String[] args)
{
String hold_string = "I love Geeks for Geeks";

Reverse top_on = Switch_string(hold_string);

top_on = Reverse(top_on);

System.out.println("\nAfter:");
show_off(top_on);
}
}