These commands will install Apache and its PHP library.
sudo apt-get update
sudo apt-get install apache2
sudo apt-get install php5 libapache2-mod-php5
2015-05-18
PYTHON - Determine all possible factor combinations for a given number, from a given numeric array
Check this out at GitHub.com
https://github.com/falconerandloillc/factors
# 1. Sample call
#print( factors( 240, [2,3,4,5,6,7,8,9,10,11,12,24]
) );
# 2. The function...
|
import
time
|
def
factors(target,
arr):
|
# Parameters test/fix
|
if target == None or target == 0 or arr == None or len(arr) < 2:
|
return
None
|
# Declarer
|
start = int(round(time.time() * 1000))
|
global iterations
|
global combinations
|
iterations=0
|
combinations=[]
|
# Keep only non-zero numbers
|
arr = [x for x in arr if isinstance(x, float) or isinstance(x, int)]
|
if len(arr) <= 1:
|
return
None
|
# Sort
|
arr.sort()
|
# Recurse each array element
|
for j in range(len(arr)):
|
i =
j
|
r =
[]
|
def
recurse(v,
i):
|
global
iterations, combinations
|
while
i <
len(arr)
and
(v*arr[i-1]) < abs(target):
|
iterations += 1
|
r.append(arr[i])
|
recurse(v*arr[i], i+1)
|
i += 1
|
r.pop()
|
if
v ==
target and
len(r)
>
1:
|
combinations.append("".join(str(r)))
|
return
1
|
r.append(arr[j])
|
recurse(arr[j], j+1)
|
return {
|
"combinations": combinations
|
, "count": len(combinations)
|
, "time": str(int(round(time.time()*1000))-start) + " ms"
|
, "array": arr
|
, "target": target
|
, "iterations": iterations
|
}
|
TSQL - Company name cleanup, reducing a company's name to its essence
This can be very helpful when comparing two different lists of companies, matching them when no unique ID is available, and when the company names may be slightly different on both lists.
/*
--
Execution
select
dbo.getCompanyNameCleanForMatching( 'ABC Co. Ltd. L.L.C.');
*/
ALTER function [dbo].[getCompanyNameCleanForMatching]
(
@strCompanyName varchar(max)
)
returns varchar(max)
as
begin
return(
replace(
replace(
replace(
replace(
replace(
replace(
replace(
replace(
replace(
replace(
replace(
replace(
replace(
replace(
replace(
replace(
replace(
replace(
replace(
replace(
replace(
replace(
replace(
replace(
replace(
replace(
replace(
replace(
replace(
replace(
replace(
replace(
replace(
replace(
replace(
replace(
replace(
replace(
replace(
replace(
replace(
replace(
replace(
replace(
replace(
replace(
lower(@strCompanyName)
, '.'
, ''
)
, ','
, ''
)
, '*'
, ''
)
, '('
, ''
)
,
')'
,
''
)
,
' llc'
,
''
)
, ' incorporated'
, ''
)
, ' inc'
, ''
)
, ' limited partnership'
, ''
)
, ' lp'
, ''
)
, ' limited'
, ''
)
, ' ltd'
, ''
)
, 'corporation'
, ''
)
, ' corporate'
, ''
)
, ' corp'
, ''
)
,
'ultimate parent'
,
''
)
,
' co '
,
''
)
,
' par '
, ''
)
, 'group'
, ''
)
, 'company'
, ''
)
, 'international'
, ''
)
, 'holdings'
, ''
)
, 'communications'
, ''
)
, 'industries'
, ''
)
, 'broadcasting'
, ''
)
, 'financial'
, ''
)
, 'products'
, ''
)
, 'technologies'
, ''
)
, 'services'
, ''
)
, 'acquisition'
, ''
)
, 'systems'
, ''
)
, 'manufacturing'
, ''
)
, 'enterprises'
, ''
)
, 'entertainment'
, ''
)
, 'manufacturing'
, ''
)
, 'processing'
, ''
)
, '-dip'
, ''
)
, 'bank loan'
, ''
)
, 'cfs'
, ''
)
, 'hfs'
, ''
)
, 'cif'
, ''
)
, 'global sponsor finance'
, ''
)
, ' - '
, ''
)
, '- '
, ''
)
, ' -'
, ''
)
, '-'
, ''
)
);
end
Subscribe to:
Posts (Atom)