Shell grooming (31) = = = A small example of common year leap year and nested loops

Source: Internet
Author: User

Topic (i)

There are 1 2 3 44 digits, any combination of how many different and no duplicates of the number, what is the difference?

The shell code is as follows:

#!/bin/bash


For i in ' seq 4 '

Do

For x in ' SEQ 4 '

Do

For y in ' seq 4 '

Do

[$x-eq $i] && continue

[$x-eq $y] && continue

[$i-eq $y] && continue

echo $i $x$y



Done

Done

Done


There are 24 types of outputs:

[Email protected] ding]# bash 11.sh

123

124

132

134

142

143

213

............

For example: We change the title, or 1 2 3 4 The following rules

[Email protected] ding]# bash 12.sh

123

124

134

234

[Email protected] ding]#

The shell code is as follows:

#!/bin/bash


For i in ' seq 4 '

Do

For x in ' seq $i 4 '

Do

For y in ' seq $x 4 '

Do

[$i-eq $x] && continue

[$x-eq $y] && continue

echo $i $x$y

Done

Done

Done


650) this.width=650; "Src=" https://s5.51cto.com/wyfs02/M00/A6/38/wKioL1nLOJjQK5SrAAB53A4ypI8621.png-wh_500x0-wm_ 3-wmp_4-s_1290789857.png "Title=" This is the three-layer nested figure "alt=" wkiol1nlojjqk5sraab53a4ypi8621.png-wh_50 "/>


The first question to this figure can be completely thought out, a total of 64, but we add to judge what the final screening out 24 kinds

(b) The user arbitrarily enter four numbers, judging whether it is common year or leap year

Rule of Judgement:

Look at the end of the year two can not be divisible by 4 is common year, is divisible by 4 but the last two bits are 0, to see the first two can be divisible by 4 is a leap year, not divisible by common year. For example: 1996, 2000 leap year 1990, 1997 common year

The output is as follows:

[Email protected] ding]# bash 14.sh

input:1996

Run year

[Email protected] ding]# bash 14.sh

input:2000

Run year

[Email protected] ding]# bash 14.sh

input:1990

Ping year

[Email protected] ding]# bash 14.sh

input:1997

Ping year

[Email protected] ding]#


The shell code is as follows:

#!/bin/bash



Pre_1 () {

a=${#REPLY}

[-Z $REPLY] && echo-e "\033[32m plz input! \033[0m "&& exit 0

[$a-lt 4] && echo "Plz Input more four num!" && exit 0

}


Pre_2 () {

B= ' echo $REPLY |cut-c 3-4 '

D= ' echo $REPLY |cut-c 1-2 '

c=$ (($b%100)) #判断后两位是俩0, this is a method

[$c-eq 0] && [$ ($d%4)-EQ 0] && echo "Run year" && exit 0

[$c-eq 0] && [$ ($d%4)-ne 0] && echo "Ping year" && exit 0

f=$ (($b%4))

}

Echo-n "Input:"

Read

Pre_1

Pre_2


If [$f-ne 0];then

echo "Ping Year"

Else

echo "Run Year"

Fi


This article is from the "It Life" blog, so be sure to keep this source http://dingxue.blog.51cto.com/12290895/1969132

Shell grooming (31) = = = A small example of common year leap year and nested loops

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.