September 2017 Update

This commit is contained in:
Ingy döt Net 2017-09-23 10:01:46 +02:00
parent bba7bfd280
commit ba8067c3b7
14570 changed files with 153136 additions and 63871 deletions

View file

@ -0,0 +1,10 @@
Public Sub Form_Open()
Dim sMenu As String[] = ["fee fie", "huff and puff", "mirror mirror", "tick tock"]
Dim sAnswer As String
Do
sAnswer = InputBox("0: fee fie 1: huff and puff 2: mirror mirror 3: tick tock", "Please select an number")
If InStr("0123", sAnswer) Then Message("You selected item " & sAnswer & " - " & sMenu[Val(sAnswer)], "OK")
Loop
End

View file

@ -0,0 +1,25 @@
// version 1.1.2
fun menu(list: List<String>): String {
if (list.isEmpty()) return ""
val n = list.size
while (true) {
println("\n M E N U\n")
for (i in 0 until n) println("${i + 1}: ${list[i]}")
print("\nEnter your choice 1 - $n : ")
val index = readLine()!!.toIntOrNull()
if (index == null || index !in 1..n) continue
return list[index - 1]
}
}
fun main(args: Array<String>) {
val list = listOf(
"fee fie",
"huff and puff",
"mirror mirror",
"tick tock"
)
val choice = menu(list)
println("\nYou chose : $choice")
}

View file

@ -0,0 +1,61 @@
program Menu;
{$ASSERTIONS ON}
uses
objects;
var
MenuItems :PUnSortedStrCollection;
selected :string;
Function SelectMenuItem(MenuItems :PUnSortedStrCollection):string;
var
i, idx :integer;
code :word;
choice :string;
begin
// Return empty string if the collection is empty.
if MenuItems^.Count = 0 then
begin
SelectMenuItem := '';
Exit;
end;
repeat
for i:=0 to MenuItems^.Count-1 do
begin
writeln(i+1:2, ') ', PString(MenuItems^.At(i))^);
end;
write('Make your choice: ');
readln(choice);
// Try to convert choice to an integer.
// Code contains 0 if this was successful.
val(choice, idx, code)
until (code=0) and (idx>0) and (idx<=MenuItems^.Count);
// Return the selected element.
SelectMenuItem := PString(MenuItems^.At(idx-1))^;
end;
begin
// Create an unsorted string collection for the menu items.
MenuItems := new(PUnSortedStrCollection, Init(10, 10));
// Add some menu items to the collection.
MenuItems^.Insert(NewStr('fee fie'));
MenuItems^.Insert(NewStr('huff and puff'));
MenuItems^.Insert(NewStr('mirror mirror'));
MenuItems^.Insert(NewStr('tick tock'));
// Display the menu and get user input.
selected := SelectMenuItem(MenuItems);
writeln('You chose: ', selected);
dispose(MenuItems, Done);
// Test function with an empty collection.
MenuItems := new(PUnSortedStrCollection, Init(10, 10));
selected := SelectMenuItem(MenuItems);
// Assert that the function returns an empty string.
assert(selected = '', 'Assertion failed: the function did not return an empty string.');
dispose(MenuItems, Done);
end.

View file

@ -1,11 +0,0 @@
function Get-Choice ([array] $Items) {
Set-StrictMode -Version Latest
do {
$Items | ForEach-Object { $i = 0 } { '{0,3}. {1}' -f (++$i),$_ }
$choice = Read-Host Your choice
} while ($choice -notmatch '^\d+$' -or
!(1..$Items.Length -eq $choice))
$Items[$choice-1]
}

View file

@ -1 +0,0 @@
Get-Choice 'fee fie', 'huff and puff', 'mirror mirror', 'tick tock'

View file

@ -1,23 +1,26 @@
def select(prompt, items)
return "" if items.empty?
loop do
items.each_index {|i| puts "#{i}. #{items[i]}"}
print "#{prompt}: "
begin
answer = Integer(gets)
rescue ArgumentError
redo
def select(prompt, items = [])
if items.empty?
''
else
answer = -1
until (0...items.length).cover?(answer)
items.each_with_index {|i,j| puts "#{j}. #{i}"}
print "#{prompt}: "
begin
answer = Integer(gets)
rescue ArgumentError
redo
end
end
return items[answer] if (0...items.length).cover?(answer)
items[answer]
end
end
# test empty list
response = select("Which is empty", [])
puts "empty list returns: >#{response}<"
puts
response = select('Which is empty')
puts "empty list returns: >#{response}<\n"
# "real" test
items = ['fee fie', 'huff and puff', 'mirror mirror', 'tick tock']
response = select("Which is from the three pigs", items)
response = select('Which is from the three pigs', items)
puts "you chose: >#{response}<"

13
Task/Menu/Zkl/menu.zkl Normal file
View file

@ -0,0 +1,13 @@
fcn teleprompter(options){
os:=T("exit").extend(vm.arglist); N:=os.len();
if(N==1) return("");
while(1){
Utils.zipWith(fcn(n,o){"%d) %s".fmt(n,o).println()},[0..],os);
a:=ask("Your choice: ");
try{ n:=a.toInt(); if(0<=n<N) return(os[n]); } catch{}
println("Ack, not good");
}
}
teleprompter("fee fie" , "huff and puff" , "mirror mirror" , "tick tock")
.println();