Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const as integer NUMOPS = 4
- const as integer N = 4
- dim as zstring ptr optab(0 to NUMOPS - 1) = {@"+", @"-", @"*", @"/"}
- dim as integer dat(0 to N - 1) = {1, 2, 3, 4}
- dim as integer cnt = (N ^ N) * (NUMOPS ^ (N - 1))
- dim as integer l = (N * 2) - 1
- dim as integer values(0 to l - 1)
- print "cnt: " & cnt
- print "l : " & l
- for i as integer = 0 to cnt - 1
- dim as integer temp = i
- dim as string expr
- dim as integer bad_flag
- for j as integer = 0 to l - 1
- if (j and 1) = 0 then
- ' must be a number
- values(j) = temp mod N
- temp \= N
- expr &= dat(values(j))
- else
- ' must be an operator
- values(j) = temp mod NUMOPS
- temp \= NUMOPS
- expr &= *optab(values(j))
- end if
- ' If we are not at the first number, and we are at a number,
- ' look back and make sure this number hasn't appeared before.
- if j and ((j and 1) = 0) then
- for k as integer = j - 2 to 0 step - 2
- if values(j) = values(k) then
- bad_flag = 1
- exit for
- end if
- next k
- end if
- next j
- if bad_flag = 0 then
- print expr
- end if
- next i
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement