Questions tagged [integer]

1

votes
1

answer
29

Views

The best way to use Infinity in java to avoid double type? [duplicate]

This question already has an answer here: How to implement infinity in Java? 9 answers If I want to have a target Integer number that I want to initialized as infinity, Am I forced to use the Double type to begin with? Integer min_val(List nums) { double min_so_far = Double.POSITIVE_INFINITY; for (...
1

votes
1

answer
25

Views

PostgreSQL: When casting an integer to a non-integer type to force floating point division in PostgreSQL, which number type should I use?

I know there are many integer division questions on StackOverflow, but I did not see this one. Similar to many programming languages, PostgreSQL performs integer division if both operands are integers. If one has: SELECT s.id AS student_id, COUNT(DISTINCT(bc.book_id)) / COUNT(c.id) AS average_books_...
Peter Jirak
1

votes
1

answer
26

Views

How to convert specific byte in a byte array to integer

I have a scenario where in based on a given String I need to return an integer value. I am hashing String to a byte array . Now since my Integer range is 0-999 which can be represented by 2bytes, I am hoping to use last two bytes of the byte array to convert to integer . But I am not getting the co...
varkashy
1

votes
4

answer
14.8k

Views

how to put a string into an integer array c++

I have a string that contains what ever the user has input string userstr = ''; cout
user3080755
1

votes
1

answer
3.1k

Views

Declaring variables in NASM

I am just learning NASM and I am kind of struggling to figure this out. How do you declare variables in NASM? For example, how would you declare unsigned int i in NASM? Thanks
Kenneth
0

votes
1

answer
39

Views

Processing of integers on different CPUs

My task is to design a function that fulfils those requirements: Function shall sum members of given one-dimensional array. However, it should sum only members whose number of ones in the binary representation is higher than defined threshold (e.g. if the threshold is 4, number 255 will be counted...
user46581
1

votes
1

answer
90

Views

Converting 32-bit integer value to unsigned 16-bit integer

What does the C standard say about: uint32_t a = 0x11223344; uint16_t b = a; When printed, I am getting 0x3344, which makes sense; so this must be legal and correct behaviour?
Mark
1

votes
1

answer
111

Views

Is a java long enough to store epoch time in microseconds?

Can I use a java long to store with reasonable precision the epoch time in microseconds with out any special signed to unsigned conversion tricks? If so how would I calculate the end date range? This is the usual 8 byte date range: -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807 UPDATE From...
simgineer
1

votes
3

answer
114

Views

Is there a way to optimize this function?

For an application I'm working on, I need to take two integers and add them together using a particular mathematical formula. This ends up looking like this: int16_t add_special(int16_t a, int16_t b) { float limit = std::numeric_limits::max();//32767 as a floating point value float a_fl = a, b_fl =...
Xirema
1

votes
1

answer
46

Views

Matlab: random integers from a range with no repetition

I want to get an array with randomized integer included in range with no repeat, I used : randperm(15,3) output is : 8, 10, 12 This function not use a range, I would like to random values only from 10 e.g. Thank you !
KiMaN
5

votes
1

answer
204

Views

Determine allocation of staff - Python

I am trying to create an optimal shift schedule where employees are assigned to shifts. An output which meets the minimum staffing requirements, while spending the least amount of money. The tricky part is I need to account for specific constraints. These being: 1) At any given time period, you must...
jonboy
1

votes
1

answer
90

Views

Getting C# Int64 in Python

I have to get an Int64 object in Python. My code looks like this: from System import Int64 l = Int64.Parse('123') print(l, type(l)) but it returns: 123 When I did the same with DateTime c# object, it returned just right type: So why does Python convert an Int64 C# object back to it's own int clas...
Josef Kvita
1

votes
1

answer
63

Views

Getting from datatype string hexadecimal to INTEGER hexadecimal type in Python

I'm having an issue getting from hexadecimal string to hexadecimal integer in Python 3. When you write hex(12) you get the output 0xc which is a str class. However, when you type fx. int = 0x55 the class/type is an INTEGER. How do you go from '0x55' to 0x55 (as an integer) Thank you :)
Dapper
1

votes
1

answer
851

Views

Linear optimization with PuLP, additional condition on variables

I have to solve an integer linear optimization problem in Python with pulp. I solved the basic problem and now I have to add additional constraints. Is anybody who can help me with adding the condition with a logical indicator? The logical restriction is: B>5 if A>20 Here is my code: from pulp impo...
patii
1

votes
1

answer
19

Views

trasformation index array in value

example value return: array[1]=1 array[5]=5 array[12]=[1, 2] array[85]=[8, 5] array[7453]=[7, 4, 5, 3] array[8987556322415]=[8, 9, 8, 7, 5, 5, 6, 3, 2, 2, 4, 1, 5] Which is the best way to convert the index to an array with single decimal value (only one number for every index) var array=[30]; func...
ROth
1

votes
0

answer
22

Views

Non Repeating Random Integer values within range of previous guessed values

I am creating random number game for my class where the computer guesses random values within the range set by the user. I am trying to get it to the point where if the user input Higher or Lower, the new values will not disobey the previous values. For example, if the range is between 2-50 and the...
Blink
1

votes
0

answer
147

Views

How to solve a non-square linear system with integer solutions in R

Is there any way to solve a non-square linear system with integer solution in R? I want the elements of the vector-solution to be equal to 0 or positive. For example, I want to solve Ax=B with x∈c(0,1,2,3): A=matrix(c(1,-2,3,6,1,2,5,1,1,4,4,2),3,4,T) B=matrix(c(4,3,6),3,1,T) A [,1] [,2] [,3] [,4]...
Vassilis Chasiotis
1

votes
1

answer
31

Views

as.integer makes characters NA

I have some sequencing data for some biological samples. The file to read contains 7 columns first that contain characters, as they have gene names and codes etc. From the 8th column are my samples that contain count data, so a number assigned to a gene depending of how much of that gene is present...
user9317212
1

votes
0

answer
17

Views

How can keep these values in my list, they only execute when they're listed as strings, but then they have no value?

Cant return my 'suits' list in the random unless it is strings but i want to keep the values! Anything missing or any way I can force them later in my black jack game? import random import itertools Ace = 11 Jack = 10 Queen = 10 #trying to create an acurate point system held in these #variables...
Bruce Pouncey
1

votes
1

answer
884

Views

cvxopt.glpk.ilp documentation on Integer & Binary set keys

I have a mixed integer programming problem, (cutting stock with column generation), that I've solved in AMPL and I'm ported to Python using cvxopt. CVXOPT 'op' doesn't provide the binary variable option that I need, so I'm extending it with GLPK to use 'ILP'. I'm getting the ilp status = 'LP relax...
PointOnePA
1

votes
0

answer
46

Views

Find how many times an integer is in an array with varying integers [duplicate]

This question already has an answer here: Java count occurrence of each item in an array 16 answers find the frequency of elements in a java array 8 answers Frequency of elements in an array [duplicate] 4 answers Find the element with highest occurrences in an array [java] 8 answers I am trying...
Caleb
1

votes
3

answer
35

Views

Transforming month names to numbers

I have a userform that askes to which month the data input is applicable. I have used a combibox with jan, feb, mar etc as possible answers. Now I want to use these answers to refer to a sheet index number Jan is sheets(2), feb = sheets(3) etc. How do I do this? Private Sub Userform_Initialize() 'Em...
Boolean
1

votes
0

answer
78

Views

GAMS : Avoid Scan of obviously wrong solutions in CPLEX

I have the following problem in GAMS I implemented a location routing problem. While checking the .log file I noticed something that could speed up the calculation time immensly if I fixed it. Let me state an example first: Let's assume that we have a set S of all nodes consisting of s1*s140 nodes w...
Adam92
1

votes
1

answer
125

Views

How to implement uint32 addition and subtraction operations in Ruby?

Please do not suggest using any gems or creating classes for unsigned integers. Input data - strings that represent 4 byte sequence. Output data should be the same type of string. This is what I've got so far: def addition(augend, addend) sum = augend.to_i(16)+addend.to_i(16) sum -= 2**32 if sum >=...
MOPO3OB
1

votes
0

answer
128

Views

How to get intermediate Integer solutions when solving a MIP in Julia (JuMP)?

I am solving a MIP model using CPLEX in Julia. I know CPLEX has a so-called Solution Pool where all the intermediate integer solutions during the solving process are stored. Is there a way of accessing those solutions using Julia (JuMP)?
Berni
1

votes
1

answer
63

Views

Is an integer variable not numeric in Ruby?

I have user_waiting period saved as an integer in my DB. I am trying to use it in the below code, but I keep getting the error 'Expected Numeric.' I am very new to Ruby, and my understanding was that an integer would be numeric. Am I incorrect in this understanding? if @pto_management.waiting_period...
triepe
1

votes
1

answer
9

Views

Why isnt my module always printing the lowest of 3 single inputs?

I am trying to get it to print the lowest of the 3 inputs but it is sometimes printing the second lowest. a = (input()) b = (input()) c = (input()) if int(c) < int(b) and int(a): print (c) elif int(b) < int(c) and int(a): print(b) elif int(a) < int(b) and int(c): print (a)
ClintFromNYtoVA
1

votes
0

answer
31

Views

Pandas - dtype shows int, but describe shows float

I have changed my variable age to an integer since it was stored as a float: sessions['age'] = sessions['age'].astype(int) Pandas dtypes returns an int: In: sessions['age'].dtype Out: dtype('int64') However, describe() shows a float: In: sessions['age'].describe() Out: Name: age, dtype: float64 Tryi...
Lisadk
3

votes
1

answer
89

Views

X86 IDIV sign of remainder depends on sign of dividend for 8/-3 and -8/3?

Can anyone explain for me why the sign of the remainder is different in these cases? Is this an emulator bug or do real CPUs do this, too? 8 / -3 : quotient(AL) = -2 remainder(AH) = 2 -8 / 3 : quotient(AL) = -2 remainder(AH) = -2
user3018354
1

votes
1

answer
114

Views

Why is conversion not working?

I'd like to develop an algorithm that is able to do a AnyBase 2 AnyBase conversion in C++. So I started with just translating this javascript code into C++ and ended with the use of a BigInt - library because it will of course not work using integer (long int, long double, etc) precision - so I had...
1

votes
3

answer
91

Views

How to determine if an inputted integer contains certain digits without using strings

In this program I am supposed to figure out if the integer that the user enters contains a certain digit (in this case 7 and 3), and then return a boolean. So far I have: public static boolean contains(int num, int x) { Scanner input = new Scanner(System.in); int currentLength = numberDigits(num);...
UnknownJ25
1

votes
3

answer
43

Views

Print minimum integer of list's elements based on indices from other list

I have two lists a and b(both have same length) where the list b has only 1, 2 and 3 as its elements(random repetition allowed).Now , for all the indices of 1 in list 'b' I want to print a min integer from list a.And same for 2 and 3 in list 'b'. For example: a = [10,33,42,17,9,32,33,43,12,2,5,22] b...
gunjanpatait
1

votes
1

answer
30

Views

permutation for string doesnt work for array of ints

So I have the working string perm code below public static List myperm( String s ){ List l = new ArrayList(); mypermImpl('', s, l ); return l; } public static void mypermImpl( String built, String other, List l ){ if (other.length() == 0 ){ l.add( built ); } for ( int i=0; i
Joe Bloom
1

votes
0

answer
38

Views

Why does adding the integer 1 to another integer, then cast to a float give me .99?

I am in a visual programming class, trying to make a GUI in Processing that will eventually control an Arduino MeArm. I have a controlP5 element for each of the 4 servos, whose values are stored as int variables. For example, my variable for the elbow would be: eVal = (int)elbow.getValue(); I have s...
Janaga
1

votes
0

answer
62

Views

Avoiding integers multiplication overflow for 3+ integers

I'm testing my C++11 code with static analysis tool (CodeSonar). Here's my code: int weights_size = c * n * size * size; int weights_memory_size = weights_size * sizeof(float); if (IS_OVERFLOW_6(weights_memory_size, c, n, size, size, (int)sizeof(float))) { overflow_error(); } l.weights = (float*) ca...
frozenca
1

votes
2

answer
45

Views

How to group subarrays and perform conditional calculations?

I need to group my subarray using product_id and perform some conditional arithmetic. If moving_type is 1 then the overall product_number tally for the current product_id should be increased by the product_number. Alternatively, if the moving_type is 2 then the overall product_number tally should b...
Arka
1

votes
2

answer
103

Views

Calculate logarithm by hand

I'd like to calculate the mathematical logarithm 'by hand'... ... where stands for the logarithmBase and stands for the value. Some examples (See Log calculator): The base 2 logarithm of 10 is 3.3219280949 The base 5 logarithm of 15 is 1.6826061945 ... Hoever - I do not want to use a already imple...
jonas00
1

votes
2

answer
36

Views

'Split' integers in Terminal

In Ruby, I'm trying to solve a quiz as like a FizzBuzz Challenge. My question is 'How I can print the integer number |n| adding a comma and space(', ')at the end of they?' To separate the Namaand Team strings I'm using $stdout.print 'Team, ' && $stdout.print 'Nama, '. But for the integers my syntax...
gbs0
2

votes
1

answer
28

Views

How to convert an “unsigned” long to BigInteger

If we have a Java long value - say x - which should be interpreted as an unsigned value (i.e. 0x8000_0000_0000_0000 and higher should be interpreted as positive value) then how can I convert it to BigInteger? Obviously, BigInteger.valueOf(x) would result in a negative value, and conversion to hexade...
Maarten Bodewes
1

votes
0

answer
54

Views

How to add minimum up time constraint for a home load into a Mixed Integer Linear Programming in matlab?

I have written the code for the operation of the appliances for a minimum up time in a MILP problem in MATLAB. The code I have written is based on the lines of the 'optimal operation of thermal plants' tutorial video for MILP problem.Following is the link to it - https://in.mathworks.com/videos/mixe...
Paramvir Atwal

View additional questions