Data update
This commit is contained in:
parent
4d5544505c
commit
4924dd0264
3073 changed files with 55820 additions and 4408 deletions
|
|
@ -0,0 +1,3 @@
|
|||
(let ((table (rosetta-code-hash-from-two-arrays #(foo bar baz) #(123 456 789))))
|
||||
(loop for key being the hash-keys of table do
|
||||
(format t "~a => ~a~%" key (gethash key table))))
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
create or replace function keys_values_object( keys, values ) as (
|
||||
list_transform( keys, (k,i) -> json_object(k, json_extract(values, i-1)))
|
||||
.list_reduce( (acc,x) -> json_merge_patch(acc, x))
|
||||
);
|
||||
38
Task/Hash-from-two-arrays/EasyLang/hash-from-two-arrays.easy
Normal file
38
Task/Hash-from-two-arrays/EasyLang/hash-from-two-arrays.easy
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
hashsz = 9973
|
||||
len hashind$[] hashsz
|
||||
len hashv$[] hashsz
|
||||
#
|
||||
func hstrind key$ .
|
||||
for c$ in strchars key$
|
||||
c = strcode c$
|
||||
h = bitxor c h
|
||||
h = bitand (h * 16777619) 0xffffffff
|
||||
.
|
||||
return h mod1 hashsz
|
||||
.
|
||||
func$ hget key$ .
|
||||
hi = hstrind key$
|
||||
repeat
|
||||
if hashind$[hi] = key$ : return hashv$[hi]
|
||||
until hashind$[hi] = ""
|
||||
hi = hi mod hashsz + 1
|
||||
.
|
||||
return ""
|
||||
.
|
||||
proc hset key$ val$ .
|
||||
hi = hstrind key$
|
||||
while hashind$[hi] <> "" and hashind$[hi] <> key$
|
||||
hi = hi mod hashsz + 1
|
||||
.
|
||||
hashind$[hi] = key$
|
||||
hashv$[hi] = val$
|
||||
.
|
||||
#
|
||||
keys$[] = [ "Bob" "Alice" "Trudy" ]
|
||||
vals$[] = [ "555-1234" "555-2323" "555-6666" ]
|
||||
for i to len keys$[]
|
||||
hset keys$[i] vals$[i]
|
||||
.
|
||||
for i to len keys$[]
|
||||
print hget keys$[i]
|
||||
.
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
keys: ["a","b","c"]$
|
||||
vals: [1,2,3]$
|
||||
for i from 1 thru length(keys) do(hash[keys[i]]: vals[i])$
|
||||
arrayinfo(hash);
|
||||
listarray(hash);
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
local countries = {"Denmark", "Norway", "Italy", "Spain", "China", "Japan", "Egypt", "Algeria"}
|
||||
local cities = {"Copenhagen", "Oslo", "Rome", "Madrid", "Beijing", "Tokyo", "Cairo", "Algiers"}
|
||||
local capitals = {}
|
||||
for i = 1, 8 do capitals[countries[i]] = cities[i] end
|
||||
for k, v in capitals do print(k, v) end
|
||||
|
|
@ -1,10 +1,27 @@
|
|||
package require Tcl 8.5
|
||||
|
||||
set keys [list fred bob joe]
|
||||
set values [list barber plumber tailor]
|
||||
|
||||
foreach a $keys b $values {
|
||||
dict set jobs $a $b
|
||||
proc lzip {l1 l2} {
|
||||
set zipped {}
|
||||
foreach x $l1 y $l2 {
|
||||
lappend zipped $x $y
|
||||
}
|
||||
return $zipped
|
||||
}
|
||||
|
||||
puts "jobs: [dict get $jobs]"
|
||||
proc search {arr key} {
|
||||
set k_idx [lsearch $arr $key]
|
||||
if {$k_idx ne -1} {
|
||||
set v_idx [expr {$k_idx + 1}]
|
||||
return [lindex $arr $v_idx]
|
||||
} else {
|
||||
return {}
|
||||
}
|
||||
}
|
||||
set a {1 2 3 4}
|
||||
set b {a b c d}
|
||||
|
||||
set arr [lzip $a $b]
|
||||
|
||||
puts "\{$arr\}\n"
|
||||
|
||||
set res [search $arr 3]
|
||||
|
||||
puts "$res"
|
||||
|
|
|
|||
10
Task/Hash-from-two-arrays/Tcl/hash-from-two-arrays-3.tcl
Normal file
10
Task/Hash-from-two-arrays/Tcl/hash-from-two-arrays-3.tcl
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
package require Tcl 8.5
|
||||
|
||||
set keys [list fred bob joe]
|
||||
set values [list barber plumber tailor]
|
||||
|
||||
foreach a $keys b $values {
|
||||
dict set jobs $a $b
|
||||
}
|
||||
|
||||
puts "jobs: [dict get $jobs]"
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
keys=( foo bar baz )
|
||||
values=( 123 456 789 )
|
||||
declare -A hash
|
||||
typeset -A hash
|
||||
|
||||
for (( i = 0; i < ${#keys[@]}; i++ )); do
|
||||
hash["${keys[i]}"]=${values[i]}
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
keys=( foo bar baz )
|
||||
values=( 123 456 789 )
|
||||
declare -A hash
|
||||
|
||||
for i in {1..$#keys}; do
|
||||
hash[$keys[i]]=$values[i]
|
||||
done
|
||||
|
||||
printf '%s => %s\n' "${(kv@)hash}"
|
||||
Loading…
Add table
Add a link
Reference in a new issue