Can I use the function yes () to return 1 [closed] - function

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
Is the following function is correct?
local function yes()
return 1
end
local function no()
return 0
end
Can I use it to set the values ​​of the variables in this way?
local May_I = yes()
if May_I ~= 0 then
-- Yes I can do that
end
I like numbers, but sometimes they are not very precise.

You can deal with the imprecision you mentioned like so:
> epsilon = 1e-2
> function yes()
>> return 1
>> end
> if math.abs( yes() - 1 ) <= epsilon then
>> print("Yes I can")
>> end
Yes I can
Or alternately, be precise and use true and false.

Related

Why is the result of (a+b+c')(a'b'+c) not 1? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about programming within the scope defined in the help center.
Closed 3 years ago.
Improve this question
So I got his problem as homework in my course, when I solved it the result I came up with was 1, but everywhere I check the solution stops at line 4 is if it is the final solution, but I can't spot the error in my logic for some reason!
Line1: (a+b+c')(a'b'+c)
Line2: =aa'b'+ba'b'+c'a'b'+ac+bc+c'c
Line3: =0+0+c'a'b'+ac+bc+0
Line4: =c'a'b'+ac+bc
Line5: =c'a'b'+c(a+b)
Line6: =c'+c(a'b'+(a+b))
Line7: =1*(a'b'+(a+b))
Line8: =1
You can do a very little bit better if XOR (^) is a primitive operation in your system:
Line1: (a+b+c')(a'b'+c)
Line2: = aa'b'+ba'b'+c'a'b'+ac+bc+c'c
Line3: = 0+0+c'a'b'+ac+bc+0
Line4: = c'a'b'+ac+bc
Line5: = c'a'b'+c(a+b)
Line6: = c'a'b'+c(a'b')'
Line7: = c^(a'b')
Your error is the following:
Line5: = c'a'b'+c(a+b)
Line6: = c'+c(a'b'+(a+b))
Clearly, lines 5 and 6 do not show equivalent expressions because c=0 satisfies the second regardless of a and b whereas c=0, a=1 does not satisfy the first.

Grouping WHERE and AND as one satement [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 3 years ago.
Improve this question
Im trying run this sql statement but its not working..
the select statement is ok but its just the bottom part that's giving me trouble.
SELECT VRVDIL.INVOICE_DATE,
VRVDIL.INVOICE_NO,
VRVDIL.DEAL_NO,
VRVDIL.COST,
VVD.DEAL_DATE,
VVD.SALESMAN_NAME,
VVD.SIGNED_DATE,
VVD.STOCK_NO,
VVD.VEHICLE_ID,
VVD.VEHICLE_SALES_GROUP_DESCRIPTION,
VVD.INVOICE_TO_NAME,
VRVS.DATE_SOLD,
VRVS.DAYS_IN_STOCK_BEFORE_SOLD,
VRVS.LOCATION_NAME,
VRVS.STOCKED_DATE,
VRVS.VEHICLE_CLASS_DESCRIPTION,
VRVRD.BUYER_NAME,
VRVRD.PURCHASING_PRICE,
VRVRD.SELLING_PRICE,
VRV.VIN,
VRV.VEHICLE_TYPE,
VRV.REGO_NO,
VRV.REGISTRATION_EXPIRY_DATE,
VRV.MODEL_ID,
VRV.MAKE_ID,
VRVDOL.QTY
FROM VW_RG_VEHICLE_DEAL_INVOICE_LINE VRVDIL,
VW_VEHICLE_DEAL VVD,
VW_RG_VEHICLE_DEAL_ORDER_LINE VRVDOL,
VW_RG_VEHICLE VRV,
VW_RG_VEHICLE_STOCKCARD VRVS,
VW_RG_VEHICLE_REGISTER_DETAIL VRVRD
WHERE (VRVDIL.VEHICLE_DEAL_KEY = VVD.VEHICLE_DEAL_KEY
AND VRVDOL.VEHICLE_DEAL_KEY = VVD.VEHICLE_DEAL_KEY
AND VVD.VEHICLE_KEY = VRV.VEHICLE_KEY
AND VRVS.VEHICLE_STOCKCARD_KEY = VVD.VEHICLE_STOCKCARD_KEY
AND VRVS.VEHICLE_KEY = VRV.VEHICLE_KEY
AND VRVS.VEHICLE_STOCKCARD_KEY = VRVRD.VEHICLE_STOCKCARD_KEY
what is the error?
Do you miss a closing parenthesis?
WHERE (VRVDIL.VEHICLE_DEAL_KEY = VVD.VEHICLE_DEAL_KEY
AND VRVDOL.VEHICLE_DEAL_KEY = VVD.VEHICLE_DEAL_KEY
AND VVD.VEHICLE_KEY = VRV.VEHICLE_KEY
AND VRVS.VEHICLE_STOCKCARD_KEY = VVD.VEHICLE_STOCKCARD_KEY
AND VRVS.VEHICLE_KEY = VRV.VEHICLE_KEY
AND VRVS.VEHICLE_STOCKCARD_KEY = VRVRD.VEHICLE_STOCKCARD_KEY)
At the end of the last AND condition, you should put a closing parenthesis.

beautifulsoup parse every html files in a folder webscraping [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 5 years ago.
Improve this question
My task is to read every html file from a directory. Conditions are to find whether each file contains tags
(1) <strong>OO</strong>
(2) <strong>QQ</strong>
Then
Your write function is nested in the for loop, that's why you write multiple lines to your index.txt, just move the write out of the loop and put all your parti text to a variable parti_names like this:
participants = soup.find(find_participant)
parti_names = ""
for parti in participants.find_next_siblings("p"):
if parti.find("strong", text=re.compile(r"(Operator)")):
break
parti_names += parti.get_text(strip=True)+","
print parti.get_text(strip=True)
indexFile = open('index.txt', 'a+')
indexFile.write(filename + ', ' + title.get_text(strip=True) + ticker.get_text(strip=True) + ', ' + d_date.get_text(strip=True) + ', ' + parti_names + '\n' )
indexFile.close()
Update:
You can work with basename to get the file name:
from os.path import basename
# you can call it directly with basename
print(basename("C:/Users/.../output/100107-.html"))
Output:
100107-.html

Angular2 how to display an array of numbers [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
Whats is the most elegant solution in angular2 for displaying an html table of z numbers in x rows and y columns?
X, Y and Z are numbers not necessarily collections. Also the table should contain numbers 1 to z.
I would do it like this : Plunker
Component
rows : any[];
cols : any[];
constructor() {
this.rows = Array(50).fill('');
this.cols = Array(10).fill('');
}
Template :
<table>
<tr *ngFor="let row of rows; let rowId = index">
<td *ngFor="let col of cols; let colId = index">{{rowId + colId*10+1}}</td>
</tr>
</table>

calculate a boolean flag [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I have a very basic question related to boolean logic.
I have two boolean flags- flagA and flagB. I need to calculate flagC based on the values of flagA and flagB.
The code/rules are:
if($flagA && $flagB) {
$flagC = true;
} else if (!$flagA || !$flagB) {
$flagC = false;
} else if(!$flagA && !$flagB) {
$flagC = true;
}
These rules match with the XNOR truth table - http://en.wikipedia.org/wiki/XNOR_gate
I want to find out different ways to re-write the above code(if possible) with:
fewer lines of code
better performance (even if it is a minute difference)
using bit shifting?
The languages I am hoping to write this in - php, ruby/ruby on rails.
Any help/pointers will be great!
Thanks!
Don't use these languages much but this might work:
$flagC = ($flagA == $flagB);
From the link posted: http://en.wikipedia.org/wiki/XNOR_gate
two-input version implements logical equality, behaving according to the truth table to the right. A HIGH output (1) results if both of the inputs to the gate are the same. If one but not both inputs are HIGH (1), a LOW output (0) results.
So flagC is true when flagA equals flagB.
if($flagA && $flagB) {
$flagC = true;
} else {
$flagC = false;
}
(Your second rule covers all other cases.)