Coding Challenge #2 - Passwords
-
FUZE Coding Challenge #2
Hi everyone and welcome to the 2nd challenge. The rules are:- Post your code below
- There will be 2 tasks per challenge, a Beginners challenge and an Advanced challenge. Anyone can participate in any one of them or both tasks.
- We are always open to suggestions!
- Have fun coding!!
TASK #1
LEVEL: Beginner
Given a string, return that string with all its words reversed while maintaining the spaces between them.
Example:
"Hello world" -> "olleH dlrow"TASK #2
LEVEL: Advanced
Password checker:
A password (Which is a string) must have 1 capitalized letter, 5 common letters and 1 - 3 numbers.
Example:- Abdjfk1 -> accepted
- dkDj2fd -> accepted
- DHrsfj4 -> rejected
- 14fdsDf -> rejected
- 4Ddsdfq32 -> accepted
-
Do we post actual code or IDs? Sorry, just a little confused. 😕
-
@ben-2-0 You'll need to post the actual code below. Not the ID's.
-
caps = ["A", "B", etc...] norms = ["a", "b", etc...] nums = ["0", "1", etc...] loop clear() pass = input("Enter a Password") clear() secure = chechsecurity(pass) if secure == 1 then print("Secure") else print("Not Secure") endif update() sleep(2) repeat function checksecurity(password) result = false totalcaps = 0 totalnorms = 0 totalnums = 0 for i = 0 to len(password) loop for k = 0 to len(caps) loop if password[i] == caps[k] then totalcaps += 1 endif repeat repeat // use same logic for norms and nums to count amout of each if totalcaps == 1 and totalnorms == 5 then if totalnums == 1 or totalnums == 2 or totalnums == 3 then result = true endif endif return result
Could probably do this better but hope it makes sense. This was fun to do so thanks for posting it!
-
A recursive solution for TASK #1:
Recursive solutions are probably not the best way to do things, but they are so much fun to write. Elegant solutions for a more civilised age!
I’ll skip the other task, since it seems to me that it’s hard to come up with any solution that isn’t just loops and counters. But I would be happy to be proved wrong about that! ;)