digit

Prolog converting integer to a list of digit

蓝咒 提交于 2019-12-14 01:37:14
问题 I want to write a predicate that an integer and a list of digits, and succeed if Digits contain the digits of the integer in the proper order, i.e: ?-digit_lists( Num, [1,2,3,4] ). [Num == 1234]. Here is what I have so far: my_digits( 0, [] ). my_digits(N,[A|As]) :- N1 is floor(N/10), A is N mod 10, my_digits(N1, As). 回答1: As already suggested, consider using finite domain constraints: :- use_module(library(clpfd)). number_digits(Number, 0, [Number]) :- Number in 0..9. number_digits(Number, N

How do I change the format/amount of digits that appear?

谁说我不能喝 提交于 2019-12-13 06:50:15
问题 I'm very new to Python and have a question. Currently I'm using this to calculate the times between a message goes out and the message comes in. The resulting starting time, time delta, and the Unique ID are then presented in file. As well, I'm using Python 2.7.2 Currently it is subtracting the two times and the result is 0.002677777777(the 0.00 are hours and minutes) which I don't need. How do I format it so that it would start with seconds (59.178533,00) with 59 being seconds. As well,

Get a number with exactly x digits from string

时光怂恿深爱的人放手 提交于 2019-12-13 06:21:05
问题 im looking for a regex pattern, which matches a number with a length of exactly x (say x is 2-4) and nothing else. Examples: "foo.bar 123 456789" , "foo.bar 456789 123" , " 123" , "foo.bar123 " has to match only "123" So. Only digits, no spaces, letters or other stuff. How do I have to do it? EDIT: I want to use the Regex.Matches() function in c# to extract this 2-4 digit number and use it in additional code. 回答1: Any pattern followed by a {m,n} allows the pattern to occur m to n times. So in

java Regex: replace all numerical values with one number

青春壹個敷衍的年華 提交于 2019-12-12 18:28:18
问题 I have a simple line of text which might include numbers like "12.3" or "1983" or "5/8". Whenever any number appears, I just need to replace with a fixed character, say the digit "8". I've been fiddling about with Regex in Java, with things like this: String line = str.replaceAll("[0-9]+/*.*[0-9]*", "8"); but to no avail. Any idea what the correct pattern should be? 回答1: Try this expression: (?>-?\d+(?:[\./]\d+)?) , keep in mind that in Java strings you need to escape the backslashes, i.e.

Python ISBN program

大兔子大兔子 提交于 2019-12-12 02:29:44
问题 I'm trying to calculate the check digit for an ISBN input on python. so far I have... def ISBN(): numlist = [] request = raw_input("Please enter the 10 digit number: ") if len(request) == 10: **numlist == request print numlist** if len(request) != 10: print "Invalid Input" ISBN() ISBN() The bold bit is where im having trouble, I cant seem to split the 10 digit input into individual numbers in the list (numlist) and then multiply the seperated individual numbers by 11 then the next by 10 then

ARABIC-INDIC DIGIT android

≯℡__Kan透↙ 提交于 2019-12-12 01:54:46
问题 I am trying to show in my Android application the ARABIC-INDIC DIGIT. So I tried this code, The method I used to display it is showed in the end of the class. public class num extends Activity{ @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.num); Typeface Bader = Typeface.createFromAsset(getAssets(),"fonts/bader_al yadawi.ttf"); final RelativeLayout rl = (RelativeLayout) findViewById(R.id.myLayout); Button back =

Regex for replacing the number by 2* the number -1. Used for replacing file names

[亡魂溺海] 提交于 2019-12-11 16:52:43
问题 I need the regular expression for multiplying the digits in the filename by 2 and subtracting 1. for eg: filename12.pdf should become filename23.pdf filename225.pdf should become filename449.pdf Please help me with the regular expression. 回答1: A regex generally cannot do calculations, but it can help you capture the number. You can use a callback of replace. Here's C#, for example: Helper method (we could have used a lambda, but it's less pretty): public string CalculateNumber(Match match) {

How can I keep 1 million digit in Java?

耗尽温柔 提交于 2019-12-11 11:07:48
问题 My question is that, I want to multiply 2 number which has 1 million digit. When I tried to assign 1 million number to BigInteger, Compiler is giving to me error. The error is that:"constant string too long". 回答1: BigInteger is indeed the way to store such large integers, although hundreds or a few thousands of digits are more typical use cases. However, Java class files have limitations that won't allow hard coding a literal number that large. Instead, store the number in a file and read it

find number in string, add 1 and replace

与世无争的帅哥 提交于 2019-12-11 04:15:02
问题 I need to write a code where a string contains a number, then this number is incremented by 1, and then printed out within the initial string input. It should work like this >>>addNumber('I slept 3 hours') what number would you like to increment? 3 I slept 4 hours >>>addNumber('I have 366 friends on facebook') what number would you like to increment? 6 I have 377 friends on facebook so far I have this, but I know it is wrong and honestly I don't know how to do this. def incrementNumbers

VBA. How to find position of first digit in string

Deadly 提交于 2019-12-09 05:18:42
问题 I have string "ololo123". I need get position of first digit - 1. How to set mask of search ? 回答1: Something like this should do the trick for you: Public Function GetPositionOfFirstNumericCharacter(ByVal s As String) As Integer For i = 1 To Len(s) Dim currentCharacter As String currentCharacter = Mid(s, i, 1) If IsNumeric(currentCharacter) = True Then GetPositionOfFirstNumericCharacter = i Exit Function End If Next i End Function You can then call it like this: Dim iPosition as Integer