I'm writing a module to handle dice rolling. Given x die of y sides, I'm trying to come up with a list of all potential roll combinations.
This code assumes 3 die, each with 3 sides labeled 1, 2, and 3. (I realize I'm using "magic numbers" but this is just an attempt to simplify and get the base code working.)
int[] set = { 1, 1, 1 };
list = diceroll.recurse(0,0, list, set);
...
public ArrayList<Integer> recurse(int index, int i, ArrayList<Integer> list, int[] set){
if(index < 3){
// System.out.print("\n(looping on "+index+")\n");
for(int k=1;k<=3;k++){
// System.out.print("setting i"+index+" to "+k+" ");
set[index] = k;
dump(set);
recurse(index+1, i, list, set);
}
}
return list;
}
(dump() is a simple method to just display the contents of list[]. The variable i is not used at the moment.)
What I'm attempting to do is increment a list[index] by one, stepping through the entire length of the list and incrementing as I go.
This is my "best attempt" code. Here is the output:
Bold output is what I'm looking for. I can't figure out how to get rid of the rest. (This is assuming three dice, each with 3 sides. Using recursion so I can scale it up to any x dice with y sides.)
[1][1][1] [1][1][1]
[1][1][1] [1][1][2] [1][1][3] [1][2][3]
[1][2][1] [1][2][2] [1][2][3] [1][3][3]
[1][3][1] [1][3][2] [1][3][3] [2][3][3] [2][1][3]
[2][1][1] [2][1][2] [2][1][3] [2][2][3]
[2][2][1] [2][2][2] [2][2][3] [2][3][3]
[2][3][1] [2][3][2] [2][3][3] [3][3][3] [3][1][3]
[3][1][1] [3][1][2] [3][1][3] [3][2][3]
[3][2][1] [3][2][2] [3][2][3] [3][3][3]
[3][3][1] [3][3][2] [3][3][3]
I apologize for the formatting, best I could come up with.
Any help would be greatly appreciated. (This method was actually stemmed to use the data for something quite trivial, but has turned into a personal challenge. :)
edit: If there is another approach to solving this problem I'd be all ears, but I'd also like to solve my current problem and successfully use recursion for something useful.
Obviously, there must be something stupid i'm doing. The unicode chart for subscripts and superscripts says #00B2 is superscript 2, but i get scrambled output. 0078 is x, but I get N, and 0120 is x. Am i reading wrong manual?
EDIT
$x = 'N';
print html_entity_decode($x, ENT_NOQUOTES, 'UTF-8') . "\n";
Hi all,
Let's say we have these classes:
class Foo(object):
_bar = ""
def __init__(self):
self.bar = "hello"
def getBar(self):
return self._bar
def setBar(self, bar):
self._bar = bar
def getAttributes(self):
for attr in self.__dict__:
print attr
bar = property(getBar, setBar)
class Child(Foo):
def __init__(self):
super(Child, self).__init__()
self.a = ""
self.b = ""
if I do something like:
child = Child()
child.getAttributes()
I get all the attributes from parent and child. How could I get the attributes only from the parent?
Thanks in advance!
Why I can't construct large tuples in Haskell? Why there's a tuple size limit?
Prelude> (1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1)
<interactive>:1:0:
No instance for (Show
(t,
t1,
t2,
...
t23))
arising from a use of `print' at <interactive>:1:0-48
Possible fix:
add an instance declaration for
(Show
(t,
t1,
t2,
...
t23))
In a stmt of a 'do' expression: print it
This is a module named XYZ.
def func(x)
.....
.....
if __name__=="__main__":
print func(sys.argv[1])
Now I have imported this module in another code and want to use the func. How can i use it?
import XYZ
After this, where to give the argument, and syntax on how to call it, please?
Hi,
I jus created a rails application. I created a model using ruby script/generate model Article
next i edited the my articles.rb file by adding these lines in self.up method
def self.up
create_table :articles do |t|
t.string :title
t.text :body
t.string :published_at
t.timestamps
end
end
Now i ran rake db:migrate . But migrate does not work, it simply does no print anything. Anyone knows where i am going wrong?
Let's say I have a list of elements
@list=(1,2,3);
#desired output
1,2,3
And I want to print them as comma seperated values. And most importantly, I do not want the last element to have a comma after it.
What is the cleanest way to do this in Perl?
I want to generate multiple pdf reports on click of single print button and zip all the pdf's and store it in a folder.
Any help please. I need this functionality in my project.
wow i thought i knew python untill tonight.. what is the correct way to do something like this.. heres my code
a = ["one", "two", "three"]
b = a #here i want a complete copy that when b is changed, has absolutely no effect on a
b.append["four"]
print a #a now has "four" in it..
so basically i want to know, instead of the b = a step, how would i correctly make a copy of a list or dictionary so that when b is changed a does not change along with it.. thanks guys
My current code:
wp_enqueue_style( 'script-css', plugins_url( 'script/myscript.js', FILE ));
My goal:
Instead of loading the file from the plugins directory, I want to load above script file from http://mycloudfronturl.net/myscript.js
But somehow I am messing with either the quotes or while replacing the plugins_url. I am not a hard code php coder, so can someone tell me what to do please?
Thanks and Regards,
Amod
Hello all,
Does anyone know of a DB setting in DotNetNuke, where you can configure ALL modules to disable print or maximize&minimize? Just so I don't have to configure every module individually.
How can I make it a default?
Thanks again!
System.out.println(
Arrays.deepToString(
"abc<def>ghi".split("(?:<)|(?:>)")
)
);
This prints [abc, def, ghi], as if I had split on "<|>". I want it to print [abc, <def>, ghi]. Is there a way to work some regex magic to accomplish what I want here?
What value is hashCode() method is returning in java?. i read that it is an memory reference of an object. when i print hascode value for new Integer(1), its 1. for String(a) - 97. so i confused. is it ascii or what type of value is?
I installed Doxygen 1.6.1.
I used \section, \subsection and \subsubsection for titles in C++ sources.
I surprisingly obtained titles in which \subsubsection have large font size than for \subsection and \section.
How can this be fixed?
CSS should be used to workaround this or can I fix my doxygen installation to obtain expected common behavior?
i will be printing the access report. the report will not be printed a regular white paper. it will be printed on top of a paper with checkboxes and fields on it. i need those checkboxes and fields to be printed on according to the access data.
are there any libraries for access that make this easier? is there a feature that will help to print on specific coordinates?
I have read somewhere that javascript and css files that only get cached in memory sooner or later get pushed out by other content. Is this true? Are there any other issues regarding cashing SSL-objects?
Can any one please tell me how can I disable the border of html? I was going to embed the html on another application and the border makes it look kind of boring.. Is there any CSS code to do this?
thanks!
typedef unsigned long long IMSI;
IMSI imsi;
when i am trying to print this using %llu as a format specifier, i am getting a rather unrelated value.
What can i do to remove this problem?
Iphone or blackberry or any other?
I do XHTML, CSS, Design, PHP work and use gmail, skype, firefox, twitter etc.
Which device would be helpful for me when i'm not at desk.
OK I have a program that creates two pipes - forks - the child's stdin and stdout are redirected to one end of each pipe - the parent is connected to the other ends of the pipes and tries to read the stream associated with the child's output and print it to the screen (and I will also make it write to the input of the child eventually).
The problem is, when the parent tries to fgets the child's output stream, it just stalls and waits until the child dies to fgets and then print the output. If the child doesn't exit, it just waits forever. What is going on? I thought that maybe fgets would block until SOMETHING was in the stream, but not block all the way until the child gives up its file descriptors.
Here is the code:
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <sys/types.h>
#include <unistd.h>
int main(int argc, char *argv[]) {
FILE* fpin;
FILE* fpout;
int input_fd[2];
int output_fd[2];
pid_t pid;
int status;
char input[100];
char output[100];
char *args[] = {"/somepath/someprogram", NULL};
fgets(input, 100, stdin); // the user inputs the program name to exec
pipe(input_fd);
pipe(output_fd);
pid = fork();
if (pid == 0) {
close(input_fd[1]);
close(output_fd[0]);
dup2(input_fd[0], 0);
dup2(output_fd[1], 1);
input[strlen(input)-1] = '\0';
execvp(input, args);
}
else {
close(input_fd[0]);
close(output_fd[1]);
fpin = fdopen(input_fd[1], "w");
fpout = fdopen(output_fd[0], "r");
while(!feof(fpout)) {
fgets(output, 100, fpout);
printf("output: %s\n", output);
}
}
return 0;
}
Hello,
I have been coding a site in pure HTML/CSS - using no server-side language.
I was wondering if anyone had any feedback - is there anything that you would change etc...?
Many Thanks,
J
View Site
How can I send trace messages to the console (like print) when I'm running my Django app under manage.py runserver, but have those messages sent to a log file when I'm running the app under Apache?
I reviewed Django logging and although I was impressed with its flexibility and configurability for advanced uses, I'm still stumped with how to handle my simple use-case.
My apologies for not being able to find the answer elsewhere-- this is a newbie question I know.