How can I Use semaphores to describe the synchronization of the eight processes in the general
precedence graph above?
p1 p2 p3 p4 p5 p6 p7 p8
=============================================================================
. . . . . . . .
work . . . . . . .
| . . . . . . .
V(s1, 3) P(s1) . . P(s1) . P(s1) .
x | . . | . | .
work . . | . | .
| . . | . | .
V(s2, 2) P(s2) P(s2) work . | .
x | | | . | .
| work | . work .
| | | . | .
work V(s3, 1) V(s3, 1) P(s3) | .
| x x P(s3) | .
| | | .
| work | .
| | | .
V(s4, 1) V(s4, 1) V(s4, 1) P(s4)
x x x P(s4)
P(s4)
|
work
|
x
Related
I have this table:
| 1 | 2 | 3 | 4 | 5 | 6 |
|------------------------------------------------------------------------------------------------------
| A | B | C | D | E | F | G | H | I | J | K | L | M | N | N | O | P | Q | R | S | T | U | V | W | X | Y
|------------------------------------------------------------------------------------------------------
| n | n | n | n | n | n | n | n | n | n | n | n | n | n | n | n | n | n | n | n | n | n | n | n | n | n
| n | n | n | n | n | n | n | n | n | n | n | n | n | n | n | n | n | n | n | n | n | n | n | n | n | n
| n | n | n | n | n | n | n | n | n | n | n | n | n | n | n | n | n | n | n | n | n | n | n | n | n | n
| n | n | n | n | n | n | n | n | n | n | n | n | n | n | n | n | n | n | n | n | n | n | n | n | n | n
where number 1-6 (but it actualy goes futher up to 12) stands for month and where "n" stands for random number.
What do I need is to add colum at the end and in each row count data from current row and up to todays month (A, E, I, M, P, T, X,...) but based on current month, so if currentmonth is 4 (by today), then sumup "n" cols (A, E, I and M), if would be only february then sumup only cells in this single row by current month (so sumup only A and E).
simple in VbA, however I need it as excel formula.
Have no idea how do I even start
Given your data layout, if you have the latest version of Excel, with the SEQUENCE function, you can use:
=SUM(INDEX(3:3, SEQUENCE(MONTH(TODAY()),,0,1)*4+1))
If you don't have the SEQUENCE function, try:
=SUM(INDEX(3:3,N(IF(1,(ROW(INDEX($A:$A,1,1):INDEX($A:$A,MONTH(TODAY()),1))-1)*4+1))))
With the latter formula, especially, you may need to "confirm" this array-formula by holding down ctrl + shift while hitting enter. If you do this correctly, Excel will place braces {...} around the formula as observed in the formula bar
You say it's simple in VBA, but you need a formula.
When you declare a VBA function as public in your module (Public Function Calculate_Month(...) as ...), you can use that function as a formula:
=Calculate_Month(...)
You can use SUMPRODUCT function:
=SUMPRODUCT((A3:X3)*($A$1:$X$1<=MONTH(TODAY()))*($A$1:$X$1<>""))
My homework is to write simple functions related to chess. The rook function is working fine i guess it shows where can you step from the given start coordinate. And now I'm stuck with the knight function. My idea is to filter the coordinates list by the following condition: If the abs value of the coordinate differences is 3 and the rows are different then its a valid step. But I don't really know how should i implement this in Haskell. Any idea how should i do that?
My Code:
import Data.List
possibleMoves = [ (x, y) | x <- [0..7], y <- [7,6..0]]
rook :: (Int, Int) -> [(Int, Int)]
rook (x,y) = filter (/=(x,y)) (filter ((==y).snd) possibleMoves ++ filter ((==x).fst ) possibleMoves)
knight :: (Int, Int) -> [(Int, Int)]
knight (x,y) = filter ((==3)((abs(y - head(map snd(possibleMoves))))).snd) possibleMoves
Resulting the following error :
* Couldn't match expected type `Int -> Bool'
with actual type `Bool'
* Possible cause: `== 3' is applied to too many arguments
In the first argument of `(.)', namely
`(== 3) ((abs (y - head (map snd (possibleMoves)))))'
In the first argument of `filter', namely
`((== 3) ((abs (y - head (map snd (possibleMoves))))) . snd)'
In the expression:
filter
((== 3) ((abs (y - head (map snd (possibleMoves))))) . snd)
possibleMoves
|
9 | knight (x,y) = filter ((==3)((abs(y - head(map snd(possibleMoves))))).snd) possibleMoves
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
It seems like you're making it harder than it needs to be.
Given position K below, you could simply list each knight move:
1 2 3 4 5
+---+---+---+---+---+
1 | | H | | A | |
+---+---+---+---+---+
2 | G | | | | B |
+---+---+---+---+---+
3 | | | K | | |
+---+---+---+---+---+
4 | F | | | | C |
+---+---+---+---+---+
5 | | E | | D | |
+---+---+---+---+---+
And remove the ones that are outside the chessboard.
knight :: (Int, Int) -> [(Int, Int)]
knight (x, y) = filter validPosition
[ (x + 1, y + 2)
, (x + 2, y + 1)
, (x + 2, y - 1)
, (x + 1, y - 2)
, (x - 1, y - 2)
, (x - 2, y - 1)
, (x - 2, y + 1)
, (x - 1, y + 2)
]
Then if you think you're repeating yourself too much:
knight' :: (Int, Int) -> [(Int, Int)]
knight' (x, y) = filter validPosition
[ (x + dx, y + dy) | dx <- [-2,-1,1,2]
, dy <- [-2,-1,1,2]
, ... something about dx, dy and 3 ...
]
It seems that the (== y) . snd stuff obscures the solution a little.
Your idea of filtering the knight's positions is actually really succinct and easy to implement using a list comprehension.
knight (x, y) = [(x', y') | x'<-[x-2..x+2], y'<-[y-2..y+2], abs (x' - x) + abs (y' - y) == 3 ]
Restricting the possible displacement values to -2 and +2 will also prevent the column and row from being the same, so you can do away with that condition.
The only thing is, it will also return values that are past the board. You could check this using your preexisting possibleMoves function:
import Data.List (intersect)
safeKnight = intersect possibleMoves . knight
I'm trying to print out a board in the right way, like this:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
1. . . . . . . . . . . . . . . . . .
2. . . . . . . . . . . . . . . . . .
3. . . . . . . . . . . . . . . . . .
4. . . . . . . . . . . . . . . . . .
5. . . . . . . . . . . . . . . . . .
6. . . . . . . . . . . . . . . . . .
7. . . . . . . . . . . . . . . . . .
8. . . . . . . . . . . . . . . . . .
9. . . . . . . . . . . . . . . . . .
10. . . . . . . . . . . . . . . . . .
11. . . . . . . . . . . . . . . . . .
12. . . . . . . . . . . . . . . . . .
13. . . . . . . . . . . . . . . . . .
14. . . . . . . . . . . . . . . . . .
15. . . . . . . . . . . . . . . . . .
16. . . . . . . . . . . . . . . . . .
17. . . . . . . . . . . . . . . . . .
18. . . . . . . . . . . . . . . . . .
I have the list comprehension here
((concat [(""++show i)++" " | i <- [1..n], i<10])++"\n")
I can get the 9 first numbers correctly, but the problem comes when i would like to put an else statement in my comprehension. I can't seem to know how to do that. So to make my self extra clear, i would like to do the same thing with the double digits but the only difference will be that i want two spaces instead of three between each double digit.
The left hand of the list comprehension accepts any Haskell expression, so we can write the if-then-else in the left hand of the list comprehension and omit the i < 10 condition on the right hand:
concat [(""++show i)++if i < 10 then " " else " " | i <- [1..n]]++"\n"
For n = 15, this then produces:
Prelude> concat [(""++show i)++if i < 10 then " " else " " | i <- [1..n]]++"\n"
"1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 \n"
We can also remove the ""++ part on the left side of the list comprehension, since this is bascially a no operation:
concat [show i ++ if i < 10 then " " else " " | i <- [1..n]] ++ "\n"
The above is however not very elegant: if i = 123, then we still will run into trouble. We can calculate the length of the show, calculate 4-l (with l the length), and add this as extra spacing. For instance:
concat [s ++ replicate (4-length s) ' ' | i <- [1..n], let s = show i] ++ "\n"
There are also some more dedicated formatting and joining functions, but since the exercise is probably to get familier with lists, I think this is out of scope here.
Like #4castle says, we can use for instance printf:
import Text.Printf(printf)
concatMap (printf "%-4d") [1..n] ++ "\n"
I have my working pc and a laptop. On the pc I running Windows with domain controller account. When I log on I have access to the Internet. My laptop connected to the same network with Ubuntu operating system. Are there any ways to obtain the Internet access from my laptop? Now i'm simply using remote desktop connection from lap top, but I really need the Internet on my Ubuntu.
IP configuration Windows
HOST NAME . . . . .. . . . . . : MN10384632
DNS . . . . . . . . . . . . . : bs.idest.ru
DNS LOOKUP ORDER. . . . . . . . : bs.idest.ru
idest.ru
LAN - Ethernet:
DNS. . . . . . . . . . . . . . . :
DESCRIPTION . . . . . . . . . . . . : Broadcom NetXtreme Gigabit Ethernet
Dhcp Enabled.. . . . . . . . . .. . . . : disabled
IP-address .. . . . . . . . . . . . . . : 10.1.25.6
Network mask . . . . . . . . . . . . . : 255.255.255.0
Gateway . . .. . . . . . . . . . . .. : 10.1.25.1
DNS. . . . . . . . . . . . . . . . . . . : 10.1.10.4
10.1.10.5
WINS-server . . . . . . . . . . . . . .: 192.168.100.110
GENERAL.DEVICE: enp3s0
GENERAL.TYPE: ethernet
GENERAL.HWADDR: MYMAC
GENERAL.MTU: 1500
GENERAL.STATE: 100 (connected)
GENERAL.CONNECTION: CORPORATE
GENERAL.CON-PATH: /org/freedesktop/NetworkManager/ActiveConnection/83
WIRED-PROPERTIES.CARRIER: on
IP4.ADDRESS[1]: 10.1.25.106/24
IP4.GATEWAY: 10.1.25.1
IP4.DNS[1]: 10.1.10.4
IP4.DNS[2]: 10.1.10.5
Most probably, if you have no rights there is nothing you can do. You need at least to enable routing and NAT on your Windows...
Wasn't able to find anything related so here goes! :D
Inside Redhat terminal, whenever I do a ping towards a Redhat virtIO Ethernet Adapter interface of Windows it results to DUP! responses.
I've tried pinging either one of those two virtIO interfaces and both yields to duplicate ping responses...
I've read somewhere that it may be due to Windows' RRAS
Though I'm afraid that turning this off would disable also my capability to Remote access via RDP to this Windows machine.
So does anybody encountered this?
Windows interface setup:
Windows IP Configuration
Host Name . . . . . . . . . . . . . . . . : G162401EN
Primary Dns Suffix . . . . . . . . . . . :
Node Type . . . . . . . . . . . . . . . . : Hybrid
IP Routing Enabled . . . . . . . . . . . : No
WINS Proxy Enabled . . . . . . . . . . . : No
Ethernet Adapter EXT-CP2-EL5:
Connection-specific DNS Suffix . . . . . :
Description . . . . . . . . . . . . . . . : Red Hat VirtIO Ethernet Adapter #5
Physical Address . . . . . . . . . . . . : F0:X:Y:Z:A:B
DHCP Enabled . . . . . . . . . . . . . . : No
Autoconfiguration Enabled . . . . . . . . : Yes
IPv4 Address . . . . . . . . . . . . . . : 10.40.90.163(Preferred)
Subnet Mask . . . . . . . . . . . . . . . : 255.255.255.224
Default Gateway . . . . . . . . . . . . . :
NetBIOS over Tcpip . . . . . . . . . . . : Enabled
Ethernet Adapter EXT-CP1-EL4:
Connection-specific DNS Suffix . . . . . :
Description . . . . . . . . . . . . . . . : Red Hat VirtIO Ethernet Adapter #4
Physical Address . . . . . . . . . . . . : F0:D:E:F:G:H
DHCP Enabled . . . . . . . . . . . . . . : No
Autoconfiguration Enabled . . . . . . . . : Yes
IPv4 Address . . . . . . . . . . . . . . : 10.40.90.131(Preferred)
Subnet Mask . . . . . . . . . . . . . . . : 255.255.255.224
Default Gateway . . . . . . . . . . . . . :
NetBIOS over Tcpip . . . . . . . . . . . : Enabled