How to create pyramid of asterisks in asp - asp-classic

<%
For i = 1 To 10
For j = 5 < i to 5 step -1
response.write(" ")
Next
for k = 0 < i to 10
response.write("*")
Next
response.write("</br>")
Next
%>
above my code to create asterisk pyramid using asp classic. the result below:
how to make the solution to create asterisk pyramid below:

<%
For i = 1 To 10
For j = 1 to i
response.write(j)
Next
for k = 0 < i to 10
response.write(" ")
Next
response.write("</br>")
Next
%>

<%
For i = 1 To 10
For j = 1 to i
response.write(j)
Next
for k = i to 10 '<-- fill the rest of the blanks
response.write(" ")
Next
response.write("</br>")
Next
%>

Related

How is it possible to make a matrix with special random elements?

is there any possibility in Julia to make a matrix with special random elements?
for example, a matrix which each row has random elements but every elements should repeat at least one time:
n = zeros(Int,3, 5)
for i in indices(n, 1)
for j in indices(n, 2)
n[i,j]=rand(0:3)
end
end
n=
3×5 Array{Int64,2}:
1 2 1 1 2
3 3 2 2 0
3 2 1 0 0
but in second row, there is not 1 . would you please help me how this matrix is made?
Thanks.
You can use this function:
using Random
function randfill!(m::AbstractMatrix, s::AbstractVector)
n1 = length(s)
n2 = size(m, 2)
#assert n2 >= n1
for i in 1:size(m,1)
m[i, 1:n1] .= s
for j in n1+1:n2
m[i,j] = rand(s)
end
shuffle!(view(m, i, :))
end
m
end

Difference in local & let scoping rule?

In the following example:
Fs = cell(2)
i = 1
for i = 1:2
local i # same as local i = i
Fs[i] = () -> i
end
println(Fs[1]()) # 1
println(Fs[2]()) # 2
println(i) # 1
Is it true that local i is the same as local i = i?
Why cannot I do the same for while loop as such?
Fs = cell(2)
i = 1
while i <= 2 #LoadError: UndefVarError: i not define
local i = i
Fs[i] = ()->i
i += 1
end
But have to use let:
Fs = cell(2)
i = 1
while i <= 2
let i = i
Fs[i] = ()->i
end
i += 1
end
println(Fs[1]()) # 1
println(Fs[2]()) # 2
When you introduce new variable, and try to get it's value before assignment, Julia throws an UndefVarError error, in the first example:
Fs = cell(2)
i = 1
for i = 1:2
local i # same as local i = i
Fs[i] = () -> i
end
println(Fs[1]()) # 1
println(Fs[2]()) # 2
println(i) # 1
For block introduces a new local i, adn for command itself assign it so the code successfully dose it's duty. But in the second example:
Fs = cell(2)
i = 1
while i <= 2 #LoadError: UndefVarError: i not define
local i = i
Fs[i] = ()->i
i += 1
end
A new i was introduced in while block, but before assignment you try to get it's value, and this produces an error.
In 3d one let command declare a new local block and a new i variable for it's block.
julia> function test3()
Fs = cell(2)
i = 1
while i <= 2
let i = 100
println(i)
end
i += 1
end
println(i)
end
test3 (generic function with 1 method)
julia> test3()
100
100
3# while block use the function's scope

How to find the index of a set in Julia/JuMP?

I am trying to create a linear optimization model. I have a set that looks like this:
si=[1,51,39,400909,1244]
sj=[31,47,5]
The numbers in this set represent codes. I am trying to loop through the set to add a constraint to my model, but I do not want to loop through the sets using their values, I want to loop through the sets based on their indices.
Here is the code I have now:
si=[1,51,39,400909,1244]
sj=[31,47,5]
c= [3 5 2;
4 3 5;
4 5 3;
5 4 3;
3 5 4]
b= [80;
75;
80;
120;
60]
# x_ij >= 0 ∀ i = 1,...,5, j = 1,...,3
#defVar(m, x[i in si,j in sj] >= 0)
#setObjective(m,Min,sum{c[i,j]*x[i,j],i in si, j in sj})
# ∀j = 1,...,3
for j in sj
#addConstraint(m, sum{x[i,j],i in si} <= 480)
end
for i in si
#addConstraint(m, sum{x[i,j],j in sj} >= b[i])
end
I keep getting an error because the numbers in the sets are too big. Does anyone know how to loop through the indices instead? Or does anyone have another way to do this?
I am also having trouble printing my solution. Here is my code:
for i in n
for j in p
println("x",i,",",j,"= ", getValue(x[i,j]))
end
end (incorporating Iain Dunning's answer from below)
However the output only reads
Objective value: 1165.0
x5,3= 0.0
Do you know how to fix the output so I can read the values of my variables?
The code you have posted doesn't work because you are trying to index c by, e.g. 400909,47. Try this:
n = length(si)
p = length(sj)
#variable(m, x[i=1:n,j=1:p] >= 0)
#objective(m,Min,sum{c[i,j]*x[i,j],i=1:n,j=1:p})
for j in 1:p
#constraint(m, sum{x[i,j],i=1:n} <= 480)
end
for i in 1:n
#constraint(m, sum{x[i,j],j=1:p} >= b[i])
end

add duplicate value in multi dimensional array in classic asp

I have a 2d array in classic asp like
1-5
1-3
2-5
I need this array output in following format
1-8
2-5
please help me
You need a dictionary to sum up the col2 values grouped by the col1 values. As in:
ReDim aIn(2, 1)
aIn(0, 0) = 1 : aIn(0, 1) = 5
aIn(1, 0) = 1 : aIn(1, 1) = 3
aIn(2, 0) = 2 : aIn(2, 1) = 5
Dim dicX : Set dicX = CreateObject("Scripting.Dictionary")
Dim i
For i = LBound(aIn, 1) To UBound(aIn, 1)
dicX(aIn(i, 0)) = dicX(aIn(i, 0)) + aIn(i, 1)
Next
ReDim aOut(dicX.Count - 1, 1)
For i = LBound(aOut, 1) To UBound(aOut, 1)
aOut(i, 0) = dicX.Keys()(i)
aOut(i, 1) = dicX(aOut(i, 0))
Next
For i = LBound(aOut, 1) To UBound(aOut, 1)
WScript.Echo aOut(i, 0), aOut(i, 1)
Next
output:
======
1 8
2 5
======

Second loop runs once and stops

The basic concept behind this code is that whenever it runs, the quantity from an element decreases and the quantity from the same element, but from a different array, increases. For whatever reason, the second while loop only runs once and stops. For example, if total1 = 11 and total2 = 0, the first time the code is executed, total1 = 10 and total2 = 1. However after that, total1 = 9 and total2 = 1 and so on. Can anyone tell me what is wrong with my code? Any and all help would be appreciated.
<%
count = 0
do while NOT rs3.EOF
if rs3("ITEM_NO") = itemnum then
qtyArray(count) = qtyArray(count) - qtyreq
end if
if qtyArray(count) >= 0 and rs3("ITEM_NO") = itemnum then
total1 = total1 - qtyreq
end if
count = count + 1
rs3.MoveNext
loop
rs3.MoveFirst
pickcount = 0
do while NOT rs3.EOF
if qtyPick(pickcount) >= 0 and rs3("ITEM_NO") = itemnum then
qtyPick(pickcount) = qtyPick(pickcount) + qtyreq
total2 = total2 + qtyreq
end if
rs3.MoveNext
pickcount = pickcount + 1
loop
%>
total2 = total2 + qtyreq
Please make sure "qtyreq" variable is not 0 and really adds +1 to your total2.
There is a line on your second loop pickcount = pickcount + 1. Just move this line above the line rs3.MoveNext of your second loop

Resources