diff --git a/progress.md b/progress.md new file mode 100644 index 0000000..e69de29 diff --git a/week 1/day3/exo1.sql b/week 1/day 3/exo1.sql similarity index 100% rename from week 1/day3/exo1.sql rename to week 1/day 3/exo1.sql diff --git a/week 1/day3/exo2.sql b/week 1/day 3/exo2.sql similarity index 100% rename from week 1/day3/exo2.sql rename to week 1/day 3/exo2.sql diff --git a/week 1/day3/exo3.sql b/week 1/day 3/exo3.sql similarity index 100% rename from week 1/day3/exo3.sql rename to week 1/day 3/exo3.sql diff --git a/week 1/day3/exo4.sql b/week 1/day 3/exo4.sql similarity index 100% rename from week 1/day3/exo4.sql rename to week 1/day 3/exo4.sql diff --git a/week 1/day3/exo5.md b/week 1/day 3/exo5.md similarity index 100% rename from week 1/day3/exo5.md rename to week 1/day 3/exo5.md diff --git a/week 1/day3/init_db.sql b/week 1/day 3/init_db.sql similarity index 100% rename from week 1/day3/init_db.sql rename to week 1/day 3/init_db.sql diff --git a/week 1/day3/readme.md b/week 1/day 3/readme.md similarity index 100% rename from week 1/day3/readme.md rename to week 1/day 3/readme.md diff --git a/week 1/day 4/exo1.ps1 b/week 1/day 4/exo1.ps1 new file mode 100644 index 0000000..b9d467e --- /dev/null +++ b/week 1/day 4/exo1.ps1 @@ -0,0 +1,16 @@ +# exo 1 +$number = [int](Read-Host('please enter a number')); + +if(!$number || $number -isnot [int]) +{ + Write-Host('you should enter a number !') + exit +} + +if ($number % 2) +{ + Write-Host('Odd'); +}else +{ + Write-Host('Even'); +} \ No newline at end of file diff --git a/week 1/day 4/exo2.ps1 b/week 1/day 4/exo2.ps1 new file mode 100644 index 0000000..953f62f --- /dev/null +++ b/week 1/day 4/exo2.ps1 @@ -0,0 +1,13 @@ +# exo 2 +# return the number of character of a string only if they're letter + +$text = Read-Host('please enter a phrase') +$counter = 0 + +foreach ($char in $text.ToCharArray()) { + if($char -match '[A-Za-z]'){ + $counter++ + } +} + +Write-Host("your string contain ${counter} character") \ No newline at end of file diff --git a/week 1/day 4/exo3.ps1 b/week 1/day 4/exo3.ps1 new file mode 100644 index 0000000..f2d68f1 --- /dev/null +++ b/week 1/day 4/exo3.ps1 @@ -0,0 +1,28 @@ +# accept the username only if +# it contain letters, the username is inferior at 20 +# start with a letter, no digit, no space + +$username = Read-Host("Please enter your username"); +$badChar = $false; + +if($username -eq ''){ + Write-Host("The username can't be empty"); + exit; +} + +foreach($char in $username.ToCharArray()){ + if($char -notmatch '[A-Za-z]' -or $char -eq ' '){ + $badChar = $true; + break + } +} + +$firstLetter = $username[0] +$validFirstLetter = $firstLetter -match '[A-Za-z]' + +if(-not $badChar -and $username.Length -le 20 -and $validFirstLetter ){ + Write-Host("Accepted"); +}else{ + Write-Host("Invalid"); + +} \ No newline at end of file diff --git a/week 1/day 4/exo4.ps1 b/week 1/day 4/exo4.ps1 new file mode 100644 index 0000000..87a8362 --- /dev/null +++ b/week 1/day 4/exo4.ps1 @@ -0,0 +1,24 @@ +$users = @("admin", "root1", "John_Doe", "Alice", "Bob42") + +foreach($username in $users){ + + $badChar = $false + + foreach($char in $username.ToCharArray()){ + if($char -notmatch '[A-Za-z]' -or $char -eq ' '){ + $badChar = $true + break + } + + } + + $firstLetter = $username[0] + $validFirstLetter = $firstLetter -match '[A-Za-z]' + + if(-not $badChar -and $username.Length -le 20 -and $validFirstLetter ){ + Write-Host("$username is valid"); + }else{ + Write-Host("$username is Invalid"); + + } +} \ No newline at end of file diff --git a/week 1/day 4/exo5.md b/week 1/day 4/exo5.md new file mode 100644 index 0000000..11910ea --- /dev/null +++ b/week 1/day 4/exo5.md @@ -0,0 +1,24 @@ +**Task:** + +* Explain what happens if the number of users doubles +* Write the runtime formula using: + + * `n` = number of users + * `m` = average username length + +**Expected reasoning:** + +* Doubling the list doubles the execution time +* Linear runtime: `T(n, m) = n Γ— m` + +**Answer** + +if the number of user double in size + +$$ +T(2n, m) = n /times 2 /times m +$$ + +so the number of execution will multiply by 2 + +the big O notation will be O(nβ‹…m) diff --git a/week 1/day 4/readme.md b/week 1/day 4/readme.md new file mode 100644 index 0000000..10bad3b --- /dev/null +++ b/week 1/day 4/readme.md @@ -0,0 +1,137 @@ +# πŸ“˜ Week 1 Β· Day 4 β€” PowerShell Exercises + +This document describes **all exercises for Week 1 Day 4**, focused on **PowerShell conditionals, loops, and sysadmin-oriented input validation**. + +The goal is to translate your existing algorithmic knowledge (from C, Python, SQL) into **PowerShell syntax and pipelines**, preparing you for Windows administration and automation tasks. + +--- + +## 🎯 Learning Objectives + +By completing today’s exercises, you will: + +* Use `if / elseif / else` for conditional logic +* Loop over strings and collections with `foreach` +* Apply input validation logic in a Windows scripting context +* Understand early exit using `break` +* Reason about algorithm runtime (`T(n)`) in PowerShell +* Practice defensive programming for security-sensitive scripts + +--- + +## πŸ›  Exercises + +### Exercise 1 β€” Even / Odd Number Checker + +**Task:** + +* Prompt the user for a number +* Output `Even` or `Odd` + +**Concepts practiced:** + +* `Read-Host` +* Integer conversion +* Conditional branching (`if / else`) + +--- + +### Exercise 2 β€” Count Letters in a String + +**Task:** + +* Prompt the user for a string +* Count only letters (`A-Z`, `a-z`) +* Output the number of letters + +**Concepts practiced:** + +* `foreach` loop over string characters +* Regex matching with `-match` +* Counter variable logic + +--- + +### Exercise 3 β€” Username Validator + +**Task:** + +* Prompt the user for a username +* Validate using these rules: + + * Length ≀ 20 + * Starts with a letter + * No digits + * No spaces +* Output `Accepted` or `Refused` + +**Concepts practiced:** + +* Conditional logic +* Early exit using `break` +* Character validation via regex +* Defensive programming + +--- + +### Exercise 4 β€” Validate Multiple Usernames + +**Task:** + +* Given an array of usernames: + +```powershell +$users = @("admin", "root1", "John_Doe", "Alice", "Bob42") +``` + +* Print only valid usernames (using the same rules as Exercise 3) + +**Concepts practiced:** + +* Iterating over collections with `foreach` +* Reusing validation logic +* Output formatting + +--- + +### Exercise 5 β€” Algorithm Explanation (Written) + +**Task:** + +* Explain what happens if the number of users doubles +* Write the runtime formula using: + + * `n` = number of users + * `m` = average username length + +**Expected reasoning:** + +* Doubling the list doubles the execution time +* Linear runtime: `T(n, m) = n Γ— m` + +--- + +## πŸ” Security Perspective + +PowerShell scripts are heavily used in **Windows administration and security tasks**. Today’s exercises reinforce: + +* Input validation to prevent bad data +* Predictable scaling of loops +* Defensive coding practices + +These habits are essential for: + +* Active Directory scripting +* Log parsing and auditing +* Automating security tasks +* Incident response and analysis + +--- + +## βœ… Completion Criteria + +Day 4 is complete when: + +* Exercises 1–4 run correctly and produce expected outputs +* Exercise 5 demonstrates correct understanding of scaling and runtime +* Scripts are secure, readable, and reusable \ No newline at end of file diff --git a/week 1/day 4/test.ps1 b/week 1/day 4/test.ps1 new file mode 100644 index 0000000..de5f6d3 --- /dev/null +++ b/week 1/day 4/test.ps1 @@ -0,0 +1,5 @@ +# a little script to test if powershell work with my machine + +Write-Host("hello from powershell"); + +# ! it work :) \ No newline at end of file