C RUBY-ON-RAILS MYSQL ASP.NET DEVELOPMENT RUBY .NET LINUX SQL-SERVER REGEX WINDOWS ALGORITHM ECLIPSE VISUAL-STUDIO STRING SVN PERFORMANCE APACHE-FLEX UNIT-TESTING SECURITY LINQ UNIX MATH EMAIL OOP LANGUAGE-AGNOSTIC VB6 MSBUILD

Write a loop to select all combination of variable values generating positive equation values in R Tag : r , By : Angelo Giannatos Date : November 27 2020, 04:01 AM

``````set.seed(1222)

values <- list(x = x, t = t, v = v, w = w, n = n, f = f)

eqs <- list(
a = expression(x * t - 2 * x),
b = expression(v - x^2),
c = expression(x - w*t - t*t),
d = expression((n - f)/t)
)
``````
``````samples <- 3
values.sampled <- lapply(values, sample, samples)

\$x
[1] 642.3001 563.1001 221.3001

\$t
[1] 583.9001 279.0001 749.1001

\$v
[1] 446.6001 106.7001   0.7001

\$w
[1] 636.0001 208.8001 525.5001

\$n
[1] 559.8001  28.4001 239.0001

\$f
[1] 640.4001 612.5001 790.1001
``````
``````results <- sapply(eqs, eval, envir = values.sampled)

a          b         c          d
[1,] 373754.5 -412102.82 -711657.5 -0.1380373
[2,] 155978.8 -316975.02 -135533.2 -2.0935476
[3,] 165333.3  -48973.03 -954581.8 -0.7356827
``````
``````results[results <= 0] <- NA
``````

Share :

What is the most Ruby-like way of generating every unique combination of 3 positive integers that add up to 100

Tag : ruby , By : bdurbin
Date : March 29 2020, 07:55 AM
``````(0..100).flat_map { |x| (0..100-x).map { |y| [x, y, 100-x-y] } }
#=> [[0, 0, 100], [0, 1, 99]], ..., [99, 1, 0], [100, 0, 0]]
``````
``````[[x, y, 100-x-y] for x in 0..100 for y in 0..100-x] # imaginary Ruby
``````
``````(0..100).lazy.flat_map { |x| (0..100-x).lazy.map { |y| [x, y, 100-x-y] } }
``````
``````Enumerator.new do |e|
(0..100).each { |x| (0..100-x).each { |y| e.yield([x, y, 100-x-y]) } }
end
``````

given N absolute values of integers find the combination of N/2 negative and N/2 positive values whose sum is closest to

Tag : algorithm , By : pad
Date : March 29 2020, 07:55 AM
around this issue First sort the array, then put the biggest number into negative group and put Second-biggest into positive group. set a biggest number into positive group until sum of them is more than zero. Now set an other negative number.repeat it until you set 5 negative. This is greedy algorithm. Seems your problem is np-complete, it looks like AST problem but, size of your problem is limited to 10, so you can solve it by brute force search, you just have to check C(10,5)<10^5 possibilities and this number is small for today PCs.
Also if was able to choose different size of sets, your problem was same as subset sum problem which can be solve in pseudo-polynomial time See it :1 , 2.

SQL Select Count Values negative positive and zero values

Tag : sql , By : Boyer C.
Date : March 29 2020, 07:55 AM
I wish did fix the issue.
``````SELECT
Date,
SUM(CASE WHEN Value > 0 THEN 1 ELSE 0 END) AS pos,
SUM(CASE WHEN Value < 0 THEN 1 ELSE 0 END) AS neg,
SUM(CASE WHEN Value = 0 THEN 1 ELSE 0 END) AS zero
FROM yourTable
GROUP BY Date
``````

generating a full combination of values from multiple lists in python?

Tag : python , By : Tonci Grgin
Date : March 29 2020, 07:55 AM
I think the issue was by ths following , I would like to generate a full-matrix of value combinations from multiple lists. But I don't always know how many lists will be provided, and each one can have a different length. I was able to get the answer by abusing itertools.product(), but I think it's overkill. Is there a more pythonic way?
``````result = list(itertools.product(*listoflists))
``````
``````result = [list(item) for item in result]
``````

Users enter or select either One Value or Combination of Values or All Values in UI Search screen in Oracle PL/SQL

Tag : oracle , By : afds
Date : March 29 2020, 07:55 AM
I wish this helpful for you Parameter names you use for the procedure look like column names. I suggest you not to do that as you'll get unexpected results. For example, if you put it as where fname = fname (the first fname being column name and the second one a parameter), it'll be as if you wrote where 1 = 1 (disregard nulls for this example); precede parameters' names with p_ (or whatever you find appropriate). Also, always use table aliases (e. in my example).
Then, your code might look like this:
``````procedure search_emp (p_id        in     number,
p_fname     in     varchar2,
p_lname     in     varchar2,
p_sal       in     number,
p_org       in     varchar2,
p_location  in     varchar2,
p_country   in     varchar2,
cursor1        out ref cursor)
is
begin
open cursor1 for
select e.emp_id,
e.fname,
e.lname,
e.sal,
e.org,
e.location,
e.country
from employee e
where (upper(e.fname)    like '%' || upper(p_fname)    || '%'  or p_fname    is null)
and (upper(e.lname)    like '%' || upper(p_lname)    || '%'  or p_lname    is null)
and (e.sal             = p_sal                               or p_sal      is null)
and (upper(e.org)      like '%' || upper(p_org)      || '%'  or p_org      is null)
and (upper(e.location) like '%' || upper(p_location) || '%'  or p_location is null)
and (upper(e.country)  like '%' || upper(p_country)  || '%'  or p_country  is null);
end;
``````