Mathematics Stack Exchange is a question and answer site for people studying math at any level and professionals in related fields. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Here is a small mathematical challenge.

You have to use once and only once each of the four numbers $1,5,6,7$ in order to obtain, via the help of the usual operators ($+,-,/,*$ together with parenthesis) in order to obtain the number $21$.

Example of an unsuccessful computation: $6*5-7-1=22\neq 21$

share|cite|improve this question
$6 / (1 - 5/7)$ ${}$ – Cocopuffs Jun 12 '13 at 19:33
@Cocopuffs Arghh you beat me! – Kaish Jun 12 '13 at 19:35
Hint : Give this problem to a (non-)mathematician friend and bet that he can't solve it in 1 hour without googling it. You may often win... – user81566 Jun 12 '13 at 20:43

See Generate a number by using a given list of numbers and arithmetic operators

This is an adjusted part of the answer from Ray

#!/usr/bin/env python
# -*- coding: utf-8 -*-
from fractions import Fraction


P = {'+':lambda x,y:x+y,
     '-':lambda x,y:x-y,
     '*':lambda x,y:x*y,
     '/':lambda x,y:x/y}

def postfix_search(rest, stk):
    if len(stk) >= 2:
        y = (v2, r2) = stk.pop()
        x = (v1, r1) = stk.pop()
        for opr in O:
            if O[opr] > 0 and not (opr == '/' and v2 == 0):
                stk += [(P[opr](v1, v2), '('+r1+opr+r2+')')]
                O[opr] -= 1
                if postfix_search(rest, stk): return 1
                O[opr] += 1
        stk += [x, y]
    elif not rest:
        v, r = stk[0]
        if v == N: print(r)
        return v == N
    for x in list(rest):
        stk += [x]
        if postfix_search(rest, stk):
            return True
        rest += [x]

if __name__ == "__main__":
    postfix_search(list(zip(L, map(str, L))), [])


$ ./

My ideas with arbitrary functions

$\varphi$ is Eulers totient function

  • $\varphi(5 \cdot 6-7)-1 = \varphi(23)-1 = 22-1 = 21$
  • $\varphi((1+7) \cdot 6)+5= \varphi(48)+5=16+5=21$
share|cite|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.