Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
28
Task/Power-set/CoffeeScript/power-set-1.coffee
Normal file
28
Task/Power-set/CoffeeScript/power-set-1.coffee
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
print_power_set = (arr) ->
|
||||
console.log "POWER SET of #{arr}"
|
||||
for subset in power_set(arr)
|
||||
console.log subset
|
||||
|
||||
power_set = (arr) ->
|
||||
result = []
|
||||
binary = (false for elem in arr)
|
||||
n = arr.length
|
||||
while binary.length <= n
|
||||
result.push bin_to_arr binary, arr
|
||||
i = 0
|
||||
while true
|
||||
if binary[i]
|
||||
binary[i] = false
|
||||
i += 1
|
||||
else
|
||||
binary[i] = true
|
||||
break
|
||||
binary[i] = true
|
||||
result
|
||||
|
||||
bin_to_arr = (binary, arr) ->
|
||||
(arr[i] for i of binary when binary[arr.length - i - 1])
|
||||
|
||||
print_power_set []
|
||||
print_power_set [4, 2, 1]
|
||||
print_power_set ['dog', 'c', 'b', 'a']
|
||||
29
Task/Power-set/CoffeeScript/power-set-2.coffee
Normal file
29
Task/Power-set/CoffeeScript/power-set-2.coffee
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
> coffee power_set.coffee
|
||||
POWER SET of
|
||||
[]
|
||||
POWER SET of 4,2,1
|
||||
[]
|
||||
[ 1 ]
|
||||
[ 2 ]
|
||||
[ 2, 1 ]
|
||||
[ 4 ]
|
||||
[ 4, 1 ]
|
||||
[ 4, 2 ]
|
||||
[ 4, 2, 1 ]
|
||||
POWER SET of dog,c,b,a
|
||||
[]
|
||||
[ 'a' ]
|
||||
[ 'b' ]
|
||||
[ 'b', 'a' ]
|
||||
[ 'c' ]
|
||||
[ 'c', 'a' ]
|
||||
[ 'c', 'b' ]
|
||||
[ 'c', 'b', 'a' ]
|
||||
[ 'dog' ]
|
||||
[ 'dog', 'a' ]
|
||||
[ 'dog', 'b' ]
|
||||
[ 'dog', 'b', 'a' ]
|
||||
[ 'dog', 'c' ]
|
||||
[ 'dog', 'c', 'a' ]
|
||||
[ 'dog', 'c', 'b' ]
|
||||
[ 'dog', 'c', 'b', 'a' ]
|
||||
Loading…
Add table
Add a link
Reference in a new issue