convert number to list of char - sql

I have a function who should return a letter list of alphabet.
I obtain a table with correct size with nothing inside.
My code :
CREATE OR REPLACE FUNCTION p_get_list(IN nb integer)
RETURNS TABLE(strconcat text) AS
$BODY$DECLARE
i integer;
j integer;
r integer;
strconc text;
BEGIN
j=ASCII('A');
FOR i IN 1..nb LOOP
r=j+i-1;
SELECT chr(r) INTO strconc;
RETURN NEXT;
END LOOP;
end if;
END;$BODY$
Thanks.

you can reuse existing function generate_series for it, eg:
t=# select chr(a) from generate_series(ascii('A'),ascii('A')+25,1) a;
chr
-----
A
B
C
D
E
F
G
H
I
J
K
L
M
N
O
P
Q
R
S
T
U
V
W
X
Y
Z
(26 rows)

Related

Google Cloud BigQuery

I have a set of data (x, y) where x = 1 to 5 , y = 1 to 10
e.g. extract from them one by one where (1,1),(1,2),(1,3)…(1,10)…(2,5)…(5,10)
BEGIN
DECLARE
x,y INT64 DEFAULT 0;
LOOP
SET
x = x + 1;
IF
x <= Max(x) THEN
LOOP
SET
y = y + 1;
IF
y <= Max(y) THEN
CALL
data(x,y);
ELSE
BREAK;
END IF;
END LOOP;
END IF;
END LOOP;
END
Does anyone help me ?
I think CROSS JOIN with GENERATE_ARRAY will works better for you
SELECT * FROM UNNEST(GENERATE_ARRAY(1,5)) x, UNNEST(GENERATE_ARRAY(1,10)) y
Is it?

found '0' definitions of operator "**", cannot determine exact overloaded matching definition for "**" in VHDL

I am trying to simulate the below code. However, it shows the error " found '0' definitions of operator "", cannot determine exact overloaded matching definition for "" ". I have had attached the required packages to my code. please guide me with this error. Thank you in advance.
library IEEE;
USE IEEE.std_logic_1164.all;
USE IEEE.numeric_std.all;
USE IEEE.std_logic_arith.all;
USE IEEE.math_real.all;
library IEEE_proposed;
use IEEE_proposed.fixed_pkg.all;
entity test_zp is
end;
Architecture ARCHofZP of test_zp is
TYPE matrix IS ARRAY ( NATURAL RANGE <>, NATURAL RANGE <> ) OF INTEGER RANGE 0 TO 500;
SIGNAL kernel : matrix ( 1 TO 3 , 1 TO 3 ) := ((1,0,0),(0,1,0),(1,0,1));
SIGNAL image1 : matrix ( 1 To 6 , 1 TO 6 ) := ((25,100,75,49,130,15),(50,80,0,70,100,34),(20,5,10,20,30,0),(45,60,50,12,24,32),(34,37,53,55,21,90),(45,65,55,78,20,16));
FUNCTION batchnorm (outimg : matrix ( 1 To 8 , 1 TO 8 ) ) RETURN matrix IS
VARIABLE sum1 : INTEGER RANGE 0 TO 500;
VARIABLE SD1,SD,mean,ave,sum : UFIXED (10 downto -2):= "00000000";
VARIABLE batchnorm_mat : matrix (outimg'RANGE(1), outimg'RANGE(2));
CONSTANT alpha,beta : UFIXED (1 downto -2):= "0010";
BEGIN
R1 : FOR i IN outimg'RANGE(1) LOOP
C1 : FOR j IN outimg'RANGE(2) LOOP
sum1 := sum1 + outimg(i,j);
END LOOP;
END LOOP;
mean := sum1 / outimg'LENGTH;
ave := to_ufixed(23,10,-2);
R2 : FOR i IN outimg'RANGE(1) LOOP
C2 : FOR j IN outimg'RANGE(2) LOOP
SD1 := ((to_ufixed(outimg(i,j),10,-2)-ave)/to_ufixed(outimg'LENGTH,10,-2)) + SD1;
END LOOP;
END LOOP;
SD := SD1 ** (2);
R3 : FOR i IN batchnorm_mat'RANGE(1) LOOP
C3 : FOR j IN batchnorm_mat'RANGE(2) LOOP
batchnorm_mat(i,j) := ((to_ufixed(outimg(i,j),10,-2) - ave)/(SD)) * alpha + beta ;
END LOOP;
END LOOP;
RETURN batchnorm_mat; -- return batch normalized outimg matrix named batchnorm_mat
END FUNCTION batchnorm;
begin
outimg <= zero_padding( kernel , image1 );
end Architecture ARCHofZP;

Functions written in VB6 requires helpmigrate to Delphi

i am struggling since 2 weeks to migrate my VB6 code to Delphi (with intermediate knowledge of Delphi).
As i stuck on this Function can someone please help me to convert following function (written in VB6) to Delphi: ( Thanks in advance)
Public Function ConvertIt(s As String) As Long
Dim l As Long
Dim i As Integer
l = 0
For i = 1 To Len(s)
l = l + Asc(Mid$(s, i, 1)) * 256 ^ (4 - i)
Next
ConvertIt = l
End Function
I don't know VB, but I assume that
Long is a 32-bit signed integer,
Asc(c) returns the ASCII value of the character c,
Mid$(s, i, 1) returns the ith character of s (1-based indexing), and
^ is the binary exponentiation operator.
If so, noting that 256^(4 − i) = (2^8)^(4 − i) = 2^(32 − 8*i), the Pascal equivalent would be
function ConvertIt(const S: string): Integer;
var
i: Integer;
begin
Result := 0;
for i := 1 to Length(S) do
Inc(Result, Ord(S[i]) shl (32 - 8*i))
end;

Fixing a variable in JuMP / Julia

I have an AMPL code like this:
param N;
set R := 1..N;
set V := 1..N;
initializeSendPrepareReq{i in R, v in V}: SendPrepReq[1, i, v] = 0;
I need to write it in Julia using JuMP.
N = 10
R = 1:N
V = 1:N
?
I know I probably need to use JuMP.fix() but don't know how. Thank you
for i in R, v in V
fix(SendPrepReq[1, i, v], 0)
end
If SendPrepReq has other bounds, you need
for i in R, v in V
fix(SendPrepReq[1, i, v], 0; force = true)
end
Here is the relevant documentation: https://www.juliaopt.org/JuMP.jl/stable/variables/#JuMP.fix
Just use zeros() fonction
N=10
SendPrepReq=zeros(1,N,N) or SendPrepReq=zeros(Int,1,N,N)
Or if you really want to use for loop:
N=10
R = 1:N
V = 1:N
for r in R
for v in V
SendPrepReq[1,r,v]=0
end
end
If SendPrepReq is a variable:
for r in R
for v in V
#constraint(model, SendPrepReq[1,r,v] == 0 )
end
end

Given value p, return last element of sequence < p - Fortran

I have a sequence of numbers as follows:
1 , 1, 5, 13, 41, 121, 365, ....
The first two values are:
N(1) = 1 and N(2) = 1
As from 3rd value, N(i) = 2*N(i-1) + 3*N(i-2)
The issue I am facing with is: If I give an argument of p, it should return me the last values of the sequence < p (Using fortran77).
For instance, if p = 90, it should return the value 41.
a = 1
b = 1
while b < p:
c = 2 * b + 3 * a
a = b
b = c
return a
The Fortran equivalent is:
function fct(p) result(a)
integer, intent(in) :: p
integer :: a, b, c
a = 1
b = 1
do while (b < p)
c = 2 * b + 3 * a
a = b
b = c
enddo
end function
program test
integer :: fct
external fct
print *,fct(90)
end program
Assuming you already have the sequence in a variable lst, and p set,
max(filter(lambda x:x<=p, lst))
def get_last_element(p):
n1 = 1
n2 = 1
while True:
if n2 > p:
return n1
n1, n2 = n2, 2*n2 + 3 * n1
print(get_last_element(90))
I wrote a piece of code in Fortran 2003. I defined a type which has memory for two last parts of the sequence.The procedure is a recursive function. The type can be used standalone to get n-th part of the sequence or efficiently placed in a loop to find parts in a row (not necessarily beginning at 1) as it has memory of previous parts. (compiler: gfortran 4.8).
The type is defined in mymod.f90 file as
module mymod
implicit none
type seq_t
integer :: saved_i = 0, saved_val_i = 0, saved_val_i_1 = 0
contains
procedure :: getpart => getpart_seq
end type
contains
recursive function getpart_seq(this,i) result(r)
class(seq_t) :: this
integer, intent(in) :: i
integer :: r,r_1,r_2
if (i.eq.1.or.i.eq.2) then
r = 1
elseif(i.eq.this%saved_i) then
r = this%saved_val_i
elseif(i.eq.this%saved_i-1) then
r = this%saved_val_i_1
else
r_1 = this%getpart(i-1)
r_2 = this%getpart(i-2)
r = 2*r_1 + 3*r_2
this%saved_val_i_1 = r_1
end if
this%saved_i = i
this%saved_val_i = r
end function getpart_seq
end module mymod
The main program for the requested case is
program main
use mymod
implicit none
type (seq_t) :: seq
integer :: i,p,tmp_new,tmp_old,ans
! Set the threshold here
p = 90
! loop over parts of the sequence
i = 0
do
i = i + 1
tmp_new = seq%getpart(i)
print*,tmp_new
if (tmp_new>p) then
ans = tmp_old
exit
end if
tmp_old = tmp_new
end do
print*,"The last part of sequence less then",p," is equal to",ans
end program
The outcome is
1
1
5
13
41
121
The last part of sequence less then 90 is equal to 41.