Looping Through a1 to h8 - actionscript-3

I have some text fields inside objects a1 b1 c1 d1 e1 f1 g1 h1 a2 b2 c2...
num = 97;
while (num <= 104) {
if (this[String.fromCharCode(num) + "1"].piece == wb1_txt) {
oldSquare = String.fromCharCode(num) + "1";
trace("oldSquare = ", oldSquare);
}
num = num + 1;
}
I want to find text field's location. How can I make it loop?

The following code will go through a1 b1 c1 d1 e1 f1 g1 h1 a2 b2 ... g8 h8
for( i=1; i<=8; i++){
for( num=97; num<105; num++){
sq = String.fromCharCode(num) + i;
trace( sq );
}
}

Related

Switch of group of cell

In this function the group of cell is A1, B1 and C1 but i want to switch for B1, C1 and D1 and after C1, D1 and E1 how can i do it
function regle() {
var spreadsheet = SpreadsheetApp.getActive();
var i = i+1
var p = spreadsheet.getRange('A1').getValue();
var t = spreadsheet.getRange('C1').getValue();
if (t == 1 && p == 1){
spreadsheet.getRange('B1').activate();
spreadsheet.getActiveRange().setValue(1);
}
else{
spreadsheet.getRange('B1').activate();
spreadsheet.getActiveRange().setValue(2);
}
}

Efficiently retrieving data from MYSQL for batch processing?

I have a situation where I have data in a primary table with additional data in a bunch of associated tables. Given a list of IDs from the primary table, I need to retrieve all data for a batch process. This batch process is high volume so I need to implement it very efficiently.
I have implemented this using subqueries with group_concat and some mapping code, but I'm not very confident in it. It seems efficient but hard to maintain (particularly because my real implementation is much uglier, with it's many more tables and columns). Is this implementation a good idea? Is there some other mysql querying/joining approach I could take to improve this?
The structure of the data is similar to this, but in actuality I have many more tables and columns:
Objects
ID | column1 | column2 | column3
----------
1 a b c
2 d e f
Attributes1
ID | ObjectsId| column1 | column2 | column3
--------------------
1 1 g k l
2 1 m n o
3 2 p q r
4 2 s t u
Attributes2
ID | ObjectsId| column1 | column2 | column3
--------------------
1 1 w v x
2 1 y z aa
3 2 bb cc dd
4 2 ee ff gg
This is approximately what the object produced by my application code should look like.
[
{
id = 1,
column1 = a,
Column2 = b,
Column3 = c,
Attributes1 = [
{
Id = 1,
ObjectsId = 1,
Column1 = g,
Column2 = k,
Column3 = l
},
{
Id = 2,
ObjectsId = 1,
Column1 = m,
Column2 = n,
Column3 = o
}]
Attributes2 = [
{
Id = 1,
ObjectsId = 1,
Column1 = w,
Column2 = v,
Column3 = x
},
{
Id = 2,
ObjectsId = 1,
Column1 = y,
Column2 = z,
Column3 = aa
}]
},
{
id = 2,
column1 = d,
Column2 = e,
Column3 = f,
Attributes1 = [
{
Id = 3,
ObjectsId = 2,
Column1 = p,
Column2 = q,
Column3 = r
},
{
Id = 4,
ObjectsId = 2,
Column1 = s,
Column2 = t,
Column3 = u
}]
Attributes2 = [
{
Id = 3,
ObjectsId = 2,
Column1 = bb,
Column2 = cc,
Column3 = dd
},
{
Id = 4,
ObjectsId = 2,
Column1 = ee,
Column2 = ff,
Column3 = gg
}]
}
]
This is my implementation:
private function get_all($object_ids)
{
$a1 = " SELECT group_concat(a1.ID, '|', a1.ObjectsId, '|', a1.column1, '|', a1.column2, '|', a1.column3)
FROM Attributes1 a1
WHERE a1.objectsId = o.id";
$a2 = " SELECT group_concat(a2.ID, '|', a2.ObjectsId, '|', a2.column1, '|', a2.column2, '|', a2.column3)
FROM Attributes2 a2
WHERE a2.objectsId = o.id";
$o = " SELECT ID, column1, column2, column3,
(%s) as attributes1_result,
(%s) as attributes2_result
FROM Objects o
WHERE o.id IN (?)";
$query = sprintf($o, [$a1, $a2]);
$results = $this->query($query, $object_ids);
foreach ($results as &$result) {
$a1Results = explode(',', $result['attributes1_result']);
foreach ($a1Results as $a1Result) {
$columns = explode('|', $a1Result);
$resultRow['id'] = $columns[0];
$resultRow['ObjectsId'] = $columns[1];
$resultRow['column1'] = $columns[2];
$resultRow['column2'] = $columns[3];
$resultRow['column3'] = $columns[4];
$result['Attributes1'][] = $resultRow;
}
unset($result['attributes1_result']);
$a2Results = explode(',', $result['attributes2_result']);
foreach ($a2Results as $a2Result) {
$columns = explode('|', $a2Result);
$resultRow['id'] = $columns[0];
$resultRow['ObjectsId'] = $columns[1];
$resultRow['column1'] = $columns[2];
$resultRow['column2'] = $columns[3];
$resultRow['column3'] = $columns[4];
$result['Attributes2'][] = $resultRow;
}
unset($result['attributes2_result']);
}
return $results;
}

mysql multiple where clause not working

Based on this table
key sampleID rs A1 A2
1 12345 rs123 C C
2 12345 rs345 C C
3 11110 rs123 C C
4 11110 rs345 C A
This statement
SELECT sampleID
FROM QS_base
WHERE (rs = 'rs123' AND A1 = 'C' AND A2 = 'C')
OR (rs = 'rs345' AND A1 = 'C' AND A2 = 'C')
Returns
12345
12345
11110
And this statement
SELECT sampleID
FROM QS_base
WHERE (rs = 'rs123' AND A1 = 'C' AND A2 = 'C')
AND (rs = 'rs345' AND A1 = 'C' AND A2 = 'C')
Returns no records. I expected it to return
12345
12345
Why is it retuning no results and is there a way to write it so that the above result can be obtained?
You can get what you want using group by and having:
SELECT sampleID
FROM QS_base
WHERE (rs = 'rs123' AND A1 = 'C' AND A2 = 'C') OR
(rs = 'rs345' AND A1 = 'C' AND A2 = 'C')
GROUP BY sampleID
HAVING COUNT(DISTINCT rs) = 2;
The AND will need both the condition to be satisfied at the same time and can not find a row with 2 different condition.
You can use exits to do it
select t1.sampleID
from QS_base t1
where
t1.rs = 'rs123' AND t1.A1 = 'C' AND t1.A2 = 'C'
and exists
(
select 1 from QS_base t2 where t1.sampleID = t2.sampleID
and t2.rs = 'rs345' AND t2.A1 = 'C' AND t2.A2 = 'C'
)
You're looking for samples where rs is both 'rs123' and 'rs345'. The query only looks at rows individually.
You have excluding conditions in the second example. The where clause:
WHERE (rs = 'rs123' AND A1 = 'C' AND A2 = 'C') AND (rs = 'rs345' AND A1 = 'C' AND A2 = 'C')
cloud be written as:
WHERE rs = 'rs123' AND rs = 'rs345' AND A1 = 'C' AND A2 = 'C'
rs cannot be equal to rs123 and rs345 at the sime time. :)
As for the second part of Your question, yes it certainly can return result that You need. Just write:
WHERE (rs = 'rs123' AND A1 = 'C' AND A2 = 'C')
I assume You have additional requirements on this query, if so, please state them in You post.

Haskell program simple game

I am very new in haskell-programming. I try to program a simple dice-game, but I don't know to do it in haskell.
suc :: (Int,Int,Int) -> Int -> (Int,Int,Int) -> Bool
suc (a₁,a₂,a₃) c (d₁,d₂,d₃)
I want to consider each difference dᵢ - aᵢ (but not if aᵢ > dᵢ) and return False if (d1-a1)+(d2-a2)+(d3-a3) are larger than c. (if aᵢ > dᵢ then I sum up 0 instead the difference)
I try something like this:
suc :: (Int,Int,Int) -> Int -> (Int,Int,Int) -> Bool
suc (a1, a2, a3) c (d1, d2, d3) = ?????
where diff1 = if (d1 > a1) then d1-a1
diff2 = if (d2 > a2) then d2-a2
diff3 = if (d3 > a3) then d3-a3
Because in Haskell, else is not a optional part of an if expression, so you need to define diff1 as diff1 = if d1 > a1 then d1 - a1 else 0. Other two are similar.
Notes that > returns a Bool value, so you could just sum these three differences up and compare it with c, and use it as your condition.
There are several ways to define this function:
suc1 (a1, a2, a3) c (d1, d2, d3) = diff1 + diff2 + diff3 <= c
where diff1 = if d1 > a1 then d1 - a1 else 0
diff2 = if d2 > a2 then d2 - a2 else 0
diff3 = if d3 > a3 then d3 - a3 else 0
suc2 (a1, a2, a3) c (d1, d2, d3) = sum diffs <= c
where diff1 = max (d1-a1) 0
diff2 = max (d2-a2) 0
diff3 = max (d3-a3) 0
diffs = [diff1, diff2, diff3]
suc3 (a1, a2, a3) c (d1, d2, d3) = sum (zipWith diff as ds) <= c
where diff a d = max (d-a) 0
as = [a1, a2, a3]
ds = [d1, d2, d3]
How about this?
suc :: (Int,Int,Int) -> Int -> (Int,Int,Int) -> Bool
suc (a1, a2, a3) c (d1, d2, d3) =
((if a1> d1 then 0 else d1-a1) + (if a2> d2 then 0 else d2-a2) + (if a3>d3 then 0 else d3-a3) > c )
Or alternatively
suc :: (Int,Int,Int) -> Int -> (Int,Int,Int) -> Bool
suc (a1, a2, a3) c (d1, d2, d3) =
max 0 (d1-a1) + max 0 (d2-a2) + max 0 (d3-a3) > c

Pari/GP Exceptions/break loops

ellpow(E, P, m) will always throw an exception:
*** ellpow: impossible inverse modulo: Mod(x, y).
*** Break loop: type 'break' to go back to GP
where x and y are integers.
I want to trap the value x, without finishing the program in order to use it
later.
The snippet of the code is:
trap(invmoder,
x,
ellpow(E, P, m)
), n);
The whole program is:
ellcurv(n) = {
local(B, a1, a2, a3, a4, a6, b, E, P, m, x);
B = 20;
a4 = Mod(random(n), n);
b = 4*a4^3 + 27;
b = 1/b;
a1 = a2 = a3 = Mod(0, n);
a6 = Mod(1, n);
E = ellinit([a1, a2, a3, a4, a6]);
P = [0,1];
ellisoncurve(E, P);
m = 1;
for(i = 1, B,
m = lcm(m, i));
print(m);
x = gcd(
trap(,
ellpow(E, P, m),
ellpow(E, P, m)
), n);
}