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

  • SEARCH
  • Home
  • 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 6860135
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T02:22:14+00:00 2026-05-27T02:22:14+00:00

Essentially what I’m doing is trying to solve a Rubik’s cube with a breadth

  • 0

Essentially what I’m doing is trying to solve a Rubik’s cube with a breadth first search of all possible moves. I know this isn’t the best way to solve the cube, but I only need it for very short sequences (so the depth of the search is unlikely to be deeper than 3), and I don’t need to store anything other than the current sequence.

I’m trying to find a way of printing out ever increasing strings of number (0,1,2,00,01,02…), so I can just plug each one into a function to check if that particular sequence of moves solves the cube, but I’m having trouble finding a way of continuing the sequence indefinitely.

So far all I’ve managed is nested for loops, but there needs to be another loop each time the search gets deeper. Does anyone have any idea how I can approach this problem?

Sorry if I’ve been too vague, I could write an essay on what I’m trying to do but thought I’d try and keep it simple.

  • 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-05-27T02:22:15+00:00Added an answer on May 27, 2026 at 2:22 am

    I’m not very familiar with what’s in the Java libraries, so apologies if this is implementing something that is already there, but if I were writing this from scratch, I’d probably do something like this:

    public class Enumerator {
        private int maxDepth;
        private int currentDepth;
        private int currentPerm;
        private String alphabet;
    
        public Enumerator(String alphabet, int d) {
            this.maxDepth = d;
            this.currentDepth = 1;
            this.currentPerm = 0;
            this.alphabet = alphabet;
        }
    
        public boolean next() {
            int numPermutations = (int) Math.pow(alphabet.length(), this.currentDepth);
            boolean res=false;
    
            // finished if
            if ((this.currentDepth == this.maxDepth) && 
                (this.currentPerm == numPermutations - 1)) {
                res = false;
            }
            // next perm at this depth
            else if (this.currentPerm < numPermutations - 1) {
                this.currentPerm++;
                res = true;
            }
            // next depth
            else if (this.currentDepth <= this.maxDepth) {
                this.currentDepth++;
                this.currentPerm = 0;
                res = true;
            }
            return res;
        }
    
        public String getPermutation() {
            int tmpPerm = this.currentPerm;
            String res = "";
            for (int i=0; i<this.currentDepth; i++) {
              int ind = tmpPerm % this.alphabet.length();
              res = this.alphabet.charAt(ind) + res;
              tmpPerm /= this.alphabet.length();
            }
            return res;
        }
    
        public static void main(String args[]) {
            int depth = 3;
            String alphabet = "012";
            Enumerator e = new Enumerator(alphabet, depth); 
            do {
                System.out.println(e.getPermutation());
            } while (e.next());
        }
    }
    

    That way you can enumerate sequences from alphabets of arbitrary symbols to an arbitrary depth. This also does what you want insofar as it iterates over depth and for each depth generates the full set of possible sequences. It could also be done with recursion, as Gian says, which might be more elegant. In Python I’d use a generator function for this, but I’m not familiar with anything similar in Java.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Essentially the title of this question explains the essense of what I am trying
Essentially what I'm trying to do at this point is build a program to
Essentially I want to know if in VB.NET 2005 if using a sqlcommand and
Essentially I'd like to know just how compatible are the iPhone and the iPod
Essentially, what I'm trying to do is to check the last access time of
Essentially, all I want to do is open an external web page after the
Essentially I've got a table holding user data, all of which is AES encrypted
Essentially, when a button is pressed the randomMove() method is called, this is mean't
Essentially, my route is working perfectly, Passenger seems to be loading - all is
Essentially Im trying to get many many java clients connect to a socket on

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.