forked from nuprl/MultiPL-E
-
Notifications
You must be signed in to change notification settings - Fork 0
/
HumanEval_117_select_words-124-OK.sh.html
124 lines (122 loc) · 7.7 KB
/
HumanEval_117_select_words-124-OK.sh.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<!--
generated by Pygments <https://pygments.org/>
Copyright 2006-2022 by the Pygments team.
Licensed under the BSD license, see LICENSE for details.
-->
<html>
<head>
<title></title>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<style type="text/css">
/*
generated by Pygments <https://pygments.org/>
Copyright 2006-2022 by the Pygments team.
Licensed under the BSD license, see LICENSE for details.
*/
pre { line-height: 125%; }
td.linenos .normal { color: inherit; background-color: transparent; padding-left: 5px; padding-right: 5px; }
span.linenos { color: inherit; background-color: transparent; padding-left: 5px; padding-right: 5px; }
td.linenos .special { color: #000000; background-color: #ffffc0; padding-left: 5px; padding-right: 5px; }
span.linenos.special { color: #000000; background-color: #ffffc0; padding-left: 5px; padding-right: 5px; }
body .hll { background-color: #ffffcc }
body { background: #ffffff; }
body .c { color: #888888 } /* Comment */
body .err { color: #FF0000; background-color: #FFAAAA } /* Error */
body .k { color: #008800; font-weight: bold } /* Keyword */
body .o { color: #333333 } /* Operator */
body .ch { color: #888888 } /* Comment.Hashbang */
body .cm { color: #888888 } /* Comment.Multiline */
body .cp { color: #557799 } /* Comment.Preproc */
body .cpf { color: #888888 } /* Comment.PreprocFile */
body .c1 { color: #888888 } /* Comment.Single */
body .cs { color: #cc0000; font-weight: bold } /* Comment.Special */
body .gd { color: #A00000 } /* Generic.Deleted */
body .ge { font-style: italic } /* Generic.Emph */
body .gr { color: #FF0000 } /* Generic.Error */
body .gh { color: #000080; font-weight: bold } /* Generic.Heading */
body .gi { color: #00A000 } /* Generic.Inserted */
body .go { color: #888888 } /* Generic.Output */
body .gp { color: #c65d09; font-weight: bold } /* Generic.Prompt */
body .gs { font-weight: bold } /* Generic.Strong */
body .gu { color: #800080; font-weight: bold } /* Generic.Subheading */
body .gt { color: #0044DD } /* Generic.Traceback */
body .kc { color: #008800; font-weight: bold } /* Keyword.Constant */
body .kd { color: #008800; font-weight: bold } /* Keyword.Declaration */
body .kn { color: #008800; font-weight: bold } /* Keyword.Namespace */
body .kp { color: #003388; font-weight: bold } /* Keyword.Pseudo */
body .kr { color: #008800; font-weight: bold } /* Keyword.Reserved */
body .kt { color: #333399; font-weight: bold } /* Keyword.Type */
body .m { color: #6600EE; font-weight: bold } /* Literal.Number */
body .s { background-color: #fff0f0 } /* Literal.String */
body .na { color: #0000CC } /* Name.Attribute */
body .nb { color: #007020 } /* Name.Builtin */
body .nc { color: #BB0066; font-weight: bold } /* Name.Class */
body .no { color: #003366; font-weight: bold } /* Name.Constant */
body .nd { color: #555555; font-weight: bold } /* Name.Decorator */
body .ni { color: #880000; font-weight: bold } /* Name.Entity */
body .ne { color: #FF0000; font-weight: bold } /* Name.Exception */
body .nf { color: #0066BB; font-weight: bold } /* Name.Function */
body .nl { color: #997700; font-weight: bold } /* Name.Label */
body .nn { color: #0e84b5; font-weight: bold } /* Name.Namespace */
body .nt { color: #007700 } /* Name.Tag */
body .nv { color: #996633 } /* Name.Variable */
body .ow { color: #000000; font-weight: bold } /* Operator.Word */
body .w { color: #bbbbbb } /* Text.Whitespace */
body .mb { color: #6600EE; font-weight: bold } /* Literal.Number.Bin */
body .mf { color: #6600EE; font-weight: bold } /* Literal.Number.Float */
body .mh { color: #005588; font-weight: bold } /* Literal.Number.Hex */
body .mi { color: #0000DD; font-weight: bold } /* Literal.Number.Integer */
body .mo { color: #4400EE; font-weight: bold } /* Literal.Number.Oct */
body .sa { background-color: #fff0f0 } /* Literal.String.Affix */
body .sb { background-color: #fff0f0 } /* Literal.String.Backtick */
body .sc { color: #0044DD } /* Literal.String.Char */
body .dl { background-color: #fff0f0 } /* Literal.String.Delimiter */
body .sd { color: #DD4422 } /* Literal.String.Doc */
body .s2 { background-color: #fff0f0 } /* Literal.String.Double */
body .se { color: #666666; font-weight: bold; background-color: #fff0f0 } /* Literal.String.Escape */
body .sh { background-color: #fff0f0 } /* Literal.String.Heredoc */
body .si { background-color: #eeeeee } /* Literal.String.Interpol */
body .sx { color: #DD2200; background-color: #fff0f0 } /* Literal.String.Other */
body .sr { color: #000000; background-color: #fff0ff } /* Literal.String.Regex */
body .s1 { background-color: #fff0f0 } /* Literal.String.Single */
body .ss { color: #AA6600 } /* Literal.String.Symbol */
body .bp { color: #007020 } /* Name.Builtin.Pseudo */
body .fm { color: #0066BB; font-weight: bold } /* Name.Function.Magic */
body .vc { color: #336699 } /* Name.Variable.Class */
body .vg { color: #dd7700; font-weight: bold } /* Name.Variable.Global */
body .vi { color: #3333BB } /* Name.Variable.Instance */
body .vm { color: #996633 } /* Name.Variable.Magic */
body .il { color: #0000DD; font-weight: bold } /* Literal.Number.Integer.Long */
</style>
</head>
<body>
<h2></h2>
<div class="highlight"><pre><span></span><span class="ch">#!/bin/bash</span>
<span class="c1"># Given a string s and a natural number n, you have been tasked to implement </span>
<span class="c1"># a function that returns a list of all words from string s that contain</span>
<span class="c1"># exactly n consonants, in order these words appear in the string s.</span>
<span class="c1"># If the string s is empty then the function should return an empty list.</span>
<span class="c1"># Note: you may assume the input string contains only letters and spaces.</span>
<span class="c1">#</span>
<span class="c1"># $1 is a string</span>
<span class="c1"># $2 is an integer</span>
select_words<span class="o">()</span> <span class="o">{</span>
<span class="nb">local</span> <span class="nv">s</span><span class="o">=</span><span class="nv">$1</span>
<span class="nb">local</span> <span class="nv">n</span><span class="o">=</span><span class="nv">$2</span>
<span class="nb">local</span> <span class="nv">words</span><span class="o">=(</span><span class="nv">$s</span><span class="o">)</span>
<span class="nb">local</span> <span class="nv">result</span><span class="o">=()</span>
<span class="nb">local</span> word
<span class="nb">local</span> consonants
<span class="k">for</span> word <span class="k">in</span> <span class="s2">"</span><span class="si">${</span><span class="nv">words</span><span class="p">[@]</span><span class="si">}</span><span class="s2">"</span><span class="p">;</span> <span class="k">do</span>
<span class="nv">consonants</span><span class="o">=</span><span class="k">$(</span><span class="nb">echo</span> <span class="s2">"</span><span class="nv">$word</span><span class="s2">"</span> <span class="p">|</span> grep -o <span class="s1">'[^aeiouAEIOU ]'</span> <span class="p">|</span> wc -l<span class="k">)</span>
<span class="k">if</span> <span class="o">[[</span> <span class="nv">$consonants</span> -eq <span class="nv">$n</span> <span class="o">]]</span><span class="p">;</span> <span class="k">then</span>
<span class="nv">result</span><span class="o">+=(</span><span class="s2">"</span><span class="nv">$word</span><span class="s2">"</span><span class="o">)</span>
<span class="k">fi</span>
<span class="k">done</span>
<span class="nb">echo</span> <span class="s2">"</span><span class="si">${</span><span class="nv">result</span><span class="p">[@]</span><span class="si">}</span><span class="s2">"</span>
<span class="o">}</span>
</pre></div>
</body>
</html>