Add tasks for all the new languages
This commit is contained in:
parent
9dc3c2bb62
commit
bba7bfd280
13208 changed files with 134745 additions and 0 deletions
15
Task/Menu/Axe/menu.axe
Normal file
15
Task/Menu/Axe/menu.axe
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
"FEE FIE"→Str1
|
||||
"HUFF AND PUFF"→Str2
|
||||
"MIRROR MIRROR"→Str3
|
||||
"TICK TOCK"→Str4
|
||||
For(I,1,4)
|
||||
Disp I▶Hex+3,":",strGet(Str1,I-1),i
|
||||
End
|
||||
Disp "NUMBER? "
|
||||
input→A
|
||||
{A}-'0'→N
|
||||
If N<1 or N>4
|
||||
Disp "BAD NUMBER",i
|
||||
Return
|
||||
End
|
||||
Disp strGet(Str1,N-1),i
|
||||
22
Task/Menu/Ceylon/menu.ceylon
Normal file
22
Task/Menu/Ceylon/menu.ceylon
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
"Run the module `menu`."
|
||||
shared void run() {
|
||||
value selection = menu("fee fie", "huff And puff", "mirror mirror", "tick tock");
|
||||
print(selection);
|
||||
}
|
||||
|
||||
String menu(String* strings) {
|
||||
if(strings.empty) {
|
||||
return "";
|
||||
}
|
||||
value entries = map(zipEntries(1..strings.size, strings));
|
||||
while(true) {
|
||||
for(index->string in entries) {
|
||||
print("``index``) ``string``");
|
||||
}
|
||||
process.write("> ");
|
||||
value input = process.readLine();
|
||||
if(exists input, exists int = parseInteger(input), exists string = entries[int]) {
|
||||
return string;
|
||||
}
|
||||
}
|
||||
}
|
||||
16
Task/Menu/ERRE/menu.erre
Normal file
16
Task/Menu/ERRE/menu.erre
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
PROCEDURE Selection(choices$[],prompt$->sel$)
|
||||
IF UBOUND(choices$,1)-LBOUND(choices$,1)=0 THEN
|
||||
sel$=""
|
||||
EXIT PROCEDURE
|
||||
END IF
|
||||
ret$=""
|
||||
REPEAT
|
||||
FOR i=LBOUND(choices$,1) TO UBOUND(choices$,1) DO
|
||||
PRINT(i;": ";choices$[i])
|
||||
END FOR
|
||||
PRINT(prompt$;)
|
||||
INPUT(index)
|
||||
IF index<=UBOUND(choices$,1) AND index>=LBOUND(choices$,1) THEN ret$=choices$[index] END IF
|
||||
UNTIL ret$<>""
|
||||
sel$=ret$
|
||||
END PROCEDURE
|
||||
22
Task/Menu/Nim/menu.nim
Normal file
22
Task/Menu/Nim/menu.nim
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
import strutils, rdstdin
|
||||
|
||||
proc menu(xs) =
|
||||
for i,x in xs: echo " ",i,") ",x
|
||||
|
||||
proc ok(reply, count): bool =
|
||||
try:
|
||||
let n = parseInt(reply)
|
||||
return 0 <= n and n < count
|
||||
except: return false
|
||||
|
||||
proc selector(xs, prompt): string =
|
||||
if xs.len == 0: return ""
|
||||
var reply = "-1"
|
||||
while not ok(reply, xs.len):
|
||||
menu(xs)
|
||||
reply = readLineFromStdin(prompt).strip()
|
||||
return xs[parseInt(reply)]
|
||||
|
||||
const xs = ["fee fie", "huff and puff", "mirror mirror", "tick tock"]
|
||||
let item = selector(xs, "Which is from the three pigs: ")
|
||||
echo "You chose: ", item
|
||||
23
Task/Menu/Phix/menu.phix
Normal file
23
Task/Menu/Phix/menu.phix
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
function menu_select(sequence items, object prompt)
|
||||
sequence res
|
||||
integer nres
|
||||
if length(items)=0 then return 0 end if
|
||||
while 1 do
|
||||
for i = 1 to length(items) do
|
||||
printf(1,"%d) %s\n",{i,items[i]})
|
||||
end for
|
||||
|
||||
puts(1,iff(atom(prompt)?"Choice?":prompt))
|
||||
res = scanf(trim(gets(0)),"%d")
|
||||
puts(1,"\n")
|
||||
if length(res)=1 then
|
||||
nres = res[1][1]
|
||||
if nres>0 and nres<=length(items) then exit end if
|
||||
end if
|
||||
end while
|
||||
return nres
|
||||
end function
|
||||
|
||||
constant items = {"fee fie", "huff and puff", "mirror mirror", "tick tock"}
|
||||
integer n = menu_select(items,"Which is from the three pigs? ")
|
||||
printf(1,"You chose %d(%s).\n",{n,items[n]})
|
||||
19
Task/Menu/Ring/menu.ring
Normal file
19
Task/Menu/Ring/menu.ring
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
aList = ["fee fie", "huff and puff", "mirror mirror", "tick tock"]
|
||||
selected = menu(aList, "please make a selection: ")
|
||||
see "" + selected + nl
|
||||
|
||||
func menu aList, prompt
|
||||
ndex = 1
|
||||
while index>0 and index<=len(aList)
|
||||
for index = 1 to len(aList)
|
||||
if aList[index]!="" see "" + index + " : " + aList[index] + " " ok
|
||||
next
|
||||
see nl
|
||||
see prompt
|
||||
give select
|
||||
index = number(select)
|
||||
see "" + aList[index] + nl
|
||||
if select!=string(index) index = -1 ok
|
||||
if index>=0 if index<=len(aList) if aList[index]="" index = -1 ok ok ok
|
||||
end
|
||||
return aList[index]
|
||||
17
Task/Menu/Sidef/menu.sidef
Normal file
17
Task/Menu/Sidef/menu.sidef
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
func menu (prompt, arr) {
|
||||
arr.len > 0 || return ''
|
||||
loop {
|
||||
for i in ^arr {
|
||||
say " #{i}: #{arr[i]}"
|
||||
}
|
||||
var n = Sys.scanln(prompt) \\ return()
|
||||
n ~~ /^[0-9]+\z/ ? Num(n) : next
|
||||
arr.exists(n) && return arr[n]
|
||||
}
|
||||
}
|
||||
|
||||
var list = ['fee fie', 'huff and puff', 'mirror mirror', 'tick tock']
|
||||
var prompt = 'Please choose an item number: '
|
||||
|
||||
var answer = menu(prompt, list)
|
||||
say "You choose: #{answer}"
|
||||
37
Task/Menu/Ursa/menu.ursa
Normal file
37
Task/Menu/Ursa/menu.ursa
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
def _menu (string<> items)
|
||||
for (decl int i) (< i (size items)) (inc i)
|
||||
out " " i ") " items<i> endl console
|
||||
end for
|
||||
end _menu
|
||||
|
||||
def _ok (string reply, int itemcount)
|
||||
try
|
||||
decl int n
|
||||
set n (int reply)
|
||||
return (and (or (> n 0) (= n 0)) (< n itemcount))
|
||||
catch
|
||||
return false
|
||||
end try
|
||||
end _ok
|
||||
|
||||
def selector (string<> items, string prompt)
|
||||
# Prompt to select an item from the items
|
||||
if (= (size items) 0)
|
||||
return ""
|
||||
end if
|
||||
decl int itemcount reply
|
||||
set reply -1
|
||||
set itemcount (size items)
|
||||
while (not (_ok reply itemcount))
|
||||
_menu items
|
||||
out prompt console
|
||||
set reply (in int console)
|
||||
end while
|
||||
return items<(int reply)>
|
||||
end selector
|
||||
|
||||
decl string<> items
|
||||
append "fee fie" "huff and puff" "mirror mirror" "tick tock" items
|
||||
decl string item
|
||||
set item (selector items "Which is from the three pigs: ")
|
||||
out "You chose: " item endl console
|
||||
19
Task/Menu/jq/menu-1.jq
Normal file
19
Task/Menu/jq/menu-1.jq
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
def choice:
|
||||
def read(prompt; max):
|
||||
def __read__:
|
||||
prompt,
|
||||
( input as $input
|
||||
| if ($input|type) == "number" and 0 < $input and $input <= max then $input
|
||||
else __read__
|
||||
end);
|
||||
__read__;
|
||||
|
||||
if length == 0 then ""
|
||||
else
|
||||
. as $in
|
||||
| ("Enter your choice:\n" +
|
||||
(reduce range(0; length) as $i (""; . + "\($i + 1): \($in[$i])\n")) ) as $prompt
|
||||
| read($prompt; length) as $read
|
||||
| if ($read|type) == "string" then $read
|
||||
else "Thank you for selecting \($in[$read-1])" end
|
||||
end ;
|
||||
1
Task/Menu/jq/menu-2.jq
Normal file
1
Task/Menu/jq/menu-2.jq
Normal file
|
|
@ -0,0 +1 @@
|
|||
["fee fie", "huff and puff", "mirror mirror", "tick tock"] | choice
|
||||
16
Task/Menu/jq/menu-3.jq
Normal file
16
Task/Menu/jq/menu-3.jq
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
$ jq -n -r -f Menu.jq
|
||||
Enter your choice:
|
||||
1: fee fie
|
||||
2: huff and puff
|
||||
3: mirror mirror
|
||||
4: tick tock
|
||||
|
||||
5
|
||||
Enter your choice:
|
||||
1: fee fie
|
||||
2: huff and puff
|
||||
3: mirror mirror
|
||||
4: tick tock
|
||||
|
||||
1
|
||||
Thank you for selecting fee fie
|
||||
Loading…
Add table
Add a link
Reference in a new issue