I have a simple problem below
f2:{[x;y]
r:sum(x)*sum(y);
r
};
tm:([] pr:(100.01 100.02;100.03 100.04); rv:(15.72 55.64; 16.92 15.17 12.21 34.99))
f2 each [tm`rv][tm`pr]
The result I get is
{[x;y]
r:sum(x)*sum(y);
r
}[(15.72 55.64;16.92 15.17 12.21 34.99)'[(100.01 100.02;100.03 100.04)]]
The result I want is to add tm`rv and add tm`pr and multiply.
tm
pr rv
-------------------------------------
100.01 100.02 15.72 55.64
100.03 100.04 16.92 15.17 12.21 34.99
Hi, you can sum each nested list then do the multiplication:
select result:(sum each pr)*sum each rv from tm
result
--------
14274.14
15863.55
q)
But if you want to use your f2 function:{[x;y] r:sum(x)*sum(y); r }
You should do this:
f2'[tm`rv;tm`pr]
14274.14 15863.55
q)
' apply f2 over pairwise combinations of arguments
My current script copies text like this with a shortcut:
:WiltedFlower: aetheryxflower ─ 4
:Alcohol: alcohol ─ 3,709
:Ant: ant ─ 11,924
:Apple: apple ─ 15
:ArmpitHair: armpithair ─ 2
and pastes it modified into a single line
Pls trade 4 aetheryxflower 3 alcohol 11 ant 15 apple 2 armpithair <#id>
As you can see there are already two little problems, the first one is that it copies only the number/s before a comma if one existed instead of ignoring it. The second is that I always need to also copy before hitting the hotkey and start re/start the script, I've thought of modifying the script so that it uses the already selected text instead of the copied one so that I can bind it with a single hotkey.
That is my current script, it would be cool if anyone can also tell me what they used and why exactly, so that I also get better with ahk
!q::
list =
While pos := RegExMatch(Clipboard, "(\w*) ─ (\d*)", m, pos ? pos + StrLen(m) : 1)
list .= m2 " " m1 " "
Clipboard := "", Clipboard := "Pls trade " list " <#951737931159187457>"
ClipWait, 0
If ErrorLevel
MsgBox, 48, Error, An error occurred while waiting for the clipboard.
return
If the pattern of your copied text dont change, you can use something like this:
#Persistent
OnClipboardChange:
list =
a := StrSplit(StrReplace(Clipboard, "`r"), "`n")
Loop,% a.Count() {
b := StrSplit( a[A_Index], ": " )
c := StrSplit( b[2], " - " )
list .= Trim( c[2] ) " " Trim( c[1] ) " "
}
Clipboard := "Pls trade " list " <#951737931159187457>"]
ToolTip % Clipboard ; just for debug
return
With your example text, the output will be:
Pls trade aetheryxflower ─ 4 alcohol ─ 3,709 ant ─ 11,924 apple ─ 15 armpithair ─ 2 <#951737931159187457>
And this will run EVERY TIME your clipboard changes, to avoid this, you can add at the top of the script #IfWinActive, WinTitle or #IfWinExist, WinTitle depending of your need.
The answer given would solve the problem, assuming that it never changes pattern as Diesson mentions.
I did the explanation of the code you provided with comments in the code below:
!q::
list = ; initalize a blank variable
; regexMatch(Haystack, regexNeedle, OutputVar, startPos)
; just for frame of reference in explanation of regexMatch
While ; loop while 'pos' <> 0
pos := RegExMatch(Clipboard ; Haystack is the string to be searched,
in this case the Clipboard
, "(\w*) ─ (\d*)" ; regex needle in this case "capture word characters
(a-z OR A-Z OR 0-9 OR _) any number of times, space dash space
then capture any number of digits (0-9)"
, m ; output var array base name, ie first capture will be in m1
second m2 and so on.
, pos ? pos + StrLen(m) : 1) ; starting position for search
"? :"used in this way is called a ternary operator, what is saying
is "if pos<>0 then length of string+pos is start position, otherwise
start at 1". Based on the docs, this shouldn't actually work well
since 'm' in this case should be left blank
list .= m2 " " m1 " " ; append the results to the 'list' variable
followed with a space
Clipboard := "" ; clear the clipboard.
Clipboard := "Pls trade " list " <#951737931159187457>"
ClipWait, 0 ; wait zero seconds for the clipboard to change
If ErrorLevel ; if waiting zero seconds for the clipboard to change
doesn't work, give error msg to user.
MsgBox, 48, Error, An error occurred while waiting for the clipboard.
return
Frankly this code is what I would call quick and dirty, and seems unlikely to work well all the time.
I am struggling to understand the behaviour of dsolve for this simple ODE:
Y''(t) = b*Y'(t) + f(t)
For some reason, dsolve throws an error if I use f(t)=exp(t-a), but for general f(t) or f(t)=exp(a*t) or if I put a value for a, dsolve succeeds. The complete error message:
File "~/.local/lib/python3.7/site-packages/sympy/solvers/ode.py",
line 679, in dsolve
return _helper_simplify(eq, hint, hints, simplify, ics=ics)
File "~/.local/lib/python3.7/site-packages/sympy/solvers/ode.py",
line 704, in _helper_simplify
sols = solvefunc(eq, func, order, match)
File "~/.local/lib/python3.7/site-packages/sympy/solvers/ode.py",
line 5674, in ode_nth_linear_constant_coeff_undetermined_coefficients
return _solve_undetermined_coefficients(eq, func, order, match)
File "~/.local/lib/python3.7/site-packages/sympy/solvers/ode.py",
line 5766, in _solve_undetermined_coefficients
coeffsdict[s[x]] += s['coeff']
KeyError: exp(t)
I am using this code:
from sympy import symbols, Function, dsolve, exp, Eq
a, b, t = symbols('a b t')
Y = Function('Y')(t)
#f = Function('f')(t) # works
#f = exp(a*t) # works
f = exp(t-a) # KeyError: exp(t)
#f = exp(t-2) # works
odeY = Eq( Y.diff(t,t), b*Y.diff(t) + f )
dsolve(odeY,Y)
I am using sympy version 1.5.1 with python3.7
Many thanks!
How can I send a keys default (from hardware) behavior in its own key definition. I mean this code:
vcerc = 0
+c::
vcerc := !vcerc
Return
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
kkey = 0
$k::
if vcerc {
kkey := !kkey
if kkey
SendInput {k down}
else
SendInput {k up}
}
else {
Send, K
}
Return
In the end part Send, K It sends the word K. I am in a multi language environment which means if I switch to the other, This key still sends K rather than sending the one that is for the second language (assume ن).
How can I make this send the default? (From hardware with no matter what the language is)
Two things that seem off to me: 1) Your initial kkey declaration will never get hit since it falls after a hotkey (and a return). Declare your variables at the top. 2) if kkey is true, your script has it holding down the k button indefinitely. Is this expected? 3) Your only looking for lowercase k's but sending uppercase k's. Is this expected?
At any rate, this example should point you in the right direction.
vcerc = 0
kkey = 0
+c::
vcerc := !vcerc
return
$k::
{
if (vcerc) {
kkey := !kkey
if (kkey) {
msgbox, k down ; SendInput {k down}
} else {
msgbox, k up ; SendInput {k up}
}
} else {
Send, K
}
}
I am new in prolog. I have found breadth first search program in the internet which is search for routes between cities. I want to extend the program to store and calculate distances. But I can't figure out how to do it.
The original code:
move(loc(omaha), loc(chicago)).
move(loc(omaha), loc(denver)).
move(loc(chicago), loc(denver)).
move(loc(chicago), loc(los_angeles)).
move(loc(chicago), loc(omaha)).
move(loc(denver), loc(los_angeles)).
move(loc(denver), loc(omaha)).
move(loc(los_angeles), loc(chicago)).
move(loc(los_angeles), loc(denver)).
bfs(State, Goal, Path) :-
bfs_help([[State]], Goal, RevPath), reverse(RevPath, Path).
bfs_help([[Goal|Path]|_], Goal, [Goal|Path]).
bfs_help([Path|RestPaths], Goal, SolnPath) :-
extend(Path, NewPaths),
append(RestPaths, NewPaths, TotalPaths),
bfs_help(TotalPaths, Goal, SolnPath).
extend([State|Path], NewPaths) :-
bagof([NextState,State|Path],
(move(State, NextState), not(member(NextState, [State|Path]))),
NewPaths), !.
extend(_, []).
Output:
1 ?- bfs(loc(omaha), loc(chicago), X).
X = [loc(omaha), loc(chicago)] ;
X = [loc(omaha), loc(denver), loc(los_angeles), loc(chicago)] ;
false.
I have tried this:
bfs(A,B,Path,D) :-
bfs(A,B,Path),
path_distance(Path,D).
path_distance([_], 0).
path_distance([A,B|Cs], S1) :-
move(A,B,D),
path_distance(Cs,S2),
S1 is S2+D.
bfs(A,B, Path) :-
bfs_help([[A]], B, RevPath), reverse(RevPath, Path).
bfs_help([[Goal|Path]|_], Goal, [Goal|Path]).
bfs_help([Path|RestPaths], Goal, SolnPath) :-
extend(Path, NewPaths),
append(RestPaths, NewPaths, TotalPaths),
bfs_help(TotalPaths, Goal, SolnPath).
extend([State|Path], NewPaths) :-
bagof([NextState,State|Path],
(move(State, NextState,_), not(member(NextState, [State|Path]))),
NewPaths), !.
extend(_, []).
Output:
5 ?- bfs(loc(omaha), loc(chicago), X,D).
false.
What i want:
1 ?- bfs(loc(omaha), loc(chicago), X, D).
X = [loc(omaha), loc(chicago)] ;
D = 1
X = [loc(omaha), loc(denver), loc(los_angeles), loc(chicago)] ;
D = 6
false.
Please anyone help me to solve this problem!
Sorry for my english.
It seems cheapest to define a relation path_distance/2. That is not the most elegant way,
but it should serve your purpose:
bfs(A,B,Path,D) :-
bfs(A,B,Path),
path_distance(Path,D).
path_distance([_], 0).
path_distance([A,B|Cs], S1) :-
move(A,B,D),
path_distance([B|Cs],S2),
S1 is S2+D.
You might also reconsider bfs/3 a bit. The query
?- bfs(A,B, Path).
Gives rather odd results.
Both move/2 and move/3 are now used. Thus:
move(A,B) :-
move(A,B,_).
move(loc(omaha), loc(chicago),1).
move(loc(omaha), loc(denver),2).
move(loc(chicago), loc(denver),1).
move(loc(chicago), loc(los_angeles),2).
move(loc(chicago), loc(omaha),1).
move(loc(denver), loc(los_angeles),2).
move(loc(denver), loc(omaha),1).
move(loc(los_angeles), loc(chicago),2).
move(loc(los_angeles), loc(denver),3).