[Solved] Java Variable Substitution

This is normally solved with just a String#replaceAll, but since you have a custom, dynamic replacement string, you can to use a Matcher to efficiently and concisely do the string replacement. public static String parse(String command, String… args) { StringBuffer sb = new StringBuffer(); Matcher m = Pattern.compile(“\\$(\\d+)”).matcher(command); while (m.find()) { int num = Integer.parseInt(m.group(1)); … Read more

[Solved] Substitute LHS of = in R

1) eval/parse Create a cmd string, parse it and evaluate it: f2 <- function(DF, x, env = parent.frame()){ cmd <- sprintf(“mutate(%s, %s = mean(v1))”, deparse(substitute(DF)), x) eval(parse(text = cmd), env) } f2(DF, “v1_name”) giving v1 v1_mean 1 1 2 2 2 2 3 3 2 … etc … 2) eval/as.call Another way is to construct … Read more

[Solved] Caesar cypher in Python

Use split() numbers = input(“Please type a code: “).split() # [’16’, ’25’, ’20’, ‘8’, ’14’, ‘0’, ‘9’, ‘,19’, ‘0’, ‘3’, ’15’, ’15’, ’12’] Use for .. in .. for num in numbers: print( x[int(num)] ) If you use 0 as space you have to add space at the begginig of list x = [‘ ‘, … Read more