This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
notes:fall2024:projects:dsr0 [2024/09/21 00:58] – [state file: keeping score across sessions] cmazzara | notes:fall2024:projects:dsr0 [2024/09/26 16:08] (current) – [checking time] jmerri10 | ||
---|---|---|---|
Line 3: | Line 3: | ||
=====powers of two base math===== | =====powers of two base math===== | ||
Base 2^1 is 2 2^2 is 4 2^3 is 8 and so on and so forth. | Base 2^1 is 2 2^2 is 4 2^3 is 8 and so on and so forth. | ||
+ | |||
+ | Along with the conversions game mode, other modes should include addition, subtraction, | ||
=====powers of two base conversions===== | =====powers of two base conversions===== | ||
+ | For powers of two base conversion, or any type of conversions in bash scripts, it would behoove one to make use of the ibase / obase commands. With them, they can make the conversions of numbers for you. This is helpful for generating prompts and keys alike. | ||
+ | The goal of the conversions game mode should be for the player to be prompted with a number in one base, and be instructed to find the answer in another base (also prompted). | ||
+ | |||
+ | Can use shuf -i alongside an array to randomly generate a base | ||
=====checking time===== | =====checking time===== | ||
By using " | By using " | ||
+ | |||
+ | date +%r will give you the time in this format: HH:MM:SS AM/PM | ||
+ | |||
+ | date +%s will give you the time in seconds since the Unix epoch. If you want to use date +%s to get the current minutes, you can divide the output of date +%s by 60; if you want to use date +%s to get the current seconds, you can use the modulus operation (%60). | ||
+ | |||
=====state file: keeping score across sessions===== | =====state file: keeping score across sessions===== | ||
Line 12: | Line 23: | ||
You can either create this file manually for every new user or have the program do it for you! Here is an example of the program doing it: | You can either create this file manually for every new user or have the program do it for you! Here is an example of the program doing it: | ||
- | |||
< | < | ||
if [[ ! -f " | if [[ ! -f " | ||
Line 20: | Line 30: | ||
So that may be a lot at once to take in, so let's break it down. This line checks if the file exists, and when combined with an if statement it will do what is in the if statement if the file **DOES NOT EXIST***. | So that may be a lot at once to take in, so let's break it down. This line checks if the file exists, and when combined with an if statement it will do what is in the if statement if the file **DOES NOT EXIST***. | ||
- | |||
< | < | ||
! -f " | ! -f " | ||
Line 26: | Line 35: | ||
This line will make the file | This line will make the file | ||
- | |||
< | < | ||
touch info.txt | touch info.txt | ||
Line 44: | Line 52: | ||
echo " | echo " | ||
</ | </ | ||
- | Inside your program you can use commands like **grep, sed, cat, cut, tr, and head** to name a few in order to write to and replace the text in info.txt. And don't forget that in **BASH** you can use **|** to pipe/ | + | |
+ | Again let's break that down. Here we are redirecting the output of " | ||
+ | < | ||
+ | echo " | ||
+ | </ | ||
+ | |||
+ | Inside your program you can use commands like **grep, sed, cat, cut, tr, and head** to name a few in order to write to and replace the text in info.txt. And don't forget that in **BASH** you can use **<fs x-large>|</fs>** to pipe/ |