Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8476921
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T18:18:43+00:00 2026-06-10T18:18:43+00:00

I have a Lua function that, given n, generates all permutations of the series

  • 0

I have a Lua function that, given n, generates all permutations of the series from 1 to n and stores each unique series in table form within a container table.

The size of this generated table gets very large very quickly (and necessarily so). About the time I try n = 11, the script will run for several seconds before failing out to “lua: not enough memory.” I have 16gb of physical RAM, but watching the performance monitor in the Windows task manager allows me to watch the ram be consumed during run time, and it only gets up to about 20% before the script ends with the memory error.

I found this post that looks like the direction I need to head: memory of a process in Lua

Since I’m running my script with Lua.exe, I’m assuming that I’m limited to how much memory Windows allocates for Lua.exe. Can I increase this amount? Can I use a C# wrapper program to simply run the Lua script (the idea being that it will have a higher/less restricted memory allocation)? Or am I looking in the wrong direction?


  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T18:18:45+00:00Added an answer on June 10, 2026 at 6:18 pm

    Do you need to store all the permutations in advance? You could generate them on-the-fly instead.

    Example:

    local function genPerm(self, i)
      local result = {}
      local f = 1
      for j = 1, self.n do
        f = f * j
        table.insert(result, j)
      end
      for j = 1, self.n-1 do
        f = f / (self.n + 1 - j)
        local k = math.floor((i - 1) / f)
        table.insert(result, j, table.remove(result, j+k))
        i = i - k * f
      end
      return result
    end
    
    local function perms(n)
      return setmetatable({n=n}, {__index=genPerm})
    end
    
    local generator = perms(11)
    for _, i in ipairs {1, 42, 1000000, 39916800} do
      print(table.concat(generator[i], ','))
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a program that embeds Lua and implements a form of lazy function
I have a Lua program that is consuming data from an external device. The
I have a Lua table and an index function like this: curIndex = 0
I have a lua table that I use as a hashmap, ie with string
I have strange problem, with calling Lua function from C++. I have in Lua:
I have Lua table, t , which I iterate: for k, v in pairs(t)
I have a function that takes a variable number of arguments in C that
I have a c++ application that interfaces with lua files. I have a lua
I have a generic function for pushing stuff on to the lua stack called
I use a cluster of about 30 machines that have all recently been reconfigured

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.