language-agnostic

Playing with infinity - Lazy arithmetics

本秂侑毒 提交于 2019-12-22 06:10:02
问题 Many modern programming languages allow us to handle potentially infinite lists and to perform certain operations on them. Example [Python]: EvenSquareNumbers = ( x * x for x in naturals() if x mod 2 == 0 ) Such lists can exist because only elements that are actually required are computed. (Lazy evaluation) I just wondered out of interest whether it's possible (or even practised in certain languages) to extend the mechanism of lazy evaluation to arithmetics. Example: Given the infinite list

Algorithm to fit as many events into a schedule as possible

眉间皱痕 提交于 2019-12-22 05:39:14
问题 I'm trying to find an algorithm that can arrange as many of these non-overlapping events into a schedule as possible (where any of these events can be added or removed from the schedule as needed). None of these events can overlap, but I want to fit as many of them into a daily schedule as possible: 12:00 PM - 12:45 PM: Lunch 1:00 AM - 3:00 AM: Math class 1 3:30 PM - 5:00 PM: Math class 2 7:00 PM - 10:00 PM: History class 1 9:00 PM - 11:00 PM: History class 2 Any time of day: Grocery shopping

Class member organization

北慕城南 提交于 2019-12-22 05:26:19
问题 What is the best way to sort class members? I'm in conflict with a team member about this. He suggests that we should sort the members alphabetically. I think it's better to organize in a semantic manner: important attributes first, related methods together, etc. What do you think? 回答1: I like semantic. Alphabetical doesn't seem to make a lot of sense to me, cause when you're looking for a member, you rarely know exactly what it's called. Also, if you're using any sort of naming convention

Multilingual spell checking with language detection

99封情书 提交于 2019-12-22 05:22:00
问题 I'm working on spell checking of mixed language webpages, and haven't been able to find any existing research on the subject. The aim is to automatically detect language at a sentence level within mixed language webpages and spell check each against their appropriate language automatically. Assume that we can ignore sentences which mix multiple languages together (e.g. "He has a certain je ne sais quoi"), and assume webpages can't contain more than 2 or 3 languages. Trivial example (Welsh +

Find the maximally intersecting subset of ranges

删除回忆录丶 提交于 2019-12-22 05:18:07
问题 If you have a set of ranges, such as the following simple example... [ [12, 25], #1 [14, 27], #2 [15, 22], #3 [17, 21], #4 [20, 65], #5 [62, 70], #6 [64, 80] #7 ] ... how do you compute the maximally intersecting subset (not sure quite how to phrase it, but I mean "the subset of ranges which intersects and has the highest cardinality") and determine the degree of intersection (cardinality of ranges in that subset)? Logically I can work it out, and might be able to translate that to a naive

How does adding MIN_VALUE compare integers as unsigned?

。_饼干妹妹 提交于 2019-12-22 04:46:07
问题 In Java the int type is signed, but it has a method that compares two ints as if they were unsigned: public static int compareUnsigned(int x, int y) { return compare(x + MIN_VALUE, y + MIN_VALUE); } It adds Integer.MIN_VALUE to each argument, then calls the normal signed comparison method, which is: public static int compare(int x, int y) { return (x < y) ? -1 : ((x == y) ? 0 : 1); } How does adding MIN_VALUE to each argument magically make the comparison unsigned? 回答1: This technique works

Algorithm for maximizing coverage of rectangular area with scaling tiles

[亡魂溺海] 提交于 2019-12-22 04:19:05
问题 I have N scalable square tiles (buttons) that need to be placed inside of fixed sized rectangular surface (toolbox). I would like to present the buttons all at the same size. How could I solve for the optimal size of the tiles that would provide the largest area of the rectangular surface being covered by tiles. 回答1: Let W and H be the width and height of the rectangle. Let s be the length of the side of a square. Then the number of squares n(s) that you can fit into the rectangle is floor(W

Why isn't every type of object serializable?

ⅰ亾dé卋堺 提交于 2019-12-22 04:04:48
问题 Why isn't every type of object implicitly serializable? In my limited understanding, are objects not simply stored on the heap and pointers to them on the stack? Shouldn't you be able to traverse them programatically, store them in a universal format and also be able to reconstruct them from there? 回答1: Some objects encapsulate resources like file pointers or network sockets that can't be deserialized to the state they were in when you serialized the object that contained them. Example: you

Is there an existing solution for these particular multithreaded data structure requirements?

本秂侑毒 提交于 2019-12-22 03:59:07
问题 I've had the need for a multi-threaded data structure that supports these claims: Allows multiple concurrent readers and writers Is sorted Is easy to reason about Fulfilling multiple readers and one writer is a lot easier, but I really would wan't to allow multiple writers. I've been doing research into this area, and I'm aware of ConcurrentSkipList (by Lea based on work by Fraser and Harris) as it's implemented in Java SE 6. I've also implemented my own version of a concurrent Skip List

How can I create an alphanumeric Regex for all languages?

左心房为你撑大大i 提交于 2019-12-22 03:40:09
问题 I had this problem today: This regex matches only English: [a-zA-Z0-9] . If I need support for any language in this world, what regex should I write? 回答1: If you use character class shorthands and a Unicode aware regex engine you can do that. The \w class matches "word characters" (letters, digits, and underscores). Beware of some regex flavors that don't do this so well: JavaScript uses ASCII for \d (digits) and \w , but Unicode for \s (whitespace). XML does it the other way around. 来源: