Logic for Nine to one equals 100 [closed] - java

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about programming within the scope defined in the help center.
Closed 7 years ago.
Improve this question
I was recently asked this question in an interview . Can anyone help me with a code to solve this problem?
We have a sequence of non-zero digits 123456789. The problem is to place plus or minus signs between them so that the result of thus described arithmetic operation will be 100. We can use a number only once . However we can use the operators(+,-,*,/) any number of times
Edit : I was asked to write a Java code for this question . So i believe its relevant
The followup question was to get all possible combinations

Example
Here is an example.
Split the numbers as follows
1 with multiply
4,7,89 with sum
3,6 with sum
4,5 with subtract
3+6 - 4 - 5 = 0
4 + 7 + 89 = 100
1 * 100 = 100
Automatic way of finding all possible combinations.
You essentially have 1 set:
the set {1..9} merged with the set {-,+,/,*,nothing} (nothing being the absence of a symbol)
You need to iterate over all the order possibilities. That will take for a long time. Exclude cases where there are 2 symbols side by side e.g. -/.
I believe this will lead to k-combinations.

Related

All combinations of two numbers [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 2 years ago.
Improve this question
An integer is a lucky number if each number in it is 3 or 7. To give an example, the numbers 7, 73, and 33777 are lucky numbers. Your task is to calculate the number of lucky numbers between int(a) and int(b).
How could one achieve this efficiently (in less than 1 sec) without going through all the numbers? I have attempted many solutions in Java however none of them are fast enough.
Since you have to count the numbers and not list the numbers, you can use permutation and combination to find the answer.
Eg let say find between 1 and 999 where you can use 3, 7
Then you have 3 lengths single, double and triple digits with constraints on single and triple digits.
For single since minimum number is 1 and 3, 7 both are greater there 2 numbers.
For double digits you have no constraints hence you have 2 * 2 = 4 combinations
Similarly for 3 digits as max number allowed is 9 in each place and 3,7 are lesser than them there will be 2 * 2 * 2 = 8
So answer is 14 after summing them all... This algorithm will run fast as it depends on the size of the numbers to generate ie o(n) time complexity where n is max length of number.

How to get highest possible number between 2 numbers under one condition - Java [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 3 years ago.
Improve this question
I am looking for an efficient/simplest way to find highest possible number between 2 numbers under 2 condition. The condition being that the numbers should be added or decremented as specified by a parameter and that every number after the preceding cannot be greater than adjacent numbers by more than one
Example
If given numbers 1 and 5 with a = 7, (1) -> 2 -> 3 -> 4 -> 5 -> 6 -> 7 -> 6 -> (5). Every number is not greater by its adjacent number by more than a factor of 1. Given the range 1 and 5 and with count = 7, the highest possible number should be 7. I apologize if the question isn't explained properly.
I am looking for something mathematically or in java

Coding java program to calculate check digit numbers [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
I have this java project(using eclipse) that calculates check digit numbers. I'm stuck on how to code this one.
The check has a check digit so that it makes the sum of the sights including the check digit divisible by 7. Assume there are always 4 digits plus the check digit. The sample is 3875 with the number being 5 Second trial problem is 5862 and check number needs to be found. How do I go about doing this? I got to entering each digit and adding them but how can i do the rest?
This is for an into to computer science class so please no super complex stuff as if we didn't learn it I cant use it.
My teacher sucks by the way we learn none of this. I already did part a I need part b. Thanks. Here's an image to hell clarify.
First of all, you need to develop some "programmer logic", these problems help to develop it.
Airline tickets divide the actual identification number by 7 and assign the remainder to the check digit. Number can be of any length
Example:
12358 #3
Let's break this example:
12358 / 7 = 1765
and the reminder is 3
Let's do the same with the 2nd number on the example:
45349 / 7 = 45346
and the reminder is 3
So, your logic is correct.
An American Express traveler's check has a digit so that it maskes the sum of the digits, including the check digit, evenly divisible by 7.
Example:
3875 #5
In this problem the thing is a little different, you need to sum the digits:
3875 -> 3 + 8 + 7 + 5 = 23
Now you need to get the reminder of 23 / 7
23 / 7 = 3
And a reminder of 2
7 - 2 = 5
That's your checkDigit
5862
5862 -> 5 + 8 + 6 + 2 = 21
21 / 7 = 3
Reminder = 0
checkDigit = 7 - 0 = 7
So the formula is:
Split the number into digits
Sum the digits
Get the mod 7 of the sum
Make a rest of 7 - reminder

How to make a dynamic array Fibonacci series java program? [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 6 years ago.
Improve this question
I am in 8th grade. I am taking a 12th grade java course. I just started and my home work is to make a Fibonacci series dynamic array program. I don't know where to go. It is online so I can't ask a teacher or something.
How do you make a Fibonacci sequence using a dynamic array in Java?
This was an example of a dynamic array I got:
I don't see how you can make the Fibonacci series out of it! Here is the Fibonacci series example I got.
You can combine the two examples, as such:
Take the DynamicArrayOfInt class, and add the main method of the Fibonacci class.
Insert a new statement at the beginning of the main method instantiating a DynamicArrayOfInt object, as such:
DynamicArrayOfInt arr = new DynamicArrayOfInt();
Replace every instance of numbers[x] with arr.get(x), and instances of numbers[x] = y with arr.put(x, y).
Remove the leftover statements dealing with the numbers array. This will essentially make use of the DynamicArrayOfInt object. A sample output would look like this:
iplante$ java DynamicArrayOfInt
Size of dynamic array increased to: 2
Fibonacci series:
0
1
Size of dynamic array increased to: 4
1
2
Size of dynamic array increased to: 8
3
5
8
13
Size of dynamic array increased to: 16
21
34
55
89
144
233
377
610
Size of dynamic array increased to: 32
987
1597
2584
4181
iplante$

Using a different number system on conventional programming languages [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about programming within the scope defined in the help center.
Closed 9 years ago.
Improve this question
Let's say I don't need with the mainstream number system that starts at zero and increases or decreases infinitely. What I need is a cyclic number system that starts at 0 and ends at 5, pretty much like the angular system of a circle. So, if I do additions, it goes something like this:
0+1=1
1+1=2
2+1=3
3+1=4
4+1=5
5+1=0
Now, our programming languages use the traditional number system. Is there any workaround that if I type 5+1, the programming language will give me 0 every time and not the 6 symbol? No matter, if that is a Python, C, D, or other programming solution.
You are looking for arithmetic modulo 6:
for i in range(6):
print('{}+1 = {}'.format(i, (i+1)%6))
yields
0+1 = 1
1+1 = 2
2+1 = 3
3+1 = 4
4+1 = 5
5+1 = 0

Categories