Advertisement
Guest User

Untitled

a guest
Jul 22nd, 2017
44
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.06 KB | None | 0 0
  1. const as integer NUMOPS = 4
  2. const as integer N = 4
  3.  
  4. dim as zstring ptr optab(0 to NUMOPS - 1) = {@"+", @"-", @"*", @"/"}
  5. dim as integer dat(0 to N - 1) = {1, 2, 3, 4}
  6.  
  7. dim as integer cnt = (N ^ N) * (NUMOPS ^ (N - 1))
  8. dim as integer l = (N * 2) - 1
  9.  
  10. dim as integer values(0 to l - 1)
  11.  
  12. print "cnt: " & cnt
  13. print "l : " & l
  14.  
  15. for i as integer = 0 to cnt - 1
  16. dim as integer temp = i
  17. dim as string expr
  18. dim as integer bad_flag
  19. for j as integer = 0 to l - 1
  20. if (j and 1) = 0 then
  21. ' must be a number
  22. values(j) = temp mod N
  23. temp \= N
  24. expr &= dat(values(j))
  25. else
  26. ' must be an operator
  27. values(j) = temp mod NUMOPS
  28. temp \= NUMOPS
  29. expr &= *optab(values(j))
  30. end if
  31. ' If we are not at the first number, and we are at a number,
  32. ' look back and make sure this number hasn't appeared before.
  33. if j and ((j and 1) = 0) then
  34. for k as integer = j - 2 to 0 step - 2
  35. if values(j) = values(k) then
  36. bad_flag = 1
  37. exit for
  38. end if
  39. next k
  40. end if
  41. next j
  42. if bad_flag = 0 then
  43. print expr
  44. end if
  45. next i
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement