What programming language you start with really all depends on where you want to go with programming/coding. The great thing about this field is that there are an absolute abundance of smaller fields that you can go into, all using programming in their own unique ways. For web applications, a good start would be with HTML and later moving your way through CSS, JavaScript, JQuery, PHP, SQL, and any of the JavaScript libraries. Ruby is also a popular choice, so I would recommend checking that out too. For more scientific fields or areas with more machine learning and A.I., Python is generally a great place to start as it is widely used in that field of study. C++ is also a very useful language to know for that, but it can be a little more challenging for beginners. For game and application design, languages such as C#, C, Swift, Kotlin, and Java are most often used for that.
Challenge
Given a number A, find the smallest possible value of B+C, if B*C = A. Here A, B, and C must all be positive integers. It's okay to use brute force by checking every possible value of B and C. You don't need to handle inputs larger than six digits. Post the return value for A = 345678 along with your solution.
For instance, given A = 12345 you should return 838. Here's why. There are four different ways to represent 12345 as the product of two positive integers:
12345 = 1*12345
12345 = 3*4115
12345 = 5*2469
12345 = 15*823
The sum of the two factors in each case is:
1*12345 => 1+12345 = 12346
3*4115 => 3+4155 = 4158
5*2469 => 5+2469 = 2474
15*823 => 15+823 = 838
The smallest sum of a pair of factors in this case is 838.
Examples
12 => 7
456 => 43
4567 => 4568
12345 => 838
The corresponding products are 12 = 3*4, 456 = 19*24, 4567 = 1*4567, and 12345 = 15*823.
Hint
Want to test whether one number divides evenly into another? This is most commonly done with the modulus operator (usually %), which gives you the remainder when you divide one number by another. If the modulus is 0, then there's no remainder and the numbers divide evenly. For instance, 12345 % 5 is 0, because 5 divides evenly into 12345.
Solution
in Python
num = input("Enter a number: ")
start = int(num ** 0.5)
while (num % start != 0):
start -= 1
print(start + num / start)
Given a number A, find the smallest possible value of B+C, if B*C = A. Here A, B, and C must all be positive integers. It's okay to use brute force by checking every possible value of B and C. You don't need to handle inputs larger than six digits. Post the return value for A = 345678 along with your solution.
For instance, given A = 12345 you should return 838. Here's why. There are four different ways to represent 12345 as the product of two positive integers:
12345 = 1*12345
12345 = 3*4115
12345 = 5*2469
12345 = 15*823
The sum of the two factors in each case is:
1*12345 => 1+12345 = 12346
3*4115 => 3+4155 = 4158
5*2469 => 5+2469 = 2474
15*823 => 15+823 = 838
The smallest sum of a pair of factors in this case is 838.
Examples
12 => 7
456 => 43
4567 => 4568
12345 => 838
The corresponding products are 12 = 3*4, 456 = 19*24, 4567 = 1*4567, and 12345 = 15*823.
Hint
Want to test whether one number divides evenly into another? This is most commonly done with the modulus operator (usually %), which gives you the remainder when you divide one number by another. If the modulus is 0, then there's no remainder and the numbers divide evenly. For instance, 12345 % 5 is 0, because 5 divides evenly into 12345.
Solution
in Python
num = input("Enter a number: ")
start = int(num ** 0.5)
while (num % start != 0):
start -= 1
print(start + num / start)
?3491...now I have to code it....
ReplyDelete