subtraction

Prolog search for possible combination for subtracting 2 elements from a list

江枫思渺然 提交于 2019-12-20 04:07:51
问题 This is an extended problem from this page. Prolog possible removal of elements in a list For example, for a list X = [1,2,3], I can subtract like following: subtract 1 from 1st / 2nd element, and X becomes [1-1, 2-1, 3] = [0, 1, 3] = [1, 3] subtract 1 from 1st / 3rd element: X becomes [2, 2] subtract 1 from 2nd / 3rd element: X becomes [1, 1, 2] subtract 2 from 2nd / 3rd element: X becomes[1, 1] So, it is always subtracting 2 elements, and with the same number, but always a real number. Have

How to subtract 5 minute from date

点点圈 提交于 2019-12-20 03:00:06
问题 I have this data: `date +%Y-%m-%d`" 00:00:00" that return 2015-10-08 00:00:00 I would like cancel 5 minute: 2015-10-07 23:55:00 Many thanks 回答1: You need to subtract 5 minutes from a known point in time: $ date -d "00:00:00 today" Thu Oct 8 00:00:00 EDT 2015 $ date -d "00:00:00 today -5 minutes" Wed Oct 7 23:55:00 EDT 2015 You just need to add your format string. 回答2: There's more than one way to subtract a value from the current time, although this should match the format shown in your

PHP subtract 1 month from date formated with date ('m-Y')

半世苍凉 提交于 2019-12-18 07:28:09
问题 I'm trying to subtract 1 month from a date. $today = date('m-Y'); This gives: 08-2016 How can I subtract a month to get 07-2016 ? 回答1: <?php echo $newdate = date("m-Y", strtotime("-1 months")); output 07-2016 回答2: Warning! The above-mentioned examples won't work if call them at the end of a month. <?php $now = mktime(0, 0, 0, 10, 31, 2017); echo date("m-Y", $now)."\n"; echo date("m-Y", strtotime("-1 months", $now))."\n"; will output: 10-2017 10-2017 The following example will produce the same

Subtract n hours from a DateTime in Ruby

坚强是说给别人听的谎言 提交于 2019-12-17 23:15:10
问题 I have a Ruby DateTime which gets filled from a form. Additionally I have n hours from the form as well. I'd like to subtract those n hours from the previous DateTime. (To get a time range). DateTime has two methods "-" and "<<" to subtract day and month, but not hour. (API). Any suggestions how I can do that? 回答1: You could do this. adjusted_datetime = (datetime_from_form.to_time - n.hours).to_datetime 回答2: You can just subtract less than one whole day: two_hours_ago = DateTime.now - (2/24.0

Addition and Subtraction Assignment Operator With Sequelize

江枫思渺然 提交于 2019-12-17 21:15:25
问题 I would like to do an update by doing a simple addition on Sequelize. table: id || data 1 || 10 sample: db.table.update({ data : 1 }, { where: { id: 1 }}); after this query id || data 1 || 11 I know it's a simple question, but I could not find the solution. Which operator can I add and subtract? Thank you 回答1: Here it is : db.table.update({ field: Sequelize.literal('data + 1') }, { where: { id: 1 }})) OR User.findById(1).then(user => { // -----> First Way return user.increment('my-integer

MySQL “NOT IN” query not working

£可爱£侵袭症+ 提交于 2019-12-17 20:27:02
问题 I have a table with three columns: taxon_id , scientific_name_element_id , and parent_id . I want to find the elements that are children and not parents, so the termini of the structure. I found some sources that suggested that I use select taxon_id from taxon_name_element where taxon_id not in (select parent_id from taxon_name_element) But this does not work, I get an empty set when I can actually browse the entries and see that there is, for example, a taxon_id=1 , and NO parent_id=1

How to subtract two unsigned ints with wrap around or overflow

廉价感情. 提交于 2019-12-17 18:18:09
问题 There are two unsigned ints (x and y) that need to be subtracted. x is always larger than y. However, both x and y can wrap around; for example, if they were both bytes, after 0xff comes 0x00. The problem case is if x wraps around, while y does not. Now x appears to be smaller than y. Luckily, x will not wrap around twice (only once is guaranteed). Assuming bytes, x has wrapped and is now 0x2, whereas y has not and is 0xFE. The right answer of x - y is supposed to be 0x4. Maybe, ( x > y) ? (x

PHP subtract array values

安稳与你 提交于 2019-12-17 16:36:01
问题 I have an array with keys and values. Each value is an integer. I have an other array with the same keys. How can I subtract all of the values for the matching keys? Also there might be keys that do not occur in the second array but both arrays have the same length. If there is a key in array 2 that is not present in array 1 its value should be unchanged. If there is a key in the first array that is not in the second it should be thrown away. How do I do it? Is there any built-in function for

javascript subtract(-) keycode

你离开我真会死。 提交于 2019-12-17 09:46:30
问题 ok, i need my code to check if minus/subtract/- was pressed, if it was pressed i want an alert box to pop. i tried with both 109 and 189 key codes but i still don't get the desired result. although i press "-" i don't get that alert box 回答1: The JavaScript charCodes , which you test for during a keypress event, are ASCII. 109 is the correct keyCode , if used in a keydown or keyup event. "-" has a charCode of 45. 回答2: 1.event.keyCode = 109 is '-' on numpad 2.event.keyCode = 189 is'-' in

Subtract two rows' values within the same column using Mysql group by ID

无人久伴 提交于 2019-12-13 10:56:22
问题 I have a table as shown below. I want to do a partition and then subtract the values in the same column to get the difference. Since there is no partition or equivalent function available in MySQL, can anyone give me an idea of how to do it? I have worked out the partition but not the other part. SELECT ID,Date, @row_number:=CASE WHEN @ID=ID THEN @row_number+1 ELSE 1 END AS row_number, @ID:=ID AS ID,value FROM table1, (SELECT @row_number:=0,@ID:='') AS t ORDER BY id,Date; Input: ID Date Value