EX_03/README.md

126 lines
5.0 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# Exam Rank 03 — 42 School: Exercise Solutions
This repository contains solutions to the Exam Rank 03 exercises from the 42
School curriculum. The content is organized by exercise level and includes the
exercise subjects (for reference) together with example implementations and
build scripts where applicable.
This README provides an overview of the repository, how to build and run the
exercises, a short description of each exercise, and testing notes.
## Repository layout
- `level-1/`
- `broken_gnl/` — a variant of the "get_next_line" assignment (broken/intentional-bug version and subject)
- `filter/` — program that replaces occurrences of a substring with asterisks
- `scanf/` — partial implementation of `ft_scanf`
- `level-2/`
- `n_queens/` — N-Queens solutions with Makefile and subject
- `permutations/` — generate all permutations of a string in alphabetical order
- `powerset/` — find subsets that sum to a target value
- `tsp/` — brute-force traveling salesman solver (small n)
- `rip/` — parentheses balancing and minimal removal solutions
Each exercise directory typically contains:
- `subject.txt` or `README.md` — the exercise statement provided for reference
- `*.c`, `*.h` — implementation and headers
- `Makefile` — build helper (for many level-2 exercises)
## Purpose and license
The exercise subjects are the property of 42 School and are included for
educational reference. Implementations contained in this repository are the
original work of the repository author and are provided for non-commercial
educational use only (see `LICENSE` for full terms and contact information).
## Building
General notes:
- The projects are standard C programs and use `gcc`.
- Several level-2 directories include a `Makefile` with standard targets:
- `make` / `make all` — compile the program
- `make clean` — remove object files
- `make fclean` — remove object files and executable
- `make re` — rebuild from scratch
- `make test` — run example tests (where provided)
Examples (run from repository root):
Change into an exercise directory and build:
cd level-2/n_queens
make
For `tsp` the Makefile links against libm, so the `-lm` flag is used automatically.
## Running the exercises (summary)
Below are concise descriptions and usage examples for each exercise. For full
details refer to the exercise `subject.txt` or the directory README.
- broken_gnl (level-1/broken_gnl)
- Purpose: an implementation of a `get_next_line`-like function. The
directory includes a subject and a sample (intentionally flawed) solution.
- filter (level-1/filter)
- Purpose: read stdin and replace every occurrence of the given pattern with
a sequence of asterisks of equal length.
- Usage: `./filter <pattern>`
- Example: `echo "abcabc" | ./filter abc` outputs `*** ***` (without spaces)
- scanf (level-1/scanf)
- Purpose: partial reimplementation of `scanf` supporting `%s`, `%d` and `%c`.
- The directory contains a working `ft_scanf.c` and helper subject file.
- n_queens (level-2/n_queens)
- Purpose: print all valid placements of N queens on an N×N board.
- Usage: `./n_queens N`
- Output: lines with N integers representing row positions for each column.
- permutations (level-2/permutations)
- Purpose: print all permutations of the input string in alphabetical order.
- Usage: `./permutations <string>`
- powerset (level-2/powerset)
- Purpose: list all subsets of the provided set whose elements sum to the
target integer (first argument).
- Usage: `./powerset <target> <list of distinct integers>`
- tsp (level-2/tsp)
- Purpose: brute-force shortest closed path visiting all given points (n ≤ 11).
- Usage: `./tsp < input.txt` where input has lines like `x, y` (floating points).
- Output: a single floating number formatted to two decimals (e.g. `8.00`).
- rip (level-2/rip)
- Purpose: remove the minimum number of parentheses (replace by spaces) to
make input strings balanced and print all distinct minimal solutions.
- Usage: `./rip "( )..."`
## Testing notes
- Many directories include example `Makefile` targets named `test` that run the
compiled binary with sample inputs from the exercise statements. Use those
targets to verify behavior quickly.
- For exercises that read from stdin, you can pipe data via `echo` or use file
redirection: `./tsp < level-2/tsp/square.txt`.
## Quality and limitations
- These are educational implementations. Some directories include intentionally
broken code (for debugging practice) or partial templates intended to be
completed.
- The programs follow the constraints given in each subject (allowed
functions, expected behavior on edge cases, and error handling).
## Contributing and contact
This repository is a personal collection of exercise solutions. Contributions are
welcome as long as they follow the repository license and respect the original
exercise authorship. For questions, corrections or requests regarding licensing
or removal of subject material, contact the repository owner (see `LICENSE`).
---
Last updated: October 2025