2016 Update

This commit is contained in:
Tina Müller 2016-12-05 22:15:40 +01:00
parent 948b86eafa
commit dcf5d15da3
7965 changed files with 139854 additions and 31002 deletions

View file

@ -0,0 +1,8 @@
# syntax: GAWK -f PICK_RANDOM_ELEMENT.AWK
BEGIN {
n = split("Monday,Tuesday,Wednesday,Thursday,Friday,Saturday,Sunday",day_of_week,",")
srand()
x = int(n*rand()) + 1
printf("%s\n",day_of_week[x])
exit(0)
}

View file

@ -0,0 +1,15 @@
#import system.
#import extensions.
#class(extension)listOp
{
#method randomItem
= self @ (randomGenerator eval:(self length)).
}
#symbol program =
[
#var item := (0, 1, 2, 3, 4, 5, 6, 7, 8, 9).
console writeLine:"I picked element ":(item randomItem).
].

View file

@ -1,12 +1,6 @@
defmodule Random do
def init do
:random.seed(:erlang.now)
end
def pick_element(list) do
Enum.at(list, :random.uniform(length(list)) - 1)
end
end
Random.init
list = Enum.to_list(1..20)
IO.puts Random.pick_element(list)
iex(1)> list = Enum.to_list(1..20)
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]
iex(2)> Enum.random(list)
19
iex(3)> Enum.take_random(list,4)
[19, 20, 7, 15]

View file

@ -0,0 +1,3 @@
Random(SymmetricGroup(20));
(1,4,8,2)(3,12)(5,14,10,18,17,7,16)(9,13)(11,15,20,19)

View file

@ -0,0 +1 @@
[25, 30, 1, 450, 3, 78].sort{new Random()}?.take(1)[0]

View file

@ -1,6 +1,6 @@
import Random (randomRIO)
import System.Random (randomRIO)
pick :: [a] -> IO a
pick xs = randomRIO (0, length xs - 1) >>= return . (xs !!)
pick xs = fmap (xs !!) $ randomRIO (0, length xs - 1)
x <- pick [1 2 3]

View file

@ -1,2 +1,2 @@
array = [1,2,3]
array[rand(1:length(array))]
rand(array)

View file

@ -0,0 +1,3 @@
a := [bear, giraffe, dog, rabbit, koala, lion, fox, deer, pony]:
randomNum := rand(1 ..numelems(a)):
a[randomNum()];

View file

@ -1,5 +1,5 @@
# define the deck
constant deck = 2..9, <J Q K A> X~ <♠ ♣ ♥ ♦>;
deck.pick; # Pick a card
deck.pick(5); # Draw 5
deck.pick(*); # Get a shuffled deck
my @deck = <2 3 4 5 6 7 8 9 J Q K A> X~ <♠ ♣ ♥ ♦>;
@deck.pick; # Pick a card
@deck.pick(5); # Draw 5
@deck.pick(*); # Get a shuffled deck