Polish Notation Expression (need little help) **/^a-bc+d*ef** - infix-notation

/^a-bc+d*ef
I am little bit confused about this expression
*ef=(e*f)
+d*ef=d+(e*f)
-BC=(b-c)
/^a? if it is ^23= 2^3
here I am confused, what should I do? please need help.
/^a-bc+d*ef
/^a-bc+d(e*f)
Here now what should i do? should /^a-bc+d+(e*f) is this okay?
(b-c) then what sign should be between /^a(b-c) and d+(e*f)?
and /^a I know if ^23=2^3=8
but here I am totally fed up. Please guide me where i am wrong.

It seems to me that your expression is not correct:
/^a-bc+d*ef
<=>
/^a-bc+d(e*f)
<=>
/^a-bc (d+(e*f))
At this point you've got three values in a row and no operator. All operators should be binary for Polish notation to work.

Related

Erlang: using io_lib to convert float to string [duplicate]

I am using a function to create a list from a float.
float_to_list(0.02).
It returns:
"2.00000000000000000000e-002"
I need it to give me a number exactly like:
"0.20"
If I fed it 5.23
"5.23"
If I fed it 5.5
"5.50"
So basically the number rounded to two decimal places.
Probably an easy fix.
Thanks
EDIT:
I would like to use the io format it looks like it might work,
but it dosen't in this example:
wxTextCtrl:setValue( TcGrossProfit, io:format("~p", [NUMBER]), ),
seems textctrl wants a string, I don't want to print it to the screen.
Are you looking for something like this:
6> F = 5/2.
2.50000
7> io_lib:format("~.1f",[F]).
["2.5"]
8> io_lib:format("~.2f",[F]).
["2.50"]
9> io_lib:format("~.3f",[F]).
["2.500"]
If yes, have a look at the io_lib module.
mochinum:digits converts a float to a string with an appropriate level of precision.
1> mochinum:digits(1.1).
"1.1"
2> mochinum:digits(1.2345).
"1.2345"
Not exactly what the OP requested, but useful nonetheless.
Alternatively you could use the function you were already using.
float_to_list(0.02,[{decimals, 2}]) outputs '0.02'
Or for Elixir users ;)
:erlang.float_to_list(5.231,[{:decimals, 2}]) outputs '5.2'
This link provides functions that truncate/floor or ceil or round a float. Given those you can round to 2 digits by multiplying by 100, rounging and then dividing back by 100 (and possibly rounding again to avoid precision errors)
I know people don't like the, "I am not an expert in language X" answers, but the printf command is quite ubiquitous so I will say, look for an analog of printf in Erlang.
Edit: It looks like the format and fwrite may be those analogs. For more info from erlang.org.

Rails strip all except numbers commas and decimal points

Hi I've been struggling with this for the last hour and am no closer. How exactly do I strip everything except numbers, commas and decimal points from a rails string? The closest I have so far is:-
rate = rate.gsub!(/[^0-9]/i, '')
This strips everything but the numbers. When I try add commas to the expression, everything is getting stripped. I got the aboves from somewhere else and as far as I can gather:
^ = not
Everything to the left of the comma gets replaced by what's in the '' on the right
No idea what the /i does
I'm very new to gsub. Does anyone know of a good tutorial on building expressions?
Thanks
Try:
rate = rate.gsub(/[^0-9,\.]/, '')
Basically, you know the ^ means not when inside the character class brackets [] which you are using, and then you can just add the comma to the list. The decimal needs to be escaped with a backslash because in regular expressions they are a special character that means "match anything".
Also, be aware of whether you are using gsub or gsub!
gsub! has the bang, so it edits the instance of the string you're passing in, rather than returning another one.
So if using gsub! it would be:
rate.gsub!(/[^0-9,\.]/, '')
And rate would be altered.
If you do not want to alter the original variable, then you can use the version without the bang (and assign it to a different var):
cleaned_rate = rate.gsub!(/[^0-9,\.]/, '')
I'd just google for tutorials. I haven't used one. Regexes are a LOT of time and trial and error (and table-flipping).
This is a cool tool to use with a mini cheat-sheet on it for ruby that allows you to quickly edit and test your expression:
http://rubular.com/
You can just add the comma and period in the square-bracketed expression:
rate.gsub(/[^0-9,.]/, '')
You don't need the i for case-insensitivity for numbers and symbols.
There's lots of info on regular expressions, regex, etc. Maybe search for those instead of gsub.
You can use this:
rate = rate.gsub!(/[^0-9\.\,]/g,'')
Also check this out to learn more about regular expressions:
http://www.regexr.com/

Bug in my regular expression

I'm trying to look at a string and reject anything that has seq= or app= in the string. Where it gets tricky is I need elements with q=something or p=something.
The seq= part of the string is always preceded an & and app= is always preceded by a ?
I have absolutely no idea where to start. I've been using http://www.rubular.com/ to try and figure it out but to no avail.
Any help would be hugely appreciated.
Based on your question, I believe you could just reject any strings that match the following expression:
[\?&](?:seq|app)=
This will match any string that contains a ? or & followed by either app= or seq=. The ?: inside the parentheses just tells the regular expression not to bother to capture matching groups as sub-matches. They're not really necessary, but what the heck.
Here's a Rubular link with some samples.

Regular expression to validate string like "1/2"

I need to match only strings that include one character / between numbers or integer numbers.
Examples:
1 YES
1/2 YES
some_text NO
some/test NO
some NO
2///2 NO
/12 NO
1/2/ NO
1.2/3 NO
Edit:
By rubular.com i`m tried to check this regex: /\d+(\/\d+)?
How regex should looks like?
If you're only including whole numbers or fractions:
\d+(\/\d+)?
If you also want to allow decimals:
\d+(\.\d+)?(\/\d+(\.\d+)?)?
Edit: Note that I'm making a lot of assumptions about what you really want. Bart Kiers's comments to your question are very important -- I took the liberty of assuming that what you want is numbers. If that isn't true, please clarify the question.
Edit2: I'm also making one more important assumption. Your question says "strings that include / or integer number." If you want to make sure that the string is ONLY a number and nothing else, then add ^ to the beginning of the line and $ to the end. Example:
^\d+(\/\d+)?$

printf and formatting rules

I'd like to know if all formatting rules of printf functions currently work (or are implemented) in F# ?
For instance, if I want to align arguments on 9 characters (padding with spaces or 0), I would use:
printfn "%9A %9A" arg1 arg2 //don't seem to work
Thanks!
Do check out the docs
http://msdn.microsoft.com/en-us/library/ee370560(v=VS.100).aspx
(and possibly also these
http://en.wikibooks.org/wiki/F_Sharp_Programming/Input_and_Output
http://blogs.msdn.com/dsyme/archive/2010/01/08/some-tips-and-tricks-for-formatting-data-in-f-interactive-and-a-in-sprintf-printf-fprintf.aspx
)
though I am unclear about the fine points of the spec and implementation, especially regarding the %A specifier, which does various magical things. I'll see what other info I can dig up right now...
Read the documentation:
http://msdn.microsoft.com/en-us/library/ee370560.aspx

Resources