Creating a battlefield grid in Ruby - ruby

I'm attempting to build a battlefield made of 10x10 grid.
Below is my code:
SHIP_HASH = { submarine: 2, destroyer: 3, destroyer: 3, cruiser: 4, aircraftcarrier: 5,}
def print_results
board_layout = Array.new(10, " ").map{|row| Array.new(10, " ")}
row_label = ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9"]
column_label = [" ", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9"]
end
print print_results
I received the output:
[" ", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9"]
What I wanted is to generate an output like below but I dunno know what's the error.
0 1 2 3 4 5 6 7 8 9
0 . . . . . . . . . .
1 . . . . . . . . . .
2 . . . . . . . . . .
3 . . . . . . . . . .
4 . . . . . . . . . .
5 . . . . . . . . . .
6 . . . . . . . . . .
7 . . . . . . . . . .
8 . . . . . . . . . .
9 . . . . . . . . . .

So in ruby, the last thing evaluated in a method is what is returned. So in your print results, the last thing evaluated is the assignment of column_label which is what you see is returned.
Here is the code, note the use of print in some cases and puts in others as they do different things:
SHIP_HASH = { submarine: 2, destroyer: 3, destroyer: 3, cruiser: 4, aircraftcarrier: 5,}
def print_results
board_layout = Array.new(10, ".").map{|row| Array.new(10, ".")}
row_label = ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9"]
column_label = ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9"]
print "\t"
print row_label.join("\t")
puts
board_layout.each_with_index do |row, i|
print column_label[i]
print "\t"
print row.join("\t")
puts
end
end
print_results
Output:
0 1 2 3 4 5 6 7 8 9
0 . . . . . . . . . .
1 . . . . . . . . . .
2 . . . . . . . . . .
3 . . . . . . . . . .
4 . . . . . . . . . .
5 . . . . . . . . . .
6 . . . . . . . . . .
7 . . . . . . . . . .
8 . . . . . . . . . .
9 . . . . . . . . . .
Let me know if you have any questions on that.

Related

IBM MQ dmpmqlog Not Generating Log with Persistent Data

I want to use the dmpmqlog utility to view messages found in circular logs. Even though I follow everything as per IBM documentation, after I create the dump I'm unable to find the data in the logs. I stop the queue manager before running the dmpmqlog command, manually add few messages to the queue. But in the dumped log files these messages are not shown.
I used the following invocation of dmpmqlog:
dmpmqlog -m QMA
AMQ7701I: DMPMQLOG command is starting.
LOG FILE HEADER
***************
counter1 . . . : 56
FormatVersion . : 5 StrucId . . . . : 'HLFH'
logactive . . . : 3 loginactive . . : 2
logsize . . . . : 4096 pages
baselsn . . . . : <0:0:0:0>
nextlsn . . . . : <0:0:16:43833>
lowtranlsn . . : <0:0:16:43129>
minbufflsn . . : <0:0:16:42697>
headlsn . . . . : <0:0:16:42697>
taillsn . . . . : <0:0:16:43832>
hflag1 . . . . : 1
-> CONSISTENT
-> CIRCULAR
HeadExtentID . : 0 LastEID . . . . : 1650643508
LogId . . . . . : 1650643508
FirstArchNum . : 4294967295 LastArchNum . . : 4294967295
nextArcFile . . : 4294967295
FileCount . . . : 3
Files . . . . . : 0, 1, 2
LastCId . . . . : 0 softmax . . . . : 16777216
LogPageSize . . : 4096
RecOffset . . . : 4096
MinAlign . . . : 4096
counter2 . . . : 56
AMQ7719I: DMPMQLOG command is using a default of '0:0:16:42697' for the starting dump location.
LOG RECORD - LSN <0:0:16:42697>
**********
HLG Header: lrecsize 212, version 1, rmid 0, eyecatcher HLRH
Creation Time: 2022-04-22 22:39:27.137 (UNKNOWN) (UTC +330)
LogRecdType . . : ALM Start Checkpoint (1025)
Eyecatcher . . : ALRH Version . . . . : 1
LogRecdLen . . : 192 LogRecdOwnr . . : 1024 (ALM)
XTranid . . . . : TranType: NULL
ObjectName . . : NULL
Qid . . . . . . : {NULL_QID}
ThisLSN . . . . : <0:0:0:0>
PrevLSN . . . . : <0:0:15:50639>
No data for Start Checkpoint Record
LOG RECORD - LSN <0:0:16:42909>
**********
HLG Header: lrecsize 220, version 1, rmid 0, eyecatcher HLRH
Creation Time: 2022-04-22 22:39:27.137 (UNKNOWN) (UTC +330)
LogRecdType . . : ATM Transaction Table (773)
Eyecatcher . . : ALRH Version . . . . : 1
LogRecdLen . . : 200 LogRecdOwnr . . : 768 (ATM)
XTranid . . . . : TranType: NULL
ObjectName . . : NULL
Qid . . . . . . : {NULL_QID}
ThisLSN . . . . : <0:0:0:0>
PrevLSN . . . . : <0:0:0:0>
Also my CURRLOG is showing no log files.
DIS QMSTATUS CURRLOG
1 : DIS QMSTATUS CURRLOG
AMQ8705I: Display Queue Manager Status Details.
QMNAME(QMD) STATUS(RUNNING)
CURRLOG( )
What am I doing wrong here, any help would be greatly appreciated.
IBM MQ V 9.1
I suspect you might have more luck with the dmpmqlog program if you try the following invocation:-
dmpmqlog -m QMA -b
The CURRLOG parameter is only applicable if you are using linear logging. Since you are using circular logging, it is expected to see a blank in there.
From IBM Docs about DISPLAY QMSTATUS:-
CURRLOG
The name of the log extent being written to at the time that the DISPLAY QMSTATUS command is processed. If the queue manager is using circular logging, and this parameter is explicitly requested, a blank string is displayed.

DB2-400 MCH-1210 'receiver too small to hold result' in module QQQQUERY subroutine BUILDAP

Occasionaly we get the following message
from module QQQQUERY in procedure BUILDAP.
MCH1210 Receiver value too small to hold result.
Van module . . . . . . . . : QQQQUERY
Van procedure . . . . . . . : BUILDAP
Instructie . . . . . . . . : 24041
Naar module . . . . . . . . : QQQQUERY
Naar procedure . . . . . . : BUILDAP
Instructie . . . . . . . . : 24041
Bericht . . . . : Receiver value too small to hold result.
Extra log info
MCH1210 Escape 40 11/04/18 10:33:28,661097 QQQQUERY QSYS *STMT QQQQUERY QSYS *STMT
Van module . . . . . . . . : QQQQUERY
Van procedure . . . . . . . : BUILDAP
Instructie . . . . . . . . : 24041
Naar module . . . . . . . . : QQQQUERY
Naar procedure . . . . . . : BUILDAP
Instructie . . . . . . . . : 24041
Bericht . . . . : Receiver value too small to hold result.
CPF4204 Escape 50 11/04/18 10:33:28,697990 QQQQUERY QSYS *STMT LOGGING2 SOARETPGM *STMT
Van module . . . . . . . . : QQQQUERY
Van procedure . . . . . . . : QQQQUERY
Instructie . . . . . . . . : 34332
Naar module . . . . . . . . : LOGGING2
Naar procedure . . . . . . : LOGGING2
Instructie . . . . . . . . : 1000001
Bericht . . . . : Er is een interne storing opgetreden in de queryprocessor.
Oorzaak . . . . : er is een systeemfout opgetreden in het programma van de
queryprocessor. Het nummer van het querydefinitiesjabloon (QDT) is 0.
Recovery . . . : raadpleeg de berichten van lager niveau. Verbeter
eventuele fouten en geef de opdracht opnieuw op. Als het probleem zich
opnieuw voordoet, meldt u het probleem met de opdracht ANZPRB (Problemen
analyseren).
RNX1216 Escape 99 11/04/18 10:33:28,828323 QRNXIE QSYS *STMT LOGGING2 SOARETPGM *STMT
Van module . . . . . . . . : QRNXMSG
Van procedure . . . . . . . : SignalException
Instructie . . . . . . . . : 21
Naar module . . . . . . . . : LOGGING2
Naar procedure . . . . . . : LOGGING2
Instructie . . . . . . . . : 1000001
Bericht . . . . : Error message CPF4204 appeared during OPEN for file
FALOGBL0.
Cause . . . . . : RPG procedure LOGGING2 in program SOARETPGM/LOGGING2
received the message CPF4204 while performing an implicit OPEN operation on
file FALOGBL0. The actual file is FALOGBL0. Recovery . . . : Check the
job log for a complete description of message CPF4204, and contact the
person responsible for program maintenance. If the file has a device type of
SPECIAL, there may be no message in the job log.
RNQ1216 Kopie afzender 99 11/04/18 10:33:28,838222 QRNXIE QSYS *STMT QRNXIE QSYS *STMT
Van module . . . . . . . . : QRNXMSG
Van procedure . . . . . . . : InqMsg
Instructie . . . . . . . . : 8
Naar module . . . . . . . . : QRNXMSG
Naar procedure . . . . . . : InqMsg
Instructie . . . . . . . . : 8
Bericht . . . . : Error message CPF4204 appeared during OPEN for file
FALOGBL0 (C S D F).
Cause . . . . . : RPG procedure LOGGING2 in program SOARETPGM/LOGGING2
received the message CPF4204 while performing an implicit OPEN operation on
file FALOGBL0. The actual file is FALOGBL0. Recovery . . . : Check the
job log for a complete description of message CPF4204, and contact the
person responsible for program maintenance. If the file has a device type of
SPECIAL, there may be no message in the job log. Possible choices for
replying to message . . . . . . . . . . . . . . . : D – Obtain RPG
formatted printout of system storage. S – Obtain printout of system
storage. F – Obtain full formatted printout of system storage. C – Cancel.
And this occurs in a triggerprogram that we use for logging changes.
The triggertime is *after and event is *update & *insert & *delete.
The problem occurs when starting the program and ultimatly gives a CPF4204 msg during opening the logical which contains the logged data.
It has occurred on several files we log.
Any suggestions where to look?
Tx

Signal reach in matrix algorithm

I found an algorithm problem and I've been thinking a possible solution to it but I just can think about the "intuitive" one, let's see if someone can lend me a hand.
The problem is the following, we have a n*m matrix in which we have empty spaces represented by . and walls represented by %. We can place a "router" (represented by R) in any place (i,j) inside the matrix with a range of n steps/cells . Consider that a step can only be up/down/left/right.
Which is the most efficient way to check the range of the router?
Example (n=4)
. . . . . . . . . .
. . % % . . . . . .
. . % . . . % . . .
. . . . R . % . . .
. . % . . . % . . .
. . % . . . . . . .
Soltion (# marks signal reach)
. . . # # # . . . .
. . % % # # # . . .
. # % # # # % . . .
# # # # R # % . . .
. # % # # # % . . .
. . % # # # # . . .
I've been investigating and found the Flood Fill algorithm, I guess I could use it with an extra parameter to check the steps I've already used recursively. Do any of you know any algorithm that could more efficient?
If you'd like to write some code feel free to use any language you want. Thank you beforehand guys!
I think the best approach is to use BFS. You basically use a queue to visit the nodes layer by layer.
Using BFS it will visit the cells like this (consider R as (0,0)):
t = 0 - Queue = {(0,0)}
For each element in query, visit north, east, west, south if not
visited and not wall
For (0, 0) -> Visit (1, 0), (0, 1), (-1, 0), (0, -1)
. . . . . . . . . .
. . % % . . . . . .
. . % . . . % . . .
. . . . R . % . . .
. . % . . . % . . .
. . % . . . . . . .
t = 1 Queue = {(1, 0), (0, 1), (-1, 0), (0, -1)}
For each element in query, visit north, east, west, south if not visited and not wall
For (1, 0) -> Visit (2, 0), (1, 1), (1, -1)
For (0, 1) -> Visit (0, 2), (-1, 1)
For (-1, 0) -> Visit (-1, 0), (-2, 0)
For (0, -1) -> Visit (-1, -1), (0, -2)
. . . . . . . . . .
. . % % . . . . . .
. . % . # . % . . .
. . . # R # % . . .
. . % . # . % . . .
. . % . . . . . . .
t = 2 and so on
. . . . . . . . . .
. . % % # . . . . .
. . % # # # % . . .
. . # # R # % . . .
. . % # # # % . . .
. . % . # . . . . .
t = 3
. . . . # . . . . .
. . % % # # . . . .
. . % # # # % . . .
. # # # R # % . . .
. . % # # # % . . .
. . % # # # . . . .

Golang static identifier resolution

I'm attempting to do some static analysis on function calls in a Go project using the go/parse, go/token and go/ast modules, but I can't figure out how to determine the type of a given ast.Ident object.
For instance if parse something like this:
textToContain := bytes.NewBuffer([]byte{})
// lots of other code
text := textToContain.String() // <- I care about this function call
(this is parsed from here: file)
EDIT: It took a lot of code to parse this so I didn't post it here, but you can find it as a gist at: https://gist.github.com/EricChiang/6735340c5fa3d2de2b73
I get the following code printed using the ast.Print function
0 *ast.CallExpr {
1 . Fun: *ast.SelectorExpr {
2 . . X: *ast.Ident {
4 . . . Name: "textToContain"
5 . . . Obj: *ast.Object {
6 . . . . Kind: var
7 . . . . Name: "textToContain"
8 . . . . Decl: *ast.AssignStmt {
9 . . . . . Lhs: []ast.Expr (len = 1) {
10 . . . . . . 0: *ast.Ident {
12 . . . . . . . Name: "textToContain"
13 . . . . . . . Obj: *(obj # 5)
14 . . . . . . }
15 . . . . . }
17 . . . . . Tok: :=
18 . . . . . Rhs: []ast.Expr (len = 1) {
19 . . . . . . 0: *ast.CallExpr {
20 . . . . . . . Fun: *ast.SelectorExpr {
21 . . . . . . . . X: *ast.Ident {
23 . . . . . . . . . Name: "bytes"
24 . . . . . . . . }
25 . . . . . . . . Sel: *ast.Ident {
27 . . . . . . . . . Name: "NewBuffer"
28 . . . . . . . . }
29 . . . . . . . }
31 . . . . . . . Args: []ast.Expr (len = 1) {
32 . . . . . . . . 0: *ast.CompositeLit {
33 . . . . . . . . . Type: *ast.ArrayType {
35 . . . . . . . . . . Elt: *ast.Ident {
37 . . . . . . . . . . . Name: "byte"
38 . . . . . . . . . . }
39 . . . . . . . . . }
42 . . . . . . . . }
43 . . . . . . . }
44 . . . . . . . Ellipsis: -
46 . . . . . . }
47 . . . . . }
48 . . . . }
49 . . . }
50 . . }
51 . . Sel: *ast.Ident {
53 . . . Name: "String"
54 . . }
55 . }
57 . Ellipsis: -
59 }
But I can't see where I could infer the type of textToContain
I know a bunch of tools that can do this, for instance this example from the go blog, but I think I'm going in the wrong direction.
3of3 is right; you need the type checker, which is golang.org/x/tools/go/types. In general, the type of an expression depends on type information for the transitive closure of import dependencies, so you will probably want to use the golang.org/x/tools/go/loader package (which I maintain), which takes care of many challenging details for you. Its stdlib_test.go may be a useful starting point.
Once you've identified the expression of interest, you can find its type in one of the mappings within the types.Info structure for the AST's package.
In this case, the expression is a referring identifier (*ast.Ident) so look in the Uses mapping to find the types.Object (named entity) to which it refers---a local variable (*types.Var) in this case. For expressions other than identifiers, the Types mapping will tell you its type.

FFMPEG-PHP Windows "Can't open movie file"

ffmpeg extension is loaded as it is shown at phpinfo(), my file and script are at the same location, but I'm still getting this error.
Warning: Can't open movie file Untitled.avi in C:\xampp\htdocs\skelbiu\fetch.php on line 4
Fatal error: Call to a member function getDuration() on a non-object in C:\xampp\htdocs\skelbiu\fetch.php on line 5
My script:
extension_loaded('ffmpeg') or die('Error in loading ffmpeg');
$ffmpegInstance = new ffmpeg_movie('Untitled.avi');
echo "getDuration: " . $ffmpegInstance->getDuration() .
"getFrameCount: " . $ffmpegInstance->getFrameCount() .
"getFrameRate: " . $ffmpegInstance->getFrameRate() .
"getFilename: " . $ffmpegInstance->getFilename() .
"getComment: " . $ffmpegInstance->getComment() .
"getTitle: " . $ffmpegInstance->getTitle() .
"getAuthor: " . $ffmpegInstance->getAuthor() .
"getCopyright: " . $ffmpegInstance->getCopyright() .
"getArtist: " . $ffmpegInstance->getArtist() .
"getGenre: " . $ffmpegInstance->getGenre() .
"getTrackNumber: " . $ffmpegInstance->getTrackNumber() .
"getYear: " . $ffmpegInstance->getYear() .
"getFrameHeight: " . $ffmpegInstance->getFrameHeight() .
"getFrameWidth: " . $ffmpegInstance->getFrameWidth() .
"getPixelFormat: " . $ffmpegInstance->getPixelFormat() .
"getBitRate: " . $ffmpegInstance->getBitRate() .
"getVideoBitRate: " . $ffmpegInstance->getVideoBitRate() .
"getAudioBitRate: " . $ffmpegInstance->getAudioBitRate() .
"getAudioSampleRate: " . $ffmpegInstance->getAudioSampleRate() .
"getVideoCodec: " . $ffmpegInstance->getVideoCodec() .
"getAudioCodec: " . $ffmpegInstance->getAudioCodec() .
"getAudioChannels: " . $ffmpegInstance->getAudioChannels() .
"hasAudio: " . $ffmpegInstance->hasAudio();
I'm using php 5.2.9 (XAMPP 1.7.1), Windows 7.
Thanks in advance!
Your path to the movie has to be the full path. It doesn't matter where your script resides. Because you are using Win 7 and XAMPP, your path would be for example
$ffmpegInstance = new ffmpeg_movie('C:/xampp/htdocs/yourfolder/Untitled.avi');
I hope that this resolves your problem

Resources