language-agnostic

Given n numbers find minimum perimeter triangle

家住魔仙堡 提交于 2020-01-30 02:34:31
问题 Encountered this problem in coding contest. Could think only O(n^2 log(n)) solution. I guess the expected was O(n log n). I am given n numbers, I have to find 3 numbers that follow triangle inequality and have the smallest sum. I hope this is quite easy to understand. Eg. 10,2,5,1,8,20 Answer is 23 = (5+8+10) 回答1: The longest side should be the successor of the second longest; otherwise, we could shrink the longest and thus the perimeter. Now you can use your binary search to find the third

How to handle required properties for Domain Entities?

主宰稳场 提交于 2020-01-25 07:19:05
问题 I have a UserEntity that is eventually persisted in the DB according to it's id property. In this case, the id property is obviously sensitive, because changing it would cause the UserEntity to be saved over a different UserEntity when persisted later. I would therefore like to help safe guard against something like this happening... Option 1. Do I FORCE the id to be passed into the constructor, thereby removing the Setter? This would mean that every UserEntity that the Repository is given to

When is handling a null pointer/reference exception preferred over doing a null check?

心已入冬 提交于 2020-01-24 12:42:45
问题 I have an odd question that I have always thought about, but could never see a practical use for. I'm looking to see if there would be enough justification for this. When is handling a null pointer/reference exception preferred over doing a null check? If at all. This applies to any language that has to deal with null pointers/references which has exception handling features. My usual response to this would be to perform a null check before doing anything with the pointer/reference. If non

When is handling a null pointer/reference exception preferred over doing a null check?

和自甴很熟 提交于 2020-01-24 12:42:26
问题 I have an odd question that I have always thought about, but could never see a practical use for. I'm looking to see if there would be enough justification for this. When is handling a null pointer/reference exception preferred over doing a null check? If at all. This applies to any language that has to deal with null pointers/references which has exception handling features. My usual response to this would be to perform a null check before doing anything with the pointer/reference. If non

When is handling a null pointer/reference exception preferred over doing a null check?

此生再无相见时 提交于 2020-01-24 12:42:14
问题 I have an odd question that I have always thought about, but could never see a practical use for. I'm looking to see if there would be enough justification for this. When is handling a null pointer/reference exception preferred over doing a null check? If at all. This applies to any language that has to deal with null pointers/references which has exception handling features. My usual response to this would be to perform a null check before doing anything with the pointer/reference. If non

Who's responsible for the next View?

限于喜欢 提交于 2020-01-24 09:25:07
问题 In an archetypical MVC architectur, where does the logic go, that determines which view to show next? The assumption is some kind of app with several views (windows) that may or may not be visible at different times, depending on user actions. For instance, sometimes the application may need the user to fill out a form with additional details, other times it may not. Is it the controllers responsibility to ask for a specifik view to become visible? Am I thinking about this wrong? Maybe the

How can I keep track of character positions after I remove elements from a string?

泄露秘密 提交于 2020-01-24 09:21:06
问题 Let us say I have the following string: "my ., .,dog. .jumps. , .and..he. .,is., .a. very .,good, .dog" 1234567890123456789012345678901234567890123456789012345678901 <-- char pos Now, I have written a regular expression to remove certain elements from the string above, in this example, all whitespace, all periods, and all commas. I am left with the following transformed string: "mydogjumpsandheisaverygooddog" Now, I want to construct k-grams of this string. Let us say I were to take 5-grams

Bare-minimum text sanitation

杀马特。学长 韩版系。学妹 提交于 2020-01-24 06:55:42
问题 In an application that accepts, stores, processes, and displays Unicode text (for the purpose of discussion, let's say that it's a web application), which characters should always be removed from incoming text? I can think of some, mostly listed in the C0 and C1 control codes Wikipedia article: The range 0x00 - 0x19 (mostly control characters), excluding 0x09 (tab), 0x0A (LF), and 0x0D (CR) The range 0x7F - 0x9F (more control characters) Ranges of characters that can safely be accepted would

Internationalization on database level

守給你的承諾、 提交于 2020-01-24 05:53:07
问题 Could anyone point me to some patterns addressing internationalization on the database level tasks? The simplest way would be to add a text column for every language for every text column, but that is somehow smelly - really i want to have ability to add supported languages dynamically. The solution i'm coming to is one main language that is saved in the model and a dictionary entity that gets queried for translations and saved translations to. All i want is to hear from other people who have

What is wrong with using DateTime.Now. as main part of Unique ID?

主宰稳场 提交于 2020-01-24 02:55:35
问题 I used to use RNGCryptoServiceProvider to generate string-based Order ID's, but, there were 4 instances where ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@$%^*()_- would generate an already-existing Order ID. And it got me thinking... Why can't we just use something like: <html> ... <p>@GenerateOrderId()</p> ... </html> and: public string GenerateOrderId() { return "OID" + DateTime.Now.Year + DateTime.Now.Month + DateTime.Now.Day + DateTime.Now.Hour + DateTime.Now.Minute + DateTime.Now.Second +