logic

Finding closest matching time for each patient

淺唱寂寞╮ 提交于 2019-11-30 22:05:06
I have two sets of data: First set: patient<-c("A","A","B","B","C","C","C","C") arrival<-c("11:00","11:00","13:00","13:00","14:00","14:00","14:00","14:00") lastRow<-c("","Yes","","Yes","","","","Yes") data1<-data.frame(patient,arrival,lastRow) Another set of data: patient<-c("A","A","A","A","B","B","B","C","C","C") availableSlot<-c("11:15","11:35","11:45","11:55","12:55","13:55","14:00","14:00","14:10","17:00") data2<-data.frame(patient, availableSlot) I want to create add a column to the first dataset such that for each last row of each patient, it shows the available slot that is closest to

Best resize and or crop logic

て烟熏妆下的殇ゞ 提交于 2019-11-30 20:51:09
I've come across this a few times and thought it would be good to put it out there. What's your best image resize and/or crop logic. The idea being that some method is called with a target image, dimensions and a crop flag - this would return or save off or whatever the desired image. Mine is below. Converted from VB to C# so yes there'll be small bugs but logic is what we're looking at. // INIT // On/off bool WeAreCropping = true; // Get some dimensions int TargetWidth = RequestedWidth; int TargetHeight = RequestedHeight; int SourceWidth = SourceImage.Width; int SourceHeight = SourceImage

Relational operations using only increment, loop, assign, zero

萝らか妹 提交于 2019-11-30 20:38:55
This is a follow up question for: Subtraction operation using only increment, loop, assign, zero We're only allowed to use the following operations: incr(x) - Once this function is called it will assign x + 1 to x assign(x, y) - This function will assign the value of y to x (x = y) zero(x) - This function will assign 0 to x (x = 0) loop X { } - operations written within brackets will be executed X times For example, addition can be implemented as follows: add(x, y) { loop x { y = incr(y) } return y } How do I implement the relational operators using these four operations? The relational

Why do Strings start with a “” in Java? [duplicate]

偶尔善良 提交于 2019-11-30 16:27:52
问题 This question already has answers here : Closed 9 years ago . Possible Duplicate: Why does “abcd”.StartsWith(“”) return true? Whilst debugging through some code I found a particular piece of my validation was using the .startsWith() method on the String class to check if a String started with a blank character Considering the following : public static void main(String args[]) { String s = "Hello"; if (s.startsWith("")) { System.out.println("It does"); } } It prints out It does My question is,

What' s the difference between <= and := in VHDL

丶灬走出姿态 提交于 2019-11-30 12:45:04
Currently, I am learning some FPGA design techniques using VHDL, my problem is whether we can use := and <= interchangeably in VHDL or not, though I've seen the use of := in constants declarations and <= in assignments? Thanks in advance! The rules are a little more complex than this, but basically: you use <= to do signal assignment, which takes effect on the next delta cycle. You use := to do variable assignment, which takes place immediately. So if you have a signal, you always use <= . If you have a variable, you always use := . Some places where this is not quite that case that you will

Hungarian Algorithm: How to cover 0 elements with minimum lines?

雨燕双飞 提交于 2019-11-30 11:33:38
I am trying to implement the Hungarian algorithm in Java. I have an NxN cost matrix. I am following this guide step by step. So I have the costMatrix[N][N] and 2 arrays to track covered rows and covered cols - rowCover[N], rowColumn[N] (1 means covered, 0 means uncovered) How can I cover the 0s with the minimum number of lines? Can anyone point me in the right direction? Any help/suggestion would be appreciated. Check the 3rd step of the algorithm in the Wikipedia article (section Matrix Interpretation ) , they explain a way to compute the minimal amount of lines to cover all the 0's Update:

C# convert a string for use in a logical condition

感情迁移 提交于 2019-11-30 11:32:37
Is it possible to convert a string to an operator for use in a logical condition. For example if(x Convert.ToOperator(">") y) {} or if(x ">" as Operator y){} I appreciate that this might not be standard practice question, therefore I'm not interested in answers that ask me why the hell would want to do something like this. Thanks in advance EDIT: OK I agree, only fair to give some context. We have system built around reflection and XML. I would like to be able to say something like, for ease. <Value = "Object1.Value" Operator = ">" Condition = "0"/> EDIT: Thanks for your comments, I can't

Elegant way of reading a child property of an object

与世无争的帅哥 提交于 2019-11-30 10:56:42
问题 Say you are trying to read this property var town = Staff.HomeAddress.Postcode.Town; Somewhere along the chain a null could exist. What would be the best way of reading Town? I have been experimenting with a couple of extension methods... public static T2 IfNotNull<T1, T2>(this T1 t, Func<T1, T2> fn) where T1 : class { return t != null ? fn(t) : default(T2); } var town = staff.HomeAddress.IfNotNull(x => x.Postcode.IfNotNull(y=> y.Town)); or public static T2 TryGet<T1, T2>(this T1 t, Func<T1,

1 = false and 0 = true?

帅比萌擦擦* 提交于 2019-11-30 10:55:01
I came across an is_equals() function in a c API at work that returned 1 for non-equal sql tables (false) and 0 for equal ones (true). I only realized it after running test cases on my code, one for the positive example and one for the negative and they both failed which at first made little sense. The code in the API does not have a bug as the output was recorded correctly in its documentation. My questions - are there upside down worlds / parallel universes / coding languages where this logical NOTing is normal? Isn't 1 usually true? Is the coder of the API making an error? It is common for

Why if (n & -n) == n then n is a power of 2?

蓝咒 提交于 2019-11-30 10:05:47
问题 Line 294 of java.util.Random source says if ((n & -n) == n) // i.e., n is a power of 2 // rest of the code Why is this? 回答1: The description is not entirely accurate because (0 & -0) == 0 but 0 is not a power of two. A better way to say it is ((n & -n) == n) when n is a power of two, or the negative of a power of two, or zero. If n is a power of two, then n in binary is a single 1 followed by zeros. -n in two's complement is the inverse + 1 so the bits lines up thus n 0000100...000 -n 1111100