Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save rajendraprasad9/5b89126d961411293c347e5d26cf4c0b to your computer and use it in GitHub Desktop.

Select an option

Save rajendraprasad9/5b89126d961411293c347e5d26cf4c0b to your computer and use it in GitHub Desktop.

Revisions

  1. @WhiteBlue WhiteBlue renamed this gist May 12, 2018. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  2. @WhiteBlue WhiteBlue created this gist May 12, 2018.
    41 changes: 41 additions & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,41 @@
    # coding=utf-8
    import copy

    op_method = ['+', '-', '*', '/']


    def copy_arr(old, e):
    new_buf = copy.copy(old)
    new_buf.append(e)
    return new_buf


    def check_val(buf):
    code_val = ''
    for i in buf:
    code_val += str(i)

    if eval(code_val) == 24:
    print code_val


    def get_num(buf):
    if len(buf) < 7:
    if len(buf) != 0 and (len(buf) - 1) % 2 == 0:
    for i in op_method:
    get_num(copy_arr(buf, i))
    else:
    for i in range(0, 9):
    if i in buf:
    continue
    if len(buf) != 0 and buf[len(buf) - 1] is '/':
    before_val = buf[len(buf) - 2]
    if i == 0 or before_val % i != 0:
    continue
    get_num(copy_arr(buf, i))
    else:
    check_val(buf)


    if __name__ == '__main__':
    get_num([])