Skip to content

Commit dea3ce3

Browse files
authored
Merge pull request #1 from TheAlgorithms/master
Update
2 parents e08408c + fcac632 commit dea3ce3

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+746
-166
lines changed
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
# This GitHub Action updates the DIRECTORY.md file (if needed) when doing a git push
2+
name: update_directory_md
3+
on: [push]
4+
jobs:
5+
update_directory_md:
6+
runs-on: ubuntu-latest
7+
steps:
8+
- uses: actions/checkout@master
9+
- uses: actions/setup-python@master
10+
- name: update_directory_md
11+
shell: python
12+
run: |
13+
import os
14+
from typing import Iterator
15+
16+
URL_BASE = "https://github.com/TheAlgorithms/Java/blob/master"
17+
g_output = []
18+
19+
20+
def good_filepaths(top_dir: str = ".") -> Iterator[str]:
21+
for dirpath, dirnames, filenames in os.walk(top_dir):
22+
dirnames[:] = [d for d in dirnames if d[0] not in "._"]
23+
for filename in filenames:
24+
if os.path.splitext(filename)[1].lower() == ".java":
25+
yield os.path.join(dirpath, filename).lstrip("./")
26+
27+
28+
def md_prefix(i):
29+
return f"{i * ' '}*" if i else "\n##"
30+
31+
32+
def print_path(old_path: str, new_path: str) -> str:
33+
global g_output
34+
old_parts = old_path.split(os.sep)
35+
for i, new_part in enumerate(new_path.split(os.sep)):
36+
if i + 1 > len(old_parts) or old_parts[i] != new_part:
37+
if new_part:
38+
g_output.append(f"{md_prefix(i)} {new_part.replace('_', ' ')}")
39+
return new_path
40+
41+
42+
def build_directory_md(top_dir: str = ".") -> str:
43+
global g_output
44+
old_path = ""
45+
for filepath in sorted(good_filepaths(), key=str.lower):
46+
filepath, filename = os.path.split(filepath)
47+
if filepath != old_path:
48+
old_path = print_path(old_path, filepath)
49+
indent = (filepath.count(os.sep) + 1) if filepath else 0
50+
url = "/".join((URL_BASE, filepath, filename)).replace(" ", "%20")
51+
filename = os.path.splitext(filename.replace("_", " "))[0]
52+
g_output.append(f"{md_prefix(indent)} [{filename}]({url})")
53+
return "\n".join(g_output)
54+
55+
56+
with open("DIRECTORY.md", "w") as out_file:
57+
out_file.write(build_directory_md(".") + "\n")
58+
59+
- name: Update DIRECTORY.md
60+
run: |
61+
cat DIRECTORY.md
62+
git config --global user.name github-actions
63+
git config --global user.email '${GITHUB_ACTOR}@users.noreply.github.com'
64+
git remote set-url origin https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/$GITHUB_REPOSITORY
65+
git add DIRECTORY.md
66+
git commit -am "updating DIRECTORY.md" || true
67+
git push --force origin HEAD:$GITHUB_REF || true

Conversions/AnyBaseToAnyBase.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ public static void main(String[] args) {
5252
}
5353
}
5454
System.out.println(base2base(n, b1, b2));
55+
in.close();
5556
}
5657

5758
/**

Conversions/AnytoAny.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ public static void main(String[] args) {
2424
dec /= db;
2525
}
2626
System.out.println(dn);
27+
scn.close();
2728
}
2829

2930
}

Conversions/DecimalToBinary.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
/**
66
* This class converts a Decimal number to a Binary number
77
*
8-
* @author Unknown
8+
*
99
*/
1010
class DecimalToBinary {
1111

@@ -53,6 +53,7 @@ public static void bitwiseConversion() {
5353
n >>= 1;
5454
}
5555
System.out.println("\tBinary number: " + b);
56+
input.close();
5657
}
5758

5859
}

Conversions/DecimalToHexaDecimal.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package Conversions;
22

3+
//hex = [0 - 9] -> [A - F]
34
class DecimalToHexaDecimal {
45
private static final int sizeOfIntInHalfBytes = 8;
56
private static final int numberOfBitsInAHalfByte = 4;

Conversions/DecimalToOctal.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,16 @@
55
/**
66
* This class converts Decimal numbers to Octal Numbers
77
*
8-
* @author Unknown
8+
*
99
*/
1010
public class DecimalToOctal {
1111
/**
1212
* Main Method
1313
*
1414
* @param args Command line Arguments
1515
*/
16+
17+
//enter in a decimal value to get Octal output
1618
public static void main(String[] args) {
1719
Scanner sc = new Scanner(System.in);
1820
int n, k, d, s = 0, c = 0;

Conversions/HexToOct.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,6 @@ public static void main(String args[]) {
6464
// convert decimal to octal
6565
octalnum = decimal2octal(decnum);
6666
System.out.println("Number in octal: " + octalnum);
67-
68-
67+
scan.close();
6968
}
7069
}

Conversions/HexaDecimalToBinary.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package Conversions;
22

3+
//Hex [0-9],[A-F] -> Binary [0,1]
4+
35
public class HexaDecimalToBinary {
46

57
private final int LONG_BITS = 8;
@@ -9,7 +11,7 @@ public void convert(String numHex) {
911
int conHex = Integer.parseInt(numHex, 16);
1012
// Hex a Binary:
1113
String binary = Integer.toBinaryString(conHex);
12-
// Presentation:
14+
// Output:
1315
System.out.println(numHex + " = " + completeDigits(binary));
1416
}
1517

Conversions/HexaDecimalToDecimal.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public static void main(String args[]) {
3434
and it returns the decimal form in the variable dec_output.
3535
*/
3636
System.out.println("Number in Decimal: " + dec_output);
37-
37+
scan.close();
3838

3939
}
4040
}

Conversions/IntegerToRoman.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,29 @@
11
package Conversions;
22

3+
/**
4+
* Converting Integers into Roman Numerals
5+
*
6+
*('I', 1);
7+
*('IV',4);
8+
*('V', 5);
9+
*('IV',9);
10+
*('X', 10);
11+
*('XL',40;
12+
*('L', 50);
13+
*('XC',90);
14+
*('C', 100);
15+
*('D', 500);
16+
*('M', 1000);
17+
*
18+
*/
19+
20+
321
public class IntegerToRoman {
422
private static int[] allArabianRomanNumbers = new int[]{1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1};
523
private static String[] allRomanNumbers = new String[]{"M", "CM", "D", "CD", "C", "XC", "L", "XL", "X", "IX", "V", "IV", "I"};
624

25+
//Value must be > 0
26+
727
public static String integerToRoman(int num) {
828
if (num <= 0) {
929
return "";

Conversions/OctalToHexadecimal.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ public static void main(String args[]) {
5959
// Pass the decimla number to function and get converted Hex form of the number
6060
String hex = DecimalToHex(decimal);
6161
System.out.println("The Hexadecimal equivalant is: " + hex);
62+
input.close();
6263
}
6364
}
6465

Conversions/RomanToInteger.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ public class RomanToInteger {
1313
put('D', 500);
1414
put('M', 1000);
1515
}};
16+
//Roman Number = Roman Numerals
1617

1718
/**
1819
* This function convert Roman number into Integer

0 commit comments

Comments
 (0)