Data commit

This commit is contained in:
Ingy döt Net 2023-07-01 11:58:00 -04:00
parent 7387c8f97b
commit cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions

View file

@ -0,0 +1,3 @@
is_leap() {
return $((${1%00} & 3))
}

View file

@ -0,0 +1,6 @@
leap() {
if expr $1 % 4 >/dev/null; then return 1; fi
if expr $1 % 100 >/dev/null; then return 0; fi
if expr $1 % 400 >/dev/null; then return 1; fi
return 0;
}

View file

@ -0,0 +1,3 @@
leap() {
date -d "$1-02-29" >/dev/null 2>&1;
}

View file

@ -0,0 +1,5 @@
is_leap() {
local year=$(( 10#${1:?'Missing year'} ))
(( year % 4 == 0 && ( year % 100 != 0 || year % 400 == 0 ) )) && return 0
return 1
}

View file

@ -0,0 +1,3 @@
leap() {
cal 02 $1 | grep -q 29
}

View file

@ -0,0 +1,39 @@
#!/bin/bash
is_leap_year () # Define function named is_leap_year
{
declare -i year=$1 # declare integer variable "year" and set it to function parm 1
echo -n "$year ($2)-> " # print the year passed in, but do not go to the next line
if (( $year % 4 == 0 )) # if year not dividable by 4, then not a leap year, % is the modulus operator
then
if (( $year % 400 == 0 )) # if century dividable by 400, is a leap year
then
echo "This is a leap year"
else
if (( $year % 100 == 0 )) # if century not divisible by 400, not a leap year
then
echo "This is not a leap year"
else
echo "This is a leap year" # not a century boundary, but dividable by 4, is a leap year
fi
fi
else
echo "This is not a leap year"
fi
}
# test all cases
# call the function is_leap_year several times with two parameters... year and test's expectation for 'is/not leap year.
is_leap_year 1900 not # a leap year
is_leap_year 2000 is # a leap year
is_leap_year 2001 not # a leap year
is_leap_year 2003 not # a leap year
is_leap_year 2004 is # a leap year
# Save the above to a file named is_leap_year.sh, then issue the following command to run the 5 tests of the function
# bash is_leap_year.sh