0

I have a question that was asked of me:

Form a given number using only 4s(using the least number of 4s) using only the following operations:

  1. Addition
  2. Subtraction
  3. Multiplication
  4. Division
  5. Power(^)
  6. Square root
  7. Factorial
  8. Greatest integer function

For example, 3 = 4-(4/4)

I'm a complete newbie to python. How do I approach this problem?

Community
  • 1
  • 1
  • please format your question correctly and also please show us what you have tried so far? – Kuldeep Singh Sidhu Jun 06 '20 at 03:18
  • @KuldeepSinghSidhu: From the question: "How do I approach this problem?". In other words, OP doesn't even know where to start, so what they have tried is probably irrelevant. Additionally, you do *see* the "new contributor tag, yes? People asking questions here for the first time should be given a fair bit of slack, and those who have been here a while can help out with formatting, like this ... – paxdiablo Jun 06 '20 at 03:24
  • The example is invalid: it contains a 2. Is there an exception for exponents? – Dennis Sparrow Jun 06 '20 at 03:36
  • @DennisSparrow: I corrected it – Akshay Alva Jun 06 '20 at 05:07
  • @kuldeeepsinghsidhu:No progress at all.I don't how to format properly. I'm new. – Akshay Alva Jun 06 '20 at 05:08
  • https://www.tutorialspoint.com/python/python_basic_operators.htm – Joe Jun 06 '20 at 05:32
  • A [solution to a similar but not identical problem](https://www.geeksforgeeks.org/smallest-expression-represent-number-using-single-digit/) may help. Discussions of similar problems on Stack Overflow generally don't improve on a brute force search, that is generating all possible expressions with increasing numbers of 4s until one of them generates the target. [Example](https://stackoverflow.com/questions/29353375/how-to-brute-force-arithmetic-puzzle?noredirect=1&lq=1) – Dennis Sparrow Jun 06 '20 at 06:00

1 Answers1

0

You have to use math library. Code:

from math import *
x =  4**2- sqrt(4)
print(x)

Output:

14.0

Note: Power in python is **

Osadhi Virochana
  • 1,294
  • 2
  • 11
  • 21