With your favorite language

...

Other urls found in this thread:

oeis.org/A000170
pwdhash.com/
twitter.com/SFWRedditImages

The point of 8 queens isn't to be a language exercise, but an algorithm exercise.

Doing this in Racket lisp with backtracking was pretty fun. When I get around to learning about constraint logic programming I'm going to try it again with their kanren module.

You tell me that when you write recursive subroutines in assembly.

Python, although I'm missing some stuff from Java like multiple constructors or overloaded methods.

I start with C++ and that's the only language I know...

So kill me, I like javascript. I love user functions and simple asynchronous stuff. It's okay now I promise.

solutions :: [[Int]]
solutions = helper []
where
helper xs = if length xs == 8
then return xs
else possibleChoices xs >>= (\x -> helper (x:xs))

possibleChoices :: [Int] -> [Int]
possibleChoices xs = filter (`notElem` notAllowed) [1..8]
where
notAllowed = xs
++ foldr (\x xs -> map (+1) (x:xs)) [] xs
++ foldr (\x xs -> map (flip (-) 1) (x:xs)) [] xs

English

French.
Is French really the language of love?
Of course! Have you ever planned a romantic holiday to Paris, or learnt how to say je t’aime? There’s no denying that French really is the language of love.

>French
>writes in English

At that level, is there even a difference between recursive and iterative routines?

did u copy and paste this?

#include
#include
#include

int Dim, Solutions = 0;
int* Queens;

void solution ()
{
for (int j, i = 0; i < Dim; ++i) {
for (j = 0; j < Queens[i]; ++j) {
printf(" .");
}
printf(" Q");
for (j++; j < Dim; ++j) {
printf(" .");
}
printf("\n");
}
printf("\n");
Solutions++;
}

void fill_bad_loc (int* bad, int x, int y)
{
/* vertical */
for (int i = y; i < Dim; i++) {
bad[i] |= 1

Yes, recursive means you have to call it recursively and you are adding to the stack frame.

Nope. I wrote it in Haskell.

looks elegant, too bad I don't understand any of it

So basically it's being needlessly inefficient for the sake of a pedantic difference?

>what is tail call optimization

The format that I used is a list of ints, where each int describes the position of a queen on a row. I chose to number the position from 1 to 8, so the solution show in OP would be represented as: [4,7,3,8,2,5,1,6].

possibleChoices takes in a partial solution and outputs the list of valid positions for a queen to be placed in the next row up. For example: possibleChoices [1,6] = [3,5,7]

Then, the solutions helper function basically bruteforces solutions using that.

i kind of understand.
But don't columns matter too?
and how many solutions does n queens give anyways?

C. Used to really enjoy Java but haven't worked with it in a long while.

The int itself is the column number and its position in the list is the row number.

There's no formula for working out how many solutions exist: oeis.org/A000170

I see.
Like I said, the solution looks interesting.
And btw, why did you flip (-) 1 instead of (-1)?

Haskell interprets (-1) as the number negative one.

oh yes, I forgot that little caveat
any projects you've done in haskell, or just anything really

I've been working on a deterministic password generator. Similar to pwdhash.com/ but with bcrypt instead of MD5.

good luck desu
I'm still a newbie, so I do pajeet tier code, hopefully I can get to your level before long.
Good luck senpai

Thanks, and good luck to you too.