numbers

How to do an inverse `range`, i.e. create a compact range based on a set of numbers?

时光怂恿深爱的人放手 提交于 2019-12-03 13:29:01
问题 Python has a range method, which allows for stuff like: >>> range(1, 6) [1, 2, 3, 4, 5] What I’m looking for is kind of the opposite: take a list of numbers, and return the start and end. >>> magic([1, 2, 3, 4, 5]) [1, 5] # note: 5, not 6; this differs from `range()` This is easy enough to do for the above example, but is it possible to allow for gaps or multiple ranges as well, returning the range in a PCRE-like string format? Something like this: >>> magic([1, 2, 4, 5]) ['1-2', '4-5'] >>>

Why does the range of int has a minus 1?

此生再无相见时 提交于 2019-12-03 13:25:52
I read that the range of an int is dependent on a byte. So taking int to be 4 bytes long, thats 4 * 8 bits = 32 bits. So the range should be : 2 ^ (32-1) = 2 ^ (31) Why do some people say its 2^31 - 1 though? Thanks! Because the counting starts from 0 And the range of int is 2,147,483,647 and 2^32 which is 2,147,483,648 . hence we subtract 1 Also the loss of 1 bit is for the positive and negative sign Check this interestinf wiki article on Integers:- The most common representation of a positive integer is a string of bits, using the binary numeral system. The order of the memory bytes storing

gnuplot matrix or plot : display both color and point value

谁都会走 提交于 2019-12-03 13:19:01
I'm using gnuplot to analysis data. And I frequently use palette and matrix. However whenever I use that, precision is always problem. If I increase precision by define many color, it is difficult to remember and to read. If I decrease number of color to clear comparison, precision become decrease. So I'm thinking matrix with plot number. If I can display both color and number, it will be more easy to see and analysis. At least I want display only number,(Just use excel is a one choice but I don't want to) or display number with different color.(color determined by point value) If you know the

How to generate unique order number?

时光总嘲笑我的痴心妄想 提交于 2019-12-03 12:49:32
问题 I'm looking for a good way to generate a unique order ID. Can you see any problems with the code below? int customerId = 10000000; long ticks = DateTime.UtcNow.Ticks; long orderId = customerId + ticks; int orderNumber = orderId.GetHashCode(); I'm going to check that the number is unique in the database before creating the order. 回答1: If you are storing your records in a database, you should really look into the capabilities available there to generate unique surrogate keys. In SQLServer this

Oracle NUMBER(p) storage size?

佐手、 提交于 2019-12-03 12:08:06
问题 I've searched for it but i can't find a conclusive answer to my question... I need to know what is the storage size of a number(p) field in Oracle. Examples: NUMBER(1), NUMBER(3), NUMBER(8), NUMBER(10) etc... 回答1: The storage used depends on the actual numeric value, as well as the column precision and scale of the column. The Oracle 11gR2 concepts guide says: Oracle Database stores numeric data in variable-length format. Each value is stored in scientific notation, with 1 byte used to store

SQLite function to format numbers with leading zeroes?

穿精又带淫゛_ 提交于 2019-12-03 10:47:56
问题 I’ve got an SQLite database that will need to contain products. Those products have a fixed-format composite product number, consisting of category, group and product number (cccccc.gg.ppp). Every time a new product is inserted, the new product number should be built using the category and group numbers, followed by the highest product number in that group incremented with one. To that end, I was thinking of storing all three numbers in separate fields, and use a view to dynamically assemble

Convert string to decimal number in ruby

旧城冷巷雨未停 提交于 2019-12-03 10:24:39
问题 I need to work with decimals. In my program, the user need to put a number with decimals to convert that number. The problem is: If I try to convert the argument into a number I get a integer without decimals. # ARGV[0] is: 44.33 size = ARGV[0] puts size.to_i # size is: 44 # :( 回答1: You call to_i , you get integer. Try calling to_f , you should get a float. For more string conversion methods, look here. 回答2: If you want more accurate answer with the calculation to avoid bug like this https:/

Objective-C: Numbers only text field? [duplicate]

醉酒当歌 提交于 2019-12-03 09:55:51
Possible Duplicate: Iphone UITextField only integer I want to place a text field that only accepts numbers (0-9, doesn't even need decimals), but even using the "Number Pad" entry option I still get a keyboard with various symbols on it. Is there a better control for this, is there a better control for what I'm doing, or do I just have to validate input manually? The following code will allow you to only input numbers as well as limit the amount of characters that can be used. -(BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *

iOS Core Data: Convert result of fetch request to an array

匿名 (未验证) 提交于 2019-12-03 09:52:54
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: I'm trying to put the results of a fetch request into an array. My code: let appDelegate = UIApplication . sharedApplication (). delegate as ! AppDelegate let managedContext = appDelegate . managedObjectContext let fetchRequest = NSFetchRequest ( entityName : "CLIENTS" ) var mobClients = [ NSManagedObject ]() var arrayAllPhoneNumbers = [ String ]() do { let results = try managedContext . executeFetchRequest ( fetchRequest ) mobClients = results as ! [ NSManagedObject ] for clientPhoneNumber in mobClients { let myClientPhoneNumber =

Java Histogram using asterisks

匿名 (未验证) 提交于 2019-12-03 09:52:54
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I am trying to create a histogram class that utilizes an application to run the program. public class Histogram { String name; int max; public Histogram (String name, int max) { this.name = name; this.max = max; } int[] count = new int[max+1]; public void add(int numbers) { // Handles out of bounds case if (numbers < 0 || numbers > max) return; count[numbers]++; } public String toString() { String result = name + "\n"; for (int index = 0; index < count.length; index++) { result = result + count[index] + ": "; for (int indexStar = 0;