Data update
This commit is contained in:
parent
4bb20c9b71
commit
cbaf4c4b64
12390 changed files with 318560 additions and 27248 deletions
|
|
@ -0,0 +1,17 @@
|
|||
import gleam/io
|
||||
import gleam/list
|
||||
import gleam/order.{Gt, Lt}
|
||||
import in
|
||||
|
||||
pub fn main() {
|
||||
["violet", "red", "green", "indigo", "blue", "yellow", "orange"]
|
||||
|> list.sort(by: fn(a, b) {
|
||||
io.print("Is " <> a <> " > " <> b <> "? (y/n) ")
|
||||
case in.read_line() {
|
||||
Ok("y\n") -> Gt
|
||||
Ok(_) -> Lt
|
||||
Error(_) -> panic as "Error reading from standard input."
|
||||
}
|
||||
})
|
||||
|> echo
|
||||
}
|
||||
|
|
@ -0,0 +1,41 @@
|
|||
import std/core/undiv
|
||||
import std/os/readline
|
||||
|
||||
fun treesort(xs : list<string>, ?cmp: (string, string) -> e order) : e list<string>
|
||||
recur/treesort(xs, Nil)
|
||||
|
||||
fun recur/treesort(xs : list<string>, res : list<string>, ?cmp: (string, string) -> e order) : e list<string>
|
||||
match(xs)
|
||||
Cons(x, xx) ->
|
||||
val (lo, hi) = partition(x, xx)
|
||||
treesort(lo, Cons(x, treesort(hi, res.pretend-decreasing)).pretend-decreasing)
|
||||
Nil -> res
|
||||
|
||||
fun partition(^x : string, ys : list<string>, ?cmp: (string, string) -> e order)
|
||||
match(ys)
|
||||
Nil -> (Nil, Nil)
|
||||
Cons(y, yy) ->
|
||||
match ?cmp(y, x)
|
||||
Lt ->
|
||||
val (lo, hi) = partition(x, yy)
|
||||
(Cons(y, lo), hi)
|
||||
_ ->
|
||||
val (lo, hi) = partition(x, yy)
|
||||
(lo, Cons(y, hi))
|
||||
|
||||
effect ask
|
||||
fun ask(s1: string, s2: string): order
|
||||
|
||||
fun main()
|
||||
with handler
|
||||
fun ask(s1, s2)
|
||||
print("Is " ++ s1 ++ " <, =, or > " ++ s2 ++ "? ")
|
||||
var done := Nothing
|
||||
while {done.is-nothing}
|
||||
match readline()
|
||||
">" -> done := Just(Gt)
|
||||
"<" -> done := Just(Lt)
|
||||
"=" -> done := Just(Eq)
|
||||
_ -> println("Invalid input")
|
||||
done.unjust
|
||||
["violet", "red", "green", "indigo", "blue", "yellow", "orange"].treesort(?cmp=ask)
|
||||
Loading…
Add table
Add a link
Reference in a new issue