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
|
|
@ -0,0 +1,14 @@
|
|||
(lib 'struct) ;; tables are based upon structures
|
||||
(lib 'sql) ;; sql-select function
|
||||
|
||||
;; input table
|
||||
(define emps (make-table (struct emp (name id salary dept))))
|
||||
;; output table
|
||||
(define high (make-table (struct out (dept name salary))))
|
||||
|
||||
;; sort/group procedure
|
||||
(define (get-high num-records: N into: high)
|
||||
(sql-select emp.dept emp.name emp.salary
|
||||
from emps
|
||||
group-by emp.dept
|
||||
order-by emp.salary desc limit N into high))
|
||||
|
|
@ -0,0 +1,39 @@
|
|||
(define emps_file
|
||||
'(("Tyler Bennett" E10297 32000 D101)
|
||||
("John Rappl" E21437 47000 D050)
|
||||
("George Woltman" E00127 53500 D101)
|
||||
("Adam Smith" E63535 18000 D202)
|
||||
("Claire Buckman" E39876 27800 D202)
|
||||
("David McClellan" E04242 41500 D101)
|
||||
("Rich Holcomb" E01234 49500 D202)
|
||||
("Simon Gallubert" E00000 42 D666)
|
||||
("Nathan Adams" E41298 21900 D050)
|
||||
("Richard Potter" E43128 15900 D101)
|
||||
("David Motsinger" E27002 19250 D202)
|
||||
("Tim Sampair" E03033 27000 D101)
|
||||
("Kim Arlich" E10001 57000 D190)
|
||||
("Timothy Grove" E16398 29900 D190)))
|
||||
|
||||
(list->table emps_file emps ) ;; load the table
|
||||
|
||||
(get-high 2 high)
|
||||
(table-print high)
|
||||
|
||||
[0] D050 John Rappl 47000
|
||||
[1] D050 Nathan Adams 21900
|
||||
[2] D101 George Woltman 53500
|
||||
[3] D101 David McClellan 41500
|
||||
[4] D190 Kim Arlich 57000
|
||||
[5] D190 Timothy Grove 29900
|
||||
[6] D202 Rich Holcomb 49500
|
||||
[7] D202 Claire Buckman 27800
|
||||
[8] D666 Simon Gallubert 42
|
||||
|
||||
(sql-delete from high)
|
||||
(get-high 1 high)
|
||||
(table-print high)
|
||||
[0] D050 John Rappl 47000
|
||||
[1] D101 George Woltman 53500
|
||||
[2] D190 Kim Arlich 57000
|
||||
[3] D202 Rich Holcomb 49500
|
||||
[4] D666 Simon Gallubert 42
|
||||
27
Task/Top-rank-per-group/FunL/top-rank-per-group.funl
Normal file
27
Task/Top-rank-per-group/FunL/top-rank-per-group.funl
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
data Employee( name, id, salary, dept )
|
||||
|
||||
employees = [
|
||||
Employee( 'Tyler Bennett', 'E10297', 32000, 'D101' ),
|
||||
Employee( 'John Rappl', 'E21437', 47000, 'D050' ),
|
||||
Employee( 'George Woltman', 'E00127', 53500, 'D101' ),
|
||||
Employee( 'Adam Smith', 'E63535', 18000, 'D202' ),
|
||||
Employee( 'Claire Buckman', 'E39876', 27800, 'D202' ),
|
||||
Employee( 'David McClellan', 'E04242', 41500, 'D101' ),
|
||||
Employee( 'Rich Holcomb', 'E01234', 49500, 'D202' ),
|
||||
Employee( 'Nathan Adams', 'E41298', 21900, 'D050' ),
|
||||
Employee( 'Richard Potter', 'E43128', 15900, 'D101' ),
|
||||
Employee( 'David Motsinger', 'E27002', 19250, 'D202' ),
|
||||
Employee( 'Tim Sampair', 'E03033', 27000, 'D101' ),
|
||||
Employee( 'Kim Arlich', 'E10001', 57000, 'D190' ),
|
||||
Employee( 'Timothy Grove', 'E16398', 29900, 'D190' )
|
||||
]
|
||||
|
||||
N = 2
|
||||
|
||||
for (dept, empl) <- employees.groupBy( e -> e.dept ).>toList().sortWith( (<) )
|
||||
println( dept )
|
||||
|
||||
for e <- empl.sortWith( \a, b -> a.salary > b.salary ).take( N )
|
||||
printf( " %-16s %6s %7d\n", e.name, e.id, e.salary )
|
||||
|
||||
println()
|
||||
39
Task/Top-rank-per-group/Nim/top-rank-per-group.nim
Normal file
39
Task/Top-rank-per-group/Nim/top-rank-per-group.nim
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
import algorithm
|
||||
|
||||
type Record = tuple[name, id: string, salary: int, department: string]
|
||||
|
||||
var people: seq[Record] =
|
||||
@[("Tyler Bennett", "E10297", 32000, "D101"),
|
||||
("John Rappl", "E21437", 47000, "D050"),
|
||||
("George Woltman", "E00127", 53500, "D101"),
|
||||
("Adam Smith", "E63535", 18000, "D202"),
|
||||
("Claire Buckman", "E39876", 27800, "D202"),
|
||||
("David McClellan", "E04242", 41500, "D101"),
|
||||
("Rich Holcomb", "E01234", 49500, "D202"),
|
||||
("Nathan Adams", "E41298", 21900, "D050"),
|
||||
("Richard Potter", "E43128", 15900, "D101"),
|
||||
("David Motsinger", "E27002", 19250, "D202"),
|
||||
("Tim Sampair", "E03033", 27000, "D101"),
|
||||
("Kim Arlich", "E10001", 57000, "D190"),
|
||||
("Timothy Grove", "E16398", 29900, "D190")]
|
||||
|
||||
proc pcmp(a, b): int =
|
||||
result = cmp(a.department, b.department)
|
||||
if result != 0: return
|
||||
result = cmp(b.salary, a.salary)
|
||||
|
||||
proc top(n) =
|
||||
sort(people, pcmp)
|
||||
|
||||
var rank = 0
|
||||
for i, p in people:
|
||||
if i > 0 and p.department != people[i-1].department:
|
||||
rank = 0
|
||||
echo ""
|
||||
|
||||
if rank < n:
|
||||
echo p.department," ",p.salary," ",p.name
|
||||
|
||||
inc rank
|
||||
|
||||
top(2)
|
||||
27
Task/Top-rank-per-group/Oforth/top-rank-per-group.oforth
Normal file
27
Task/Top-rank-per-group/Oforth/top-rank-per-group.oforth
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
Object Class new: Employee(name, id, salary, dep)
|
||||
|
||||
Employee method: initialize := dep := salary := id := name ;
|
||||
Employee method: salary @salary ;
|
||||
Employee method: dep @dep ;
|
||||
Employee method: << "[" << @dep << "," << @name << "," << @salary << "]" << ;
|
||||
|
||||
: topRank(n)
|
||||
| employees |
|
||||
ListBuffer new ->employees
|
||||
|
||||
Employee new("Tyler Bennett", "E10297", 32000, "D101") employees add
|
||||
Employee new("John Rappl", "E21437", 47000, "D050") employees add
|
||||
Employee new("George Woltman", "E00127", 53500, "D101") employees add
|
||||
Employee new("Adam Smith", "E63535", 18000, "D202") employees add
|
||||
Employee new("Claire Buckman", "E39876", 27800, "D202") employees add
|
||||
Employee new("David McClellan", "E04242", 41500, "D101") employees add
|
||||
Employee new("Rich Holcomb", "E01234", 49500, "D202") employees add
|
||||
Employee new("Nathan Adams", "E41298", 21900, "D050") employees add
|
||||
Employee new("Richard Potter", "E43128", 15900, "D101") employees add
|
||||
Employee new("David Motsinger", "E27002", 19250, "D202") employees add
|
||||
Employee new("Tim Sampair", "E03033", 27000, "D101") employees add
|
||||
Employee new("Kim Arlich", "E10001", 57000, "D190") employees add
|
||||
Employee new("Timothy Grove", "E16398", 29900, "D190") employees add
|
||||
|
||||
#dep employees sortBy groupWith( #dep )
|
||||
map(#[ sortBy(#[ salary neg ]) left(n) ]) apply(#println) ;
|
||||
28
Task/Top-rank-per-group/Sidef/top-rank-per-group.sidef
Normal file
28
Task/Top-rank-per-group/Sidef/top-rank-per-group.sidef
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
var data = <<'EOF'.lines.map{ (var h = Hash()){<name id salary dept>} = .split(',')...; h }
|
||||
Tyler Bennett,E10297,32000,D101
|
||||
John Rappl,E21437,47000,D050
|
||||
George Woltman,E00127,53500,D101
|
||||
Adam Smith,E63535,18000,D202
|
||||
Claire Buckman,E39876,27800,D202
|
||||
David McClellan,E04242,41500,D101
|
||||
Rich Holcomb,E01234,49500,D202
|
||||
Nathan Adams,E41298,21900,D050
|
||||
Richard Potter,E43128,15900,D101
|
||||
David Motsinger,E27002,19250,D202
|
||||
Tim Sampair,E03033,27000,D101
|
||||
Kim Arlich,E10001,57000,D190
|
||||
Timothy Grove,E16398,29900,D190
|
||||
EOF
|
||||
|
||||
var n = (ARGV ? ARGV[0].to_i : "usage: #{__MAIN__} [n]\n".die);
|
||||
|
||||
data.map {|h| h{:dept} }.uniq.sort.each { |d|
|
||||
var es = data.grep { _{:dept} == d }.sort_by{ _{:salary}.to_num }.reverse;
|
||||
say d;
|
||||
n.times {
|
||||
es || break;
|
||||
var e = es.shift;
|
||||
printf("%-15s | %-6s | %5d\n", e{%w(name id salary)});
|
||||
}
|
||||
print "\n";
|
||||
}
|
||||
6
Task/Top-rank-per-group/jq/top-rank-per-group-1.jq
Normal file
6
Task/Top-rank-per-group/jq/top-rank-per-group-1.jq
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
{
|
||||
"Employee Name": "Tyler Bennett",
|
||||
"Employee ID": "E10297",
|
||||
"Salary": "32000",
|
||||
"Department": "D101"
|
||||
}
|
||||
10
Task/Top-rank-per-group/jq/top-rank-per-group-2.jq
Normal file
10
Task/Top-rank-per-group/jq/top-rank-per-group-2.jq
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
def top_rank_per_department(n):
|
||||
group_by(.Department)
|
||||
| reduce .[] as $dept
|
||||
([]; ($dept
|
||||
| map(.Salary)
|
||||
| sort # from least to most
|
||||
| .[length - n:] # top n salaries
|
||||
| reverse) as $max
|
||||
| ($dept[0] | .Department) as $dept
|
||||
| . + [ { "Department": $dept, "top_salaries": $max } ] );
|
||||
31
Task/Top-rank-per-group/jq/top-rank-per-group-3.jq
Normal file
31
Task/Top-rank-per-group/jq/top-rank-per-group-3.jq
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
$ jq 'top_rank_per_department(2) data.json
|
||||
[
|
||||
{
|
||||
"Department": "D050",
|
||||
"top_salaries": [
|
||||
"47000",
|
||||
"21900"
|
||||
]
|
||||
},
|
||||
{
|
||||
"Department": "D101",
|
||||
"top_salaries": [
|
||||
"53500",
|
||||
"41500"
|
||||
]
|
||||
},
|
||||
{
|
||||
"Department": "D190",
|
||||
"top_salaries": [
|
||||
"57000",
|
||||
"29900"
|
||||
]
|
||||
},
|
||||
{
|
||||
"Department": "D202",
|
||||
"top_salaries": [
|
||||
"49500",
|
||||
"27800"
|
||||
]
|
||||
}
|
||||
]
|
||||
Loading…
Add table
Add a link
Reference in a new issue