guys whats problem with this source?
i use this to check MD5s but only first md5 checked?
if(md5("main\iw_00") != "92d86b9137f249a51ce14256362514bc"
|| md5("main\iw_01") != "80e13bc5fb2078728405bfae9b529414"
|| md5("main\iw_02") != "be2c0a1cbf5858e978dc39a8e00bff62"
|| md5("main\iw_03") != "223fc8672db4e0d3ef38f8348b9be6da"
|| md5("main\iw_04") != "8fde7ed770c6136039206edbb24f5b8a")
Compare string literals by pointer is usually meaningless. Try strcmp or something like.
strcmp(md5("main\iw_01"), "80e13bc5fb2078728405bfae9b529414") != 0
main\iw01 is most probably not what you really want. \ starts an escape sequence. In most cases the correct usage (especially since \i doesn't exist) would be main\\iw01.
This condition is true all the time , you can not use ! and || togther .
Related
Trying to make movement halt when (x) key is lifted (w,a,s,d) however I do not want the movement to stop if another key is held down. This is the snippet of code I was trying to use which was not working:
if (event.keyName == 'w' and event.phase == 'up') then
if (event.keyName == 's' and event.phase == 'down') then
testObj.deltaPerFrame = {testObj.deltaPerFrame[1], 2 }
else
testObj.deltaPerFrame = {testObj.deltaPerFrame[1], 0 }
return true
end
end
You have the same key event object so event.keyName or event.phase cannot have two different values. Hence your condition doesn't make any sense.
Please refer to the CoronaSDK manual.
https://docs.coronalabs.com/api/event/key/keyName.html
You'll have to maintain a list of keys that are currently pressed.
I'm having a problem that seems way more easy than it is. I think its more of an algorithmic problem than a coding one.
EDIT:
Imagine you have a database with a name and N boolean parameters, like if the person is blonde or not, if the person likes baseball or not, if person have a smartphone or not etc...
How could you print the name of someone that likes baseball AND is blonde, but doesn't matter if any of the other N parameters are true of false? How can I do that without having to write a test for every single of the (N^2)-1 possibilities?
I created a dictionary that maps a string to a struct with 4 boolean variables and some strings.
I want the user to select which booleans are important to them and return only the information that is true for all variable that he chose.
Something like a checkbox which you can use to filter a column in excel.
For instance if a user chose variables 1 and 2, I would like to know if there is a better way to return the result rather than testing every one of the 16 possibilities, like:
void filter(map<string, Mystruct> Mydictionary, bool bool1, bool bool2, bool bool3, bool bool4){
if(bool1 == true && bool2 == true && bool3 == false && bool4==false){
cout << Mydictionary.bool1Info << Mydictionary.bool2Info
if(bool1 == true && bool2 == false && bool3 == false && bool4==false)
...
Even more, for me its only important to test the booleans that the user picked up, so even if he didn't choose boolean3, it's not important to test if its true or false.
Any ideas?
I would be very glad if anyone could help me with this one
I can help you with your algorithm part ,
instead of checking all 16 possibilities just check 4 conditions separately for bool1,2,3,4 and print their info if they are true.
This way you can complete your task with only 4 if statements.
Hope this answers your query.
Hi guys My code looks like
iif(not isnull(ltrim(rtrim(a))) or not is_spaces(ltrim(rtrim(a))) or ltrim(rtrim(a))!='' or length(ltrim(rtrim(a)))!=0 or ltrim(rtrim(a))!=null or ltrim(rtrim(a))!='NULL'and not isnull(ltrim(rtrim(b))) or not is_spaces(ltrim(rtrim(b))) or ltrim(rtrim(b))!='' or length(ltrim(rtrim(b)))!=0 or ltrim(rtrim(b))!=null or ltrim(rtrim(b))!='NULL',null,ltrim(rtrim(a))).
If both a and b are not null then i have to make a as null else pass the value of a as it is. But my logic is not working fine and I've checked with session logs by giving verbose data for expression transformation still my value of b which is [NULL] coming in session logs has been considered as not null . Can you please help me guys for giving exact statements to identify the null values properly.
I've tried with is_spaces, empty strings.length!=0 options. But still null values are considered as an actual values which is wrong.
I think you need to group the conditions for a and b as shown below
IIF
(
(
NOT ISNULL(LTRIM(RTRIM(a)))
OR NOT IS_SPACES(LTRIM(RTRIM(a)))
OR LTRIM(RTRIM(a)) != ''
OR LENGTH(LTRIM(RTRIM(a))) != 0
OR LTRIM(RTRIM(a)) != NULL
OR LTRIM(RTRIM(a)) != 'NULL'
)
AND
(
NOT ISNULL(LTRIM(RTRIM(b)))
OR NOT IS_SPACES(LTRIM(RTRIM(b)))
OR LTRIM(RTRIM(b)) != ''
OR LENGTH(LTRIM(RTRIM(b))) != 0
OR LTRIM(RTRIM(b)) != null
OR LTRIM(RTRIM(b)) != 'NULL'
)
,NULL
,LTRIM(RTRIM(a))
)
Hope this helps.
NOTE: I have not optimized your checks for checking null conditions.
So I've been trying to figure out what is wrong with my if-condition, but I am getting nowhere. I am still new to R, so maybe I am not understanding some very basic concept here?
I have a dataframe (dc) to which I appended a column with logical "FALSE". Now I want to change each FALSE into a TRUE based on the values in two columns of dc (dc$Probe and dc$Resp) that I specified using regexpr().
What it does so far is that, for both if-conditions, it changes each FALSE into TRUE regardless of the values in column 5 of dc. When I run the if-conditions seperately, I can see that they seem to be working fine on the OR-part of the condition, meaning the code only generates TRUE when the strings in dc$Probe match one of the strings specified in the OR-part. However, the AND-part seems to be ignored? Thus, when I run the complete code, I get a column with only TRUE, which is not what I want.
Edit: I should get a TRUE only if the string in Probe ends in a certain pattern (as specified in either of the two if conditions I wrote) and if the corresponding value in Resp is a "100" for the patterns specified in my first condition or a "200" for the patterns specified in my second condition. Thus, for strings ending in (sg|s|w1|w3|s1|s2), Resp must be "100" to get a TRUE and for strings ending in (\d\dg|\d\d), Resp must be "200" to get a TRUE. All other cases should be FALSE. For example, if a string ends in s1 and the corresponding value in Resp is 200, the code should return FALSE.
Edit: Some example data:
>dc<-data.frame(Subject=rep("SN",6), item.c=(1:6), Stim=c("XYZc02s03","XYZc01s30","XYZc02s29", "XYZc01s38", "XYZc02s11", "XYZc06w21"), Probe=c("XYzf02s03","XYZf01s30g","XYZf02s29w1","XYZf01s38sg","XYZf02s11s","XYZv06w21s1"), Resp=c(200, 100, 100, 100, 100, 200))
This is my code:
>dc$Resp<-as.character(dc$Resp) #column 5 in dc
dc$Probe<-as.character(dc$Probe)
dc$correct_response <- FALSE
for (i in 1:nrow(dc)) {
if (regexpr("^.*sg$", dc$Probe[i])==1 || regexpr("^.*s$", dc$Probe[i])==1 || regexpr("^.*w1$", dc$Probe[i])==1 || regexpr("^.*w3$", dc$Probe[i])==1 || regexpr("^.*s1$", dc$Probe[i])==1 || regexpr("^.*s2$", dc$Probe[i])==1 && dc[i,5]=="100") {(dc$correct_response[i]<- TRUE)}
if (regexpr("^.*\\d\\dg$", dc$Probe[i])==1 || regexpr("^.*\\d\\d$", dc$Probe[i])==1 && dc[i,5]=="200") {(dc$correct_response[i]<- TRUE)}
}
Is there something wrong with the regular expressions I am using? I checked them with glob2rx() and it seems like they are ok...Is my use of "OR" (||) or/and "AND" (&&) incorrect? How do I implement the AND-part properly? I have also tried the following code for the AND-part, but it didn't change anything:
regexpr("200", dc$Resp[i])==1
I read the R-help on regular expressions and control flow, but I still don't see what I am doing wrong. Consulting other webpages on logical expressions did not help me either.
Please help!
Im wondering if it can all be reduced to the following:
dc<- read.table(header=T,text="Subject item.c Stim Probe Resp
SN 1 XYZc02s03 XYzf02s03 200
SN 2 XYZc01s30 XYZf01s30g 100
SN 3 XYZc02s29 XYZf02s29w1 100
SN 4 XYZc01s38 XYZf01s38sg 100
SN 5 XYZc02s11 XYZf02s11s 100
SN 6 XYZc06w21 XYZv06w21s1 200")
cond1<-regexpr("^.*(sg|s|w1|w3|s1|s2)$", dc$Probe)==1 & dc$Resp==100
cond2<-regexpr("^.*(\\d\\dg|\\d\\d)$", dc$Probe)==1 & dc$Resp==200
dc$correct_response<-cond1|cond2
For one thing, you are missing a logical operator between the 2nd and 3rd clauses of your first if statement.
I have a word dictionary and I'm looking for regex that can help me to get words with only one character diff. For example say for word BIG it could be words BIT, BUG etc. Length of the words should be equal.
Thank you!
/\b([a-z]ig|b[a-z]g|bi[a-z])\b/i
You'd have to do this with every word. Regex alone is probably not the best tool for this job.
Use something like this, perhaps?
>>> def word_difference(word1, word2):
... c1, c2 = list(word1), list(word2)
... return [(i, c1[i], c2[i]) for i in in range(len(c1)) if c1[i] != c2[i]]
>>> word_difference("foo", "bar")
[(0, 'f', 'b'), (1, 'o', 'a'), (2, 'o', 'r')]
>>> word_difference("big", "bug")
[(1, 'i', 'u')]
Obviously, the length of the list returned is the number of characters that are different. I assume this is what you want, since you didn't state whether the characters may be in different positions or not - but that's just as easy, you can use sets.
I found nearly the same solution than the one using ideone.
But, as vkolodrevskiy wrote “to get words with only one character diff“,
I respected it.
My code is in Python. No language precised in the question.
import re
word = 'main'
RE = '|'.join(word[0:i]+'(?!'+char+')[a-z]'+word[i+1:] for i,char in enumerate(word))
RE = '('+RE+')'
print RE
ch = 'the main reason is pain due to rain. hello muin, where is maih ?'
print re.findall(RE,ch)
Well, you could do a bunch of complicated regular expressions, or ingenius ones, but I found something that I wanted to tell you about that may be a lot easier.
Check out the Levenshtein module to get the hamming distance between two strings. Then just get the ones that have a distance of one.
To install you can use pip install python-levenshtein. If you use Ubuntu or such you can use sudo apt-get install python-levenshtein. If you're on Windows, in order to fully utilize pip you'll need a C++ compiler (like Visual C++ 2010 express, if you're using Python 3, or Visual C++ 2008 express for Python 2.x; you can download those for free from Microsoft; do a web search for them if you want them).
import Levenshtein #Note the capital L
help(Levenshtein) #See the documentation
Levenshtein.hamming("cat", "sat") #Returns 1; they must be the same length, as you specified
There are lots of other cool functions besides hamming, though. Read the help (via the help function in the code above). The functions are actually surprisingly well-documented if you use the help function. Press q to quit the help, of course.
finally I did not use idea with regex, my solution looks like:
public boolean diffOneChar(String word1, String word2) {
int diff=0;
if(word1 == null || word2 == null) return false;
if(word1.length() == 0 || word2.length() == 0) return false;
if(word1.length() != word2.length()) return false;
for(int i=0; i<word1.length(); i++) {
if(word1.charAt(i)!=word2.charAt(i))
diff++;
}
return diff == 1;
}