Game of Life RLE format - line ending with number - conways-game-of-life

I want to build a figure using it's RLE representation. I ran into a problem with "Lobster" figure, particulary with this part:
10bo2bo2$
How should I interpret '2' in the end of line? I have no clue because there are no symbols following it.

The '$' character is considered a symbol, like any other, in the RLE format, and it means "increment the row". So if there's a number before it, that means increment the row by that amount.
So if I wrote a pattern like o5bo3$o5bo!, it would translate into a pattern that looks like this:
#-----#
-------
-------
#-----#

Related

MATLAB - literally convert decimal to string

I hope I have a simple question, I just couldn't figure it out.
I have several numbers which I want to be converted to string quite literally:
12.000 -> '12.000'
4.0 -> '4.0'
34.760000 -> '34.760000'
As you can see, I cannot simply pad zeros, since that highly depends on how many zero are given with the number.
Does anyone know how to do this?
Ahh, yes, this is easily accomplished with MATLAB's num2str function, like so:
num2str(12.000 ,'%.3f')
num2str(4.0, '%.1f')
num2str(34.760000,'%.6f')
WRT " %x.f ", where x equals 3,1, and 6 in the examples above, this is called the formSpec, which I would encourage you to read about more, here. In this case, we are saying that the variable is a floating point number, and we want to preserve x digits after the decimal place. It is useful to know about format specification for parsing text, and to efficiently read from and write to files.
Edit: A point of clarification, and as I'm sure you already know, single quotes (' ') in MATLAB yield a character array rather than a string. These are different data types. If you're really after a string, just add string to the num2str argument, i.e.,
string(num2str(12.000 ,'%.3f'))
string(num2str(4.0, '%.1f'))
string(num2str(34.760000,'%.6f'))

How to find missing value from equation using java?

User made some calculations using program..and printed it on paper.. But mouse cut some part from the paper.
Now we have to create the program to find missing values.
Example:
54 + 27 = HOLE
3241 + 4HOLE45=7281
We have to find the missing value at HOLE.
If we pass multiple eqution at a time.
If (like in your example) the equations are separated by line breaks (or any other character will work) simply separate the equations maybe into custom objects then you can split each equations to numbers by splitting at every arithmetic symbols.
What I am suggesting is to phrase each line as an equation and find the missing bit by comparing both sides of the equal sign. You can find any one missing number each from any equation like this.
I have not provided any code example because you have not provided any code that you have currently tried out and also no specific language is specified. If you follow up with those I am ready to give a code sample.

Reading data from .txt file into Matlab

I have been trying in vain for days to do one seemingly simple thing--I want to read data from a .txt file that looks like this:
0.221351321
0.151351321
0.235165165
8.2254546 E-7
into Matlab. I've been able to load the data in the .txt file as a column vector using the fscanf command, like so:
U=fscanf(FileID, '%e')
provided that I go through the file first and remove the space before the 'E' wherever scientific notation occurs in the data set.
Since I have to generate a large number of such sets, it would be impractical to have to do a search-and-replace for every .txt file.
Is there a way for matlab to read the data as it appears, as in the above example (with the space preceding 'E'), and put it into a column vector?
For anyone who knows PARI-GP, an alternate fix would be to have the output devoid of spaces in the first place--but so far I haven't found a way to erase the space before 'E' in scientific notation, and I can't predict if a number in scientific notation will appear or not in the data set.
Thank you!
Thank you all for your help, I have found a solution. There is a way to eliminate the space from PARI-GP, so that the output .txt file has no spaces to begin with. I had the output set to "prettymatrix". One needs to enter the following:
? \o{0}
to change the output to "Raw," which eliminates the space before the "E" in scientific notation.
Thanks again for your help.
A simple way, may not be the best, is to read line by line, remove the space and convert back to floating point number.
For example,
x = []
tline = fgetl(FileID);
while ischar(tline)
x = [x str2num(tline(find(~isspace(tline))))]
tline = fgetl(FileID);
end
One liner:
data = str2double(strsplit(strrep(fileread('filename.txt'),' ',''), '\n'));
strrep removes all the spaces, strsplit takes each line as a separate string, and str2double coverts the strings to numbers.

Matlab not taking last number in array?

I've got a Subscripted assignment dimension mismatch problem.
I've already localized the issue, and know exactly what is going on, I just don't know why.
Here's the problematic piece of code:
mFrames(:,i) = vSignal(round(start:1:frameLength*samplingRate));
start=start+frameShift*samplingRate;
frameLength = frameLength+frameShift;
I've already checked what's going on in debugmode; usually my resulting column length of mFrames is 128, this stays the same until i=1004. Then, my column length changes to 127.
I've checked the values involved while in debug mode, and it simply does not make sense what is going on. At i==1004 start=32097 and frameLength*samplingRate=32224.
That's a difference of 127 meaning 128 points, that should work.
BUT when i assign a vector A=round(start:1:frameLength*samplingRate)
OR B=start:1:frameLength*samplingRate
In both cases I get a vector going from 32097 to 32223. This ALTHOUGH when I give in frameLength*samplingRate matlab is giving me 32224.
In other words, matlab is telling me it's using one number, but when I test I find it's using a different one.
Any help appreciated.
I suspect your 32224 is not actually 32224. MATLAB's default format only displays so many decimal places, so when dealing with floating point numbers, what is printed on screen is not necessarily the "exact" value.
Let's go back a step and look at how the synatx x = start:step:end works.
1:1:10 should give us numbers in steps of 1 from 1 to 10. Fair enough, that makes sense. What if we set the end value to something that's slightly above 10?
e.g.:
1:1:10.1
Well, it still gives us 1:1:10, (or 1:10, 1 being the default step) because we can't have values higher than the end-point, so 11 isn't a correct step.
So what about this:
1:1:9.99
Spoiler: it's the same as 1:9
And this?
1:1:9.9999999
Yep, still 1:9
But if we do this:
a = 9.9999999;
Then with default format, the value of a will be shown on the command line and in your list of workspace variables as 10.0000.
Now, if frameLength and samplingRate are both stored as floating point numbers, it's possible that the number you see as 32224 is not 32224 but very slightly below that. You can check this by changing your default format - e.g. format long at the command line - to show more decimal places.
The simplest solution is probably to do something like:
B=start:1:round(frameLength*samplingRate)
Or try to store the relevant values as integers (e.g., uint32).

MATLAB fgetl() only returning -1

I have a text file with several HEX values following a format like so:
%
AAAAAAAA
%
AAAAAAAB
and I am trying to use the fgetl() function in MATLAB to obtain the size of the HEX values (for a purpose of which I'm not entirely certain of... if it is important to you, I'll try to decipher what they were doing). Currently, this is what is being attempted:
folder = 'FolderA\hexdata.txt';
fidr = fopen(folder);
while ~feof(fidr)
get = fgetl(fidr);
hexdata=get;
if strncmp(get,'%',1)
time=time+.5;
continue
elseif size(get)<8
continue
end
%Do stuff here
end
For some reason, fgetl is returning -1 every time which I know means the line it is reading only contains the end-of-file marker. Is there something obvious I am doing wrong that I just don't see? I'm not the strongest MATLAB coder by any stretch of the imagination, so it is very possible I am missing something obvious.
Take a look at your filename folder, a seperator is missing. Use fullfile to get a proper path.