DevJourney · code I wrote while learning

README.md

4.6 KB

FAT Java practice programs

Each source is an independent program with class Main. Copy the selected source to Main.java if your lab IDE requires that filename. Do not compile these sources together. See the course index for compilation commands and import scope.

Input formats

NumberProgramInput
01Sieve of Eratosthenesone integer n
02Segmented sievetwo integers l h
03Euler phione positive integer n
04Chinese remainder theoremk, followed by k modulus/remainder pairs
05Strobogrammatic checkone digit string
06Strobogrammatic generationone positive length n
07Binary palindromeone nonnegative long n
08Toggle the switchone nonnegative long n
09Alice apple treeone nonnegative long neededApples
10Natural sortn, then n lines
11Student comparatorn, then n lines of roll name age
12Quicksortn, then n integers
13Selection sortn, then n integers
14Move hyphensone full line
15Manacher longest palindromeone full line
16Sorted unique permutationsone full line
17Combinationsn, then n integers, then r
18Josephusn k
19Maneuvering pathsrows cols
20Rat mazen, then n * n values (0/1)
21N queensn
22Warnsdorff knight tourn startRow startCol (zero-based)
23Block swap rotationn d, followed by n integers

See EXPLANATIONS.md for algorithm notes.

Input and output conventions

Use nonnegative array counts and positive grid sizes. Student names use one token. Natural sort consumes n full lines after its count. Programs 14, 15, and 16 consume a full line, including spaces. Natural sort compares digit runs numerically. Student comparison uses ordinary name order. Josephus returns a 1-based position. Knight coordinates are zero-based. Rat maze permits only down and right moves. N queens prints all solutions. Warnsdorff uses a greedy heuristic. No tour found does not prove impossibility. CRT prints the least nonnegative solution, including zero when appropriate. Enumeration programs can produce very large outputs.

Corrections from the download

Removed duplicate classes, invalid prose inside code, and hardcoded driver inputs. Corrected segmented sieve indexing for lower bounds below two. Made Manacher separators distinct from every input character. Generated unique permutations directly in sorted order without a deduplication map. Marked the knight start before searching and implemented the actual Warnsdorff rule. Added a literal block swap rotation program with n = 0 and negative d support.