How to split the String in Oracle 9i - oracle9i

Can any body help me out to solve this issue, I need to split the String using oracle 9i
String exp=" Employee Number * Pay + Years of Experience"
My Expected output is after parsing "Employee Number" "Pay" "Years of Experience".
Is it possible to do in oracle 9i Query, Thanks a ton in advance

select substr('Employee * Pay + Years of experience',1,instr('Employee * Pay + Years of experience','*')-2),substr('Employee * Pay + Years of experience',instr('Employee * Pay + Years of experience','*')+1,length('Employee * Pay + Years of experience')-instr('Employee * Pay + Years of experience','*')-21),substr('Employee * Pay + Years of experience',instr('Employee * Pay + Years of experience','+')+1) from dual;

A straight-forward answer would be to use SUBSTR and INSTR function. Here's an example:
select substr('Employee * Pay + Years', 1, instr('Employee * Pay + Years', '*') - 2),
substr('Employee * Pay + Years', instr('Employee * Pay + Years', '*') + 2,
instr('Employee * Pay + Years', '+') - instr('Employee * Pay + Years', '*') - 3),
substr('Employee * Pay + Years', instr('Employee * Pay + Years', '+') + 2)
from dual
Work your way to what you need from there. :)

select substr('Employee * Pay + Years of experience', 1, instr('Employee * Pay + Years of experiece', '*') - 2),substr('Employee * Pay + Years of experience',instr('Employee * Pay + Years of experiece', '*') + 2,instr('Employee * Pay + Years of experience', '+') - instr('Employee * Pay + Years of experiece','*')-3),substr('Employee * Pay + Years of experience', instr('Employee * Pay + Years of experience', '+') + 2)from dual;

Related

Pretty print Expressions in Drake

Is there some built in function to print expressions in a readable way? For example, this expression;
<Expression "( - (x(2) * (2 * (x(0) * P(0,0)) + (x(1) * P(1,0)) + (x(1) * P(0,1)) + (x(2) * P(2,0)) + (x(2) * P(0,2)) + (x(3) * P(3,0)) + (x(3) * P(0,3)) + 2 * (lambda(0) * Q(0,0)) + 2 * (lambda(1) * Q(0,1)))) - (x(3) * ((x(0) * P(1,0)) + (x(0) * P(0,1)) + 2 * (x(1) * P(1,1)) + (x(2) * P(2,1)) + (x(2) * P(1,2)) + (x(3) * P(3,1)) + (x(3) * P(1,3)) + 2 * (lambda(0) * Q(1,0)) + 2 * (lambda(1) * Q(1,1)))) - ((9.8000000000000007 * x(1) + (x(0) * K(0)) + (x(1) * K(1)) + (x(2) * K(2)) + (x(3) * K(3))) * ((x(0) * P(2,0)) + (x(0) * P(0,2)) + (x(1) * P(2,1)) + (x(1) * P(1,2)) + 2 * (x(2) * P(2,2)) + (x(3) * P(3,2)) + (x(3) * P(2,3)) + 2 * (lambda(0) * Q(2,0)) + 2 * (lambda(1) * Q(2,1)))) - ((19.600000000000001 * x(1) + lambda(0) - lambda(1) + (x(0) * K(0)) + (x(1) * K(1)) + (x(2) * K(2)) + (x(3) * K(3))) * ((x(0) * P(3,0)) + (x(0) * P(0,3)) + (x(1) * P(3,1)) + (x(1) * P(1,3)) + (x(2) * P(3,2)) + (x(2) * P(2,3)) + 2 * (x(3) * P(3,3)) + 2 * (lambda(0) * Q(3,0)) + 2 * (lambda(1) * Q(3,1)))))">
Would be a lot easier to see if it was organized by the matrix and variable dot products.
If you're working in a notebook workflow, then we have a ToLatex method.
My favorite way to use it is, e.g.:
from IPython.display import Markdown, display
from pydrake.all import ToLatex, MultibodyPlant, Parser
from underactuated import FindResource, ManipulatorEquations
plant = MultibodyPlant(time_step=0)
parser = Parser(plant)
parser.AddModelFromFile(FindResource("models/double_pendulum.urdf"))
plant.Finalize()
# Evaluate the dynamics numerically
q = [0.1, 0.1]
v = [1, 1]
(M, Cv, tauG, B, tauExt) = ManipulatorDynamics(plant, q, v)
display(Markdown("$M = " + ToLatex(M, precision=2) + "$"))
display(Markdown("$Cv = " + ToLatex(Cv, precision=2) + "$"))
display(Markdown("$\\tau_G = " + ToLatex(tauG, precision=2) + "$"))
display(Markdown("$B = " + ToLatex(B, precision=2) + "$"))
display(Markdown("$\\tau_{ext} = " + ToLatex(tauExt, precision=2) + "$"))
as seen in the intro chapter notebook from my underactuated course notes: https://deepnote.com/project/52e7e101-429f-4aef-a373-e4cca7980cfe/%2Fintro.ipynb

How to shorten multiple If with ascending index of named ranges

I have a Google Spreadsheets formula like this with two named range: RangeA and RangeB.
=(1+VLOOKUP($A2,Test!RangeA,2,0)) * VLOOKUP($A2,Test!RangeA,3,0)
+ if(B2>=11,(index(Test!RangeB,1,2) - 1) * ((1+vlookup($A2,Test!RangeA,2,0))^(index(Test!RangeB,1,1)-1)) * vlookup($A2,Test!RangeA,3,0),0)
+ if(B2>=21,(index(Test!RangeB,2,2) - 1) * ((1+vlookup($A2,Test!RangeA,2,0))^(index(Test!RangeB,2,1)-1)) * vlookup($A2,Test!RangeA,3,0),0)
+ if(B2>=41,(index(Test!RangeB,3,2) - 1) * ((1+vlookup($A2,Test!RangeA,2,0))^(index(Test!RangeB,3,1)-1)) * vlookup($A2,Test!RangeA,3,0),0)
+ if(B2>=61,(index(Test!RangeB,4,2) - 1) * ((1+vlookup($A2,Test!RangeA,2,0))^(index(Test!RangeB,4,1)-1)) * vlookup($A2,Test!RangeA,3,0),0)
+ if(B2>=81,(index(Test!RangeB,5,2) - 1) * ((1+vlookup($A2,Test!RangeA,2,0))^(index(Test!RangeB,5,1)-1)) * vlookup($A2,Test!RangeA,3,0),0)
https://docs.google.com/spreadsheets/d/1_4Xc8PMXjUVuI2SXY3QgkqrYQn3xc922bYJjH0KHX2Q/edit?usp=sharing
The problem is: it contains many long if (it is much longer than the example above) which I think could be shortened since it increases the index 1 row per time. Please help.
Replace the INDEX with:
vlookup(row(indirect("1:"&match(B2,index(Test!RangeB,0,1)))),{row(Test!RangeB)-min(row(Test!RangeB))+1,Test!RangeB},3,false)
Keep the first IF and get rid of the rest:
=(1+VLOOKUP($A2,Test!RangeA,2,0)) * VLOOKUP($A2,Test!RangeA,3,0)
+ if(B2>=11,sumproduct((vlookup(row(indirect("1:"&match(B2,index(Test!RangeB,0,1)))),{row(Test!RangeB)-min(row(Test!RangeB))+1,Test!RangeB},3,false) - 1) * ((1+vlookup($A2,Test!RangeA,2,0))^(vlookup(row(indirect("1:"&match(B2,index(Test!RangeB,0,1)))),{row(Test!RangeB)-min(row(Test!RangeB))+1,Test!RangeB},2,false)-1)) * vlookup($A2,Test!RangeA,3,0)),0)

Wilson Score in Rails + Add Random Number to Upvote in Postgres Select Statement

I am trying to add a randomized number to my Wilson Score select statement.
My Post model has columns 'upvotes_count' and 'downvotes_count' that get incremented and decremented according to how many upvotes and downvotes they have (duh..).
Post.select("((upvotes_count + 1 + 1.9208) / (upvotes_count + downvotes_count + 2) - " +
"1.96 * SQRT(((upvotes_count + 1) * (downvotes_count + 1)) / (upvotes_count + downvotes_count + 2) + 0.9604) / " +
"(upvotes_count + downvotes_count + 2)) / (1 + 3.8416 / (upvotes_count + downvotes_count + 2)) " +
"AS ci_lower_bound, posts.*")
.order("ci_lower_bound DESC")
Note: In theory, Wilson Score doesn't allow for cases where both upvotes_count and downvotes_count equal 0, so I cheat and add upvote and downvote to each post record. I know this is mathematical "blasphemy" so please don't hurt me math gods. Otherwise, I wouldn't get post records with zero upvotes and zero downvotes...and that sucks.
What would be ideal is to have a select statement that would add a different random number (Poisson preferably) to upvotes_count of each post to give an artificial bump to it's Wilson score so it would occasionally appear higher on the list.
Question: How do I add a different random number to upvotes_count for each post selected in my select statement?
Something like this...but obviously it doesn't work...
Post.select("((upvotes_count + 1 + random + 1.9208) / (upvotes_count + downvotes_count + 2) - " +
"1.96 * SQRT(((upvotes_count + 1 + random) * (downvotes_count + 1)) / (upvotes_count + downvotes_count + 2) + 0.9604) / " +
"(upvotes_count + random + downvotes_count + 2)) / (1 + 3.8416 / (upvotes_count + random + downvotes_count + 2)) " +
"AS ci_lower_bound, posts.*")
This answer may be blasphemy too and I'm not sure I would ever do this, but here's how you could probably do what you're asking
# app/models/post.rb
class Post < ActiveRecord::Base
def self.custom_select_query
select("((upvotes_count + 1 + #{random(100)} + 1.9208) / (upvotes_count + downvotes_count + 2) - " +
"1.96 * SQRT(((upvotes_count + 1 + #{random(99)}) * (downvotes_count + 1)) / (upvotes_count + downvotes_count + 2) + 0.9604) / " +
"(upvotes_count + #{random(98)} + downvotes_count + 2)) / (1 + 3.8416 / (upvotes_count + #{random(97)} + downvotes_count + 2)) " +
"AS ci_lower_bound, posts.*")
end
private
def self.random(max)
SecureRandom.random_number(max)
end
end
Then call it Post.custom_select_query

finding the rth term of a sequence

the question is to give a possible formula for the rth term.
i'm able to solve two questions but rest i can't seems to be of a different way or like weird.as i'm studying alevels i think there's a common rule or maybe an easy way to solve sequence related problems.i never understood sequence well enough-it's just that hard for me.
6 18 54 162
i'm able to solve it by 2*3^r
4 7 12 19
by r^2+3
but
4 12 24 40 60
i'm trying so many ways but i can't find the answer.i think there's a common rule for solving all these not much marks are there so it should be solved in an easy way but i'm not getting how to.please help
Here's a formula in R for the sequence:
g <- function(n) 6*n + 2*n^2 + 4
g(0:4)
[1] 4 12 24 40 60
Here is one way to solve this relation. First, recognize that it is quadratic as the difference is an arithmetic sequence (linear).
Then note that g(x + 1) = g(x) + 8 + 4x. Represent g(x) = a*x^2 + b*x + c.
Then:
g(x+1) = a(x+1)^2 + b(x+1) + c = g(x) + 8 + 4x = a*x^2 + b*x + c + 8 * 4x
ax^2 + 2ax + a + b*x + b + c = a*x^2 + b*x + c + 8 + 4x
Thus
2ax + a +b = 8 + 4x
As this holds for all x, it must be that 2ax = 4x or a = 2. Thus
4x + 2 + b = 8 + 4x
So b = 6. With these known, c is determined by g(0) = c = 4.

Recurrence Relation Homework Struggles

Here's the question:
Solve the recurrence by obtaining a theta bound for T(n) given that T(1) = theta(1).
T(n) = n + T(n-3)
Attempted Solution:
T(n) = T(n-6) + (n-3) + n
= T(n-9) + (n-6) + (n-3) + n
= T(n-(n-1)) + [(n-n) + (n-(n-3)) + (n-(n-6)) + ... + n]
= T(1) + [0 + 3 + 6 + ... + n]
= theta(1) = 3[1 + 2 + 3 + ... + n/3]
= theta(1) + [(n/3)(n/3 + 1)]/2
= theta(1) + (n^2+3n)/6
When I double check to see if the solution fits the recurrence, it doesn't work.
The issue was that you were getting the wrong summation.
It doesn't start at 0, since your last T function was T(n - (n-1)) , which means previous one was T(n-(n-4)). So the summation starts at 4, and goes up till n.
If you don't know how to find the summation of this, I'd suggest you look at some of the proofs from the summation formula. This is what the solution looks like.
T(n) = T(n-3) + n
= T(n-6) + (n-3) + n
= T(n-(n-1)) + [ (n-(n-4)) + (n-(n-7)) + ... + n]
= T(1) + [4 + 7 + ... + n]
= theta(1) + (4 + n) * (n - 1)/6

Resources