Permutation And Combination method in MathJax using Asscii Code - mathjax

Need a Permutation And Combination mathJaX symbol for the nCr and nPr

You can use this:
nCk => {}_n \mathrm{ C }_k
nPk => {}_n \mathrm{ P }_k

You can use
{n \choose r} or \binom{n}{r}

Related

Defining a list of strings using snowball

How can i define a list string using snowball ?
I have tried to do it like this :
define patterns (
'{m}{f}{i}{l}' or '{f}{a}{i}{l}' or .......
)
How to get the list length ? how to deal with every pattern ?
An example:
groupings ( v v_WXY valid_LI )
stringescapes {}
define v 'aeiouy'
define v_WXY v + 'wxY'
define valid_LI 'cdeghkmnrt'
Combine strings into groupings. Example drawn from: http://snowball.tartarus.org/algorithms/english/stemmer.html

How to get int from float in picat?

I try to to read a line as string from console (stdin) in picat and get its half:
main =>
L = read_line(),
B = L.length/2,
S = L.slice(1,B),
println(S).
crashes with error(integer_expected(2.0),slice)
when int used instead of B - no crash. So how to turn B into integer?
you could use built-in function such as floor, round or ceiling from math module (more functions here). So you could modify your code like this:
main =>
L = read_line(),
B = round(L.length/2),
S = L.slice(1,B),
println(S).
Try either using integer(..) function to convert L.length/2 to integer or use to_integer() function....should do it for you.
type inference plays an essential role in functional evaluation. (/ /2) it's a floating point arithmetic operator, but slice/2 expects an integer. So you should instead use (// /2).
Picat> L=read_line(),println(L.slice(1,L.length//2)).
123456789
1234
L = ['1','2','3','4','5','6','7','8','9']
yes

Find all possible variations of a string of letters

Newb programmer here, I'm most familiar with Python but also learning C and Java, so either of 3 would be fine.
What I have is a string of letters, say:
ABXDEYGH
However say,
X is possible to be M and N.
Y is possible to be P and Q.
In this example, I would like basically to print all possible variations of this string of letters.
Like:
ABMDEPGH
ABNDEPGH
ABMDEQGH
ABNDEQGH
Any help would be appreciated. Thanks in advance
This boils down to a simple problem of permutations. What you care about is the part of the text that can change; the variables. The rest can be ignored, until you want to display it.
So your question can be more simply stated: What are all the possible permutations of 1 item from set X and another item from set Y? This is known as a cross-product, sometimes also simply called a product.
Here's a possible Python solution:
import itertools
x = set(['M', 'N'])
y = set(['P', 'Q'])
for items in itertools.product(x, y)
print 'AB{0}DE{1}GH'.format(*items)
Note that the print ''.format() command uses the "unpack arguments" notation described here.
why dont you write two loops. one to replace all possible characters with X and one for Y.
foreach(char c in charSet1){
// replaces X
foreach(char ch in charSet2){
// replace Y
}
}

Prolog: how to convert string to integer?

So as the title says - how do you convert a string into an integer?
the idea is something like this:
convert(String,Integer).
examples:
convert('1',1).
convert('33',33).
I'm using swi prolog
Use atom_number/2.
E.g:
atom_number('123', X).
X = 123.
Assuming you really meant a string and not an atom, use number_codes.
?- number_codes(11, "11").
true.
?- number_codes(11, Str).
Str = [49, 49]. % ASCII/UTF-8
?- number_codes(N, "11").
N = 11.
Perhaps use of atom_codes(?Atom, ?String) and number_chars(?Number, ?CharList) would do it.
Quite an old, but there is a predicate in SWI Prolog: number_string(N, S).
Docs
number_string(123, S).
S = "123".
For those who are still looking for it.
A simple example using Visual Prolog 10
==============================
% UNS-EPISI-LAB-IA
implement main
open core
clauses
run() :-
console::write("Valor de A? "),
A = console::readLine(),
console::write("Valor de B? "),
B = console::readLine(),
Areal = toTerm(real, A),
Breal = toTerm(real, B),
console::write("A + B = ", Areal + Breal),
_ = console::readChar().
end implement main
goal
console::runUtf8(main::run).
in Visual Prolog convert:
X=toTerm(real,H).
real/integer/unsigned...

Simple haskell string manage

Theres is a little problem I want to solve with Haskell:
let substitute a function that change all of the wildcards in a string for one concrete parameter. The function has de signature of:
subs :: String -> String -> String -> String
-- example:
-- subs 'x' "x^3 + x + sin(x)" "6.2" will generate
-- "6.2^3 + 6.2 + sin(6.2)"
You could use the Text.Regex package.
Your example might look something like this:
import Text.Regex(mkRegex, subRegex)
subs :: String -> String -> String -> String
subs wildcard input value = subRegex (mkRegex wildcard) input value
See http://bluebones.net/2007/01/replace-in-haskell/ for an example which looks exactly as the piece of code you are looking for.
You can use text-format-simple library for such cases:
import Text.Format
format "{0}^3 + {0} + sin({0})" ["6.2"]
Use regular expressions (Text.Regex.Posix) and search-replace for /\Wx\W/ (Perl notation). Simply replacing x to 6.2 will bring you trouble with x + quux.
Haskell Regex Replace for more information (I think this should be imported to SO.
For extra hard-core you could parse your expression as AST and do the replacement on that level.

Resources