SEC S20W6 : Practice Cycles and Guess the Number Game

Gold Luxury Initial Circle Logo_20241019_033234_0000.png
edited with canva

Hello friends and welcome to my article in the SEC S20/W6 in this great dynamics. I would take part in the task immediately.


Experiment with colors- are there more than the ones we've used? How can you check?

Colors involve orchestrating text to look for find in appearance. There are several colors used in our programming. They vary from red, blue, green, magenta, violet. Colors can be brought to life using Esc sequence to change colors in our texts. The escape are used to change appearance of text in program. We use \033 or \e in CPP which is synonymous to the ASCII for escape symbol.

Using escape sequence, syntax, we can be able to attribute special combination, such as bold, italics or underline. Possible by attributing [] After escape code then define parameters to vs implemented.


Application Of Color Theory

There are special categories which color theory can be applied. These are;

Standard Color Code;

This explains direct application of colors to our characters. Some of these color code and colors include.

Color CodeRepresentation
30mBlack 🖤
31mRed ♥️
32mGreen 💚
33mYellow 💛
34mBlue 💙
35mMagenta []
36mWhite 🤍
0mreset all sequence

The escape sequence 033 30m or \e [30m \033 [31m......] for 🖤...just to mention a few.


Background Color Code;

Color CodeBackground Color Representation
40mBlack background ⚫
41mRed background 🔴
42mGreen background 🟢
43mYellow background 🟡
44mBlue background 🔵
45mMagenta background []
46mCyan background
47mWhite background ⚪

Representation can be \033 [40m...,\033 [41m...] for 🔴 just to mention but a few


Special Attribute to Text:

We can either make out text background look high on contrast and brightness respectively

Color CodeHigh brightness text Representation
90mBlack ⬛
91mRed 🟥
92mGreen 🟩
93mYellow 🟨
94mBlue 🟦
95mMagenta []
96mCyan
97mWhite ⬜

Color Codehigh brightness background color representation
100mBlack background ⬛
101mRed background 🟥
102mGreen background 🟩
103mYellow background 🟨
104mBlue square 🟦
105mMagenta background []
106mCyan background
107mWhite background ⬜

Text Styling:

Here we choose how we want to style, to look bold underlined and so on. It's possible with these codes

Color CodeBackground color representation
1mBold
4mUnderline
5mBlack
7minverted color
9mstrike through text

After all these codes and background, we can implement them in our program. \e [ 1; 31; 47m] is interpreted as bold red text in background below.

Screenshot_20241019-020318.png

Explanation;

It begins with what it turned out to be after encoding. Wake up message; wishes him goodluck, program ask user to input their names program proceeds by requesting level of difficulty the user wants to play. The crucial aspect of the game is giving players cluesto the right answers. Each option displays a clue whether number is high or low. Players can work with regards to hint given.

Screenshot_20241019-021037.png

Easy mode involves selecting numbers from 0 to 20. Players having maximum of t attempts until users gives correct clues. The normal mode involves selecting players from 0 to 50 here players have about seven attempts. Once they are exhausted, program displays a response with correct answers applauding congratulations

Screenshot_20241019-021111.png

Difficult mode players is requested to select random numbers from 0 to 100 In this case maximum of 10 attempts is given, if player guesses rightly it also displays congratulations if not sorry you ran out of attempts the answer would be shown immediately.

Screenshot_20241019-021135.png

Make an estimate of how long it will take us to guess a number if the range is from 0 to 1000 or from 0 to 10000

Estimated Guessing Time:

Problem Scenario:
We try to calculate average number of guesses required to find a number within a range using guessing strategy.

Assumption;
Number generation; we assume random numbers is generated uniformly within specified range

Optimal Guessing Strategy;
We'll use binary search algorithm, an efficient method for finding target values in arranged sequence. Once number aren't sorted, we can adapt binary search principle.

Analyzing:
Binary search is medium to get used, we divide space in half with each guess, the worst case scenario target numbers is median of range. Best case first guess is presumed correct.

Calculation:
Ranging from 0-100 numbers of division required is log2(1000)= 9.97
Worst case takes about 10 guesses

Ranging from 0-1000
Number of division required
log 2(10000)= 13.29
Worst case it would take around 14 guesses
Using proportion it takes 2 seconds to get an attempt from 0-100 and about 2×10= 20 sec.

Ranging from 0-10000
It is maximum of 14 attempts giving at least 2×14=28 sec


Write a two player game. There are 30 balls on table, players take time picking between 1 and 5 balls. Winner is one who takes last ball. No need to develop winning strategy, simply program codes to follow rules,majd players take turns, announce winner at completion.

Screenshot_20241019-021449.png
Game Routine

Start with numbers of ball remaining. Players take turns, a variable to store numbers of ball is present. It continues for a while in a loop while there are balls remaining. It requires current players to enter numbers of balls they need to take,validate to ensure it's allowed and there are enough balls left.

If input is valid it updates numbers of ball, switches to the next player turn and the sequence continues until there are no balls left. Game ends once the last ball is taken current player is emerged as winner.

Screenshot_20241019-021801.png

From the above it could be spotted that player 2 wind seeing he has four balls left. We all know how it works. We check for an invalid input so that you wouldn't be disqualified.


Follow same path from single star to square, transform square to triangle, pick any triangle. Experienced students should choose one with higher number as it's more challenging

Screenshot_20241019-022048.png

Here we create shapes using simple approach, start printing the * in simple forms, them transform to large complex shape by using nested loops to properly print row and column .

Cc;
@sergeyk

I have concluded my article and would love to invite @simonnwigwe @ruthjoe @pandora2010 @josepha to join challenge
Sort:  

❌❌❌Why do you have screenshots of the code from one software environment and a screenshot of the result of the application from another online software environment?

Screenshots are not your creation!!!! You took them from @rafk
this is a copy paste, the code, by the way, is also copied from @rafk

What's the point of me rating your work?

Not counted at all❌❌❌

Upvoted. Thank You for sending some of your rewards to @null. It will make Steem stronger.