Is it possible to match the middle item.
Like this:
a a ... b ... c c
The middle element get b and the rest a and c
this could work only if count of a elements and c elements was constant ie.
a || a |*| b |*| c||c
this represents 2*a, many b, 2*c
Maybe just better solution will be creating small extension where you can use any available techniques of matching?
I have not tried, but maybe:
a |*| a || b || c |*| c
Related
Write a Maple code in order to find all the at most three digits Pythagorean triples (a, b, c), for
a, b, c > 0. We say that an integer triple(a, b, c) is a Pythagorean triple if a^2+b^2=c^2.
Hint: You might need to use the command type(sqrt(x),integer) as it returns true if x is a complete square. Get help for type from the help center.
one possibility. You can try to make it more efficient if needed.
result:=Array(1..999);
n:=0;
for a from 1 to 999 do
for b from a to 999 do
c:=sqrt(a^2+b^2);
if type(c,integer) and length(c)<=3 then
n:=n+1;
result(n):=[a,b,c];
fi;
od;
od;
result:=result(1..n);
To print them
for item in result do
print(item[1]^`2`+item[2]^`2`=item[3]^`2`)
od
....
Consider this:
isolve(a^2+b^2=c^2);
In the old RPG III and the non-free RPGLE/RPG IV you could "rename" fields you get from either a record of a PF/LF or a record from a DSPF.
This lead to possibilities like grouping several lines of input (additional order text) into a array. So I didn't have to MOVEL or EVAL ottxt1 to the external described field x1txt1, ottxt2 to x1txt2 and so on.
I'd only had to rename the LF record and the DSPF record fields to the array-fields, read the record and shift them from the one array to the other and display my DSPF record
H DECEDIT('0,') DATEDIT(*DMY.) dftactgrp(*no)
Fsls001 cf e workstn
Fordtxtl0 if e k disk
D ot s 20a dim(6)
D x1 s 20a dim(6)
Iordtxtr
I ottxt1 ot(1)
I ottxt2 ot(2)
I ottxt3 ot(3)
I ottxt4 ot(4)
I ottxt5 ot(5)
I ottxt6 ot(6)
Isls00101
I x1txt1 x1(1)
I x1txt2 x1(2)
I x1txt3 x1(3)
I x1txt4 x1(4)
I x1txt5 x1(5)
I x1txt6 x1(6)
C k$or00 klist
C kfld otonbr
C kfld otopos
C eval otonbr = 2
C eval otopos = 2
C k$or00 chain ordtxtr
C if %found(ordtxtl0)
C eval x1 = ot
C endif
C
C exfmt sls00101
C
C move *on *inlr
But is this also possible in *FREE RPGLE? And if so, how?
You can define data structures containing the fields from the files, and overlay them with an array.
Replace your I specs and array definitions with these data structures. You don't have to specify anything besides the field names for the fields from the externally-described file.
dcl-ds otDs;
ottxt1;
ottxt2;
ottxt3;
ottxt4;
ottxt5;
ottxt6;
ot like(ottxt1) dim(6) pos(1);
end-ds;
dcl-ds x1Ds;
x1txt1;
x1txt2;
x1txt3;
x1txt4;
x1txt5;
x1txt6;
x1 like(x1txt1) dim(6) pos(1);
end-ds;
I have a table
t: flip `S`V ! ((`$"|A|B|"; `$"|B|C|D|"; `$"|B|"); 1 2 3)
and some dicts
t1: 4 10 15 20 ! 1 2 3 5;
t2: 4 10 15 20 ! 0.5 2 4 5;
Now I need to add a column with values on the the substrings in S and the function below (which is a bit pseudocode because I am stuck here).
f:{[s;v];
if[`A in "|" vs string s; t:t1;];
else if[`B in "|" vs string s; t:t2;];
k: asc key t;
:t k k binr v;
}
problems are that s and v are passed in as full column vectors when I do something like
update l:f[S,V] from t;
How can I make this an operation that works by row?
How can I make this a vectorized function?
Thanks
You will want to use the each-both adverb to apply a function over two columns by row.
In your case:
update l:f'[S;V] from t;
To help with your pseudocode function, you might want to use $, the if-else operator, e.g.
f:{[s;v]
t:$["A"in ls:"|"vs string s;t1;"B"in ls;t2;()!()];
k:asc key t;
:t k k binr v;
};
You've not mentioned a final else clause in your pseudocode but $ expects one hence the empty dictionary at the end.
Also note that in your table the columns S and V have been cast to a symbol. vs expects a string to split so I've had to use the stringoperation - this could be removed if you are able to redefine your original table.
Hope this helps!
Say I have the following DOM structure:
div
> svg
> defs
> g
> rect
> g
> g
<-- I want to insert an element here
> g
> g
None of the parent g's child g elements have a class, id, or anything else I can use as a selector, and I cannot modify them because they are coming from a 3rd party widget loaded into the page.
The best I can do so far is insert into the 3rd g element, but that's not acceptable. I want to add a 6th element to the parent g's children, between the current indices 2 and 3 (or indices 1 and 2 if you don't count the rect).
Here's what I have done so far:
var test = d3.selectAll('#continer svg > g > g');
test = d3.select(test[0][2]);
test.append('foreignObject').
attr('width', 690).attr('height', 500)
.append('xhtml:body').style('font', '14px "Helvetica Neue"')
.html('<h1>An HTML Foreign Object in SVG</h1>');
With that I end up with the following structure:
div
> svg
> defs
> g
> rect
> g
> g
> g
> foreignobject & its children inserted here
> g
... and I understand why. I have tried D3's insert method using a function as the second argument to specify before, but the browser keeps telling me:
An attempt was made to reference a Node in a context where it does not
exist.
Ok so this works but it's a bit of a hack. I use jQuery to rearrange elements after appending using D3. Would still like to see a pure D3 solution to this if one is possible:
// select the parent g element
var parentG = d3.select('#continer svg > g');
// append a new G element with a nested foreign object
parentG.append('g').attr('id', '__my_custom_id')
.append('foreignObject').attr('width', 690).attr('height', 500)
.append('xhtml:body').style('font', '14px "Helvetica Neue"')
.html('<h1>An HTML Foreign Object in SVG</h1>')
;
// now use jQuery to rearrange the order of the elements
$('#__my_custom_id')
.insertAfter('#container svg > g > g:nth-child(3)')
.removeAttr('id')
;
So I want to simplify z:=a+I*b; Im(z) where a, b are real variables So I try:
s:= 1+2*I
Im(s) // outputs 2
z:=a+I*b
Im(z) // outputs Im(a+I*b)
So I wonder is it any how possible to simplify Im(z) so to get b as output (here we look at general case meaning z could be any complex expression from real values (like a, b, c etc and complex I))?
You didn't tell Maple that a and b were real, so the simplification doesn't work because it doesn't necessarily hold. One way to get what you want is by using the assume command to let it know:
> s:=1+2*I;
s := 1 + 2 I
> Im(s);
2
> z:=a+I*b;
z := a + b I
> Im(z);
Im(a + b I)
> assume(a,real);
> assume(b,real);
> z;
a~ + b~ I
> Im(z);
b~
The evalc command works by considering unknowns as being real.
z:=a+I*b:
Im(z);
Im(a + I b)
evalc( Im(z) );
b
See its help-page, ?evalc.