{"id":76,"date":"2021-09-14T20:05:26","date_gmt":"2021-09-14T11:05:26","guid":{"rendered":"https:\/\/th0x0472.net\/?p=76"},"modified":"2021-09-14T20:05:26","modified_gmt":"2021-09-14T11:05:26","slug":"hacker-rank-looping-and-skipping","status":"publish","type":"post","link":"https:\/\/th0x0472.net\/index.php\/2021\/09\/14\/76\/","title":{"rendered":"Hacker Rank: Looping and Skipping"},"content":{"rendered":"<p>Hacker Rank\u306e<a href=\"https:\/\/www.hackerrank.com\/challenges\/bash-tutorials---looping-and-skipping\/problem\" target=\"_blank\" rel=\"noopener\">\u3053\u3061\u3089\u306e\u554f\u984c<\/a>\u306b\u3064\u3044\u3066\u66f8\u3044\u3066\u307f\u305f\u3044\u3068\u601d\u3044\u307e\u3059\u3002<!--more--><\/p>\n<p>1\u304b\u308999\u307e\u3067\u306e\u5947\u6570\u30921\u884c\u306b1\u3064\u305a\u3064\u51fa\u529b\u3059\u308b\u3068\u3044\u3046\u3082\u306e\u3002\u307e\u3041\u3001<em>seq 1 2 99<\/em>\u3067\u77ac\u6bba\u3067\u3059\u3002<\/p>\n<div class=\"hcb_wrap\">\n<pre class=\"prism line-numbers lang-bash\" data-lang=\"Bash\"><code>$ seq 1 2 9\r\n1\r\n3\r\n5\r\n7\r\n9<\/code><\/pre>\n<p>\u3068\u3044\u3046\u3088\u3046\u306b\u3001<em>First<\/em> \u3068<em>Last<\/em>\u306e\u6570\u5b57\u306e\u9593\u306b\u3082\u30461\u3064\u6570\u5b57\u3092\u5165\u308c\u308b\u3068\u3001<em>Increment<\/em>\u3092\u6307\u5b9a\u3067\u304d\u307e\u3059\u3002<em>seq<\/em>\u30b3\u30de\u30f3\u30c9\u306e\u30d8\u30eb\u30d7\u306b\u66f8\u3044\u3066\u3042\u308a\u307e\u3059\u3002<\/p>\n<p>\u3082\u3046\u5c11\u3057\u554f\u984c\u306e\u8da3\u65e8\u306b\u6cbf\u3063\u305f\u89e3\u304d\u65b9\u3092\u3057\u3066\u307f\u307e\u3057\u3087\u3046\u3002<br \/>\n\u30eb\u30fc\u30d7\u3068\u30b9\u30ad\u30c3\u30d7\u3092\u3057\u308d\u3068\u3044\u3046\u554f\u984c\u306a\u306e\u3067\u30011\u304b\u3089100\u307e\u3067\u5165\u529b\u3057\u3066\u3001for\u3068\u304bwhile\u3068\u304b\u3067\u30eb\u30fc\u30d7\u3057\u306a\u304c\u3089\u5947\u6570\u306a\u3089\u51fa\u529b\u3001\u5076\u6570\u306a\u3089\u30b9\u30ad\u30c3\u30d7\u3059\u308b\u3068\u3044\u3046\u306e\u304c\u738b\u9053\u306a\u306e\u3067\u3057\u3087\u3046\u3002<\/p>\n<p>\u3053\u306e\u554f\u984c\u306f\u5165\u529b\u304c\u7121\u3044\u306e\u3067\u3001\u81ea\u529b\u30671\u304b\u3089100\u307e\u3067\u306e\u6570\u5b57\u306e\u4e26\u3073\u3092\u4f5c\u3063\u3066\u3084\u308b\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002Bash\u3067\u9023\u7d9a\u3057\u305f\u6570\u5b57\u306e\u4e26\u3073\u3092\u4f5c\u308b\u3068\u304d\u306f\u3001\u5927\u4f53\u6b21\u306e\u3088\u3046\u306b\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\n<div class=\"hcb_wrap\">\n<pre class=\"prism line-numbers lang-bash\" data-lang=\"Bash\"><code>$ echo {1..9}\r\n1 2 3 4 5 6 7 8 9<\/code><\/pre>\n<p>\u3053\u308c\u3092\u5143\u30cd\u30bf\u306b\u30eb\u30fc\u30d7\u3092\u56de\u3059\u3068\u3059\u308b\u3068\u3001\u5927\u4f53\u6b21\u306e\u3084\u308a\u65b9\u304c\u6d6e\u304b\u3073\u307e\u3059\u3002<\/p>\n<div class=\"hcb_wrap\">\n<pre class=\"prism line-numbers lang-bash\" data-lang=\"Bash\"><code>$ for i in {1..3}; do echo $i ;done\r\n1\r\n2\r\n3<\/code><\/pre>\n<div class=\"hcb_wrap\">\n<pre class=\"prism line-numbers lang-bash\" data-lang=\"Bash\"><code>$ echo {1..3} | xargs -n1 | while read i; do echo $i; done\r\n1\r\n2\r\n3<\/code><\/pre>\n<p>\u30eb\u30fc\u30d7\u3092\u56de\u3059\u306a\u3089\u3001for\u6587\u3067\u6b21\u306e\u3088\u3046\u306b\u3082\u66f8\u3051\u307e\u3059\u3002<\/p>\n<div class=\"hcb_wrap\">\n<pre class=\"prism line-numbers lang-bash\" data-lang=\"Bash\"><code>$ for ((i=1;i&lt;=3;i++));do echo $i; done\r\n1\r\n2\r\n3<\/code><\/pre>\n<p>\u3053\u3053\u3067\u5947\u6570\u3060\u3051\u51fa\u529b\u3059\u308b\u306e\u306b\u3071\u3063\u3068\u601d\u3044\u3064\u304f\u306e\u306f\u6b21\u306e\u3084\u308a\u65b9\u3067\u3059\u3002<\/p>\n<div class=\"hcb_wrap\">\n<pre class=\"prism line-numbers lang-bash\" data-lang=\"Bash\"><code>$ for i in {1..3}; do [ $(($i % 2)) -eq 1 ] &amp;&amp; echo $i ; done\r\n1\r\n3<\/code><\/pre>\n<p>if\u6587\u3092\u4f7f\u3063\u3066\u66f8\u304f\u3068\u3053\u3046\u306a\u308a\u307e\u3059\u3002<\/p>\n<div class=\"hcb_wrap\">\n<pre class=\"prism line-numbers lang-bash\" data-lang=\"Bash\"><code>$ for i in {1..3}; do \\\r\n&gt;   if [ $(expr $i % 2) -eq 1 ]; then \\\r\n&gt;     echo $i\r\n&gt;   fi \\\r\n&gt; done\r\n1\r\n3<\/code><\/pre>\n<p>\u4e0a\u306e\u4e8c\u3064\u306f\u30de\u30b8\u30e1\u306b2\u3067\u5272\u3063\u305f\u4f59\u308a\u3092\u6c42\u3081\u3066\u307e\u3057\u305f\u304c\u3001\u6c42\u3081\u306a\u304f\u3066\u3082OK\u3067\u3059\u3002<\/p>\n<div class=\"hcb_wrap\">\n<pre class=\"prism line-numbers lang-bash\" data-lang=\"Bash\"><code>$ echo {1..20} | xargs -n1 | sed -n '\/[13579]$\/p'\r\n1\r\n3\r\n5\r\n7\r\n9\r\n11\r\n13\r\n15\r\n17\r\n19<\/code><\/pre>\n<p>\u6574\u6570\u3060\u3051\u3068\u3044\u3046\u306e\u3092\u5229\u7528\u3057\u3066\u30011\u306e\u4f4d\u304c13579\u306e\u3044\u305a\u308c\u304b\u306e\u5834\u5408\u3060\u3051\u51fa\u529b\u3057\u3066\u307e\u3059\u3002<\/p>\n<p>\u3093\uff5e\u3002\u3053\u306e\u304f\u3089\u3044\u3067\u3057\u3087\u3046\u304b\u3002\u6b21\u56de\u306fseq\u30b3\u30de\u30f3\u30c9\u3092\u6398\u308a\u4e0b\u3052\u3066\u307f\u305f\u3044\u3068\u601d\u3044\u307e\u3059\u3002<br \/>\n# \u81ea\u5206\u306b\u30ce\u30eb\u30de\u3092\u8ab2\u3057\u3066\u3044\u304f\u30b9\u30bf\u30a4\u30eb\u3002<\/p>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>Hacker Rank\u306e\u3053\u3061\u3089\u306e\u554f\u984c\u306b\u3064\u3044\u3066\u66f8\u3044\u3066\u307f\u305f\u3044\u3068\u601d\u3044\u307e\u3059\u3002<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2,3],"tags":[],"class_list":["post-76","post","type-post","status-publish","format-standard","hentry","category-blog","category-hackerrank"],"_links":{"self":[{"href":"https:\/\/th0x0472.net\/index.php\/wp-json\/wp\/v2\/posts\/76","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/th0x0472.net\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/th0x0472.net\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/th0x0472.net\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/th0x0472.net\/index.php\/wp-json\/wp\/v2\/comments?post=76"}],"version-history":[{"count":1,"href":"https:\/\/th0x0472.net\/index.php\/wp-json\/wp\/v2\/posts\/76\/revisions"}],"predecessor-version":[{"id":77,"href":"https:\/\/th0x0472.net\/index.php\/wp-json\/wp\/v2\/posts\/76\/revisions\/77"}],"wp:attachment":[{"href":"https:\/\/th0x0472.net\/index.php\/wp-json\/wp\/v2\/media?parent=76"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/th0x0472.net\/index.php\/wp-json\/wp\/v2\/categories?post=76"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/th0x0472.net\/index.php\/wp-json\/wp\/v2\/tags?post=76"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}