Deal Cards for Freecell Rosetta Code

Tell us what’s happening:

Hey, guys. I can’t understand what’s to be done by this challenge.
First it says theres 32768 in rand range but state mod 2^16 doubles this range
Maybe I’m seeding the wrong way

Thanks for your help :slight_smile:

Your code so far

const pow = Math.pow;

const state = (n) => 

const rand = (n) => state(n)%pow(2,16);

let cards = [

const dealFreeCell=(seed)=>{
let deal = [];
let res = [[],[],[],[],[],[],[]];
  let index = rand(seed)%cards.length;
  [ cards[index] , cards[cards.length-1] ] =
  [ cards[cards.length-1] , cards[index] ]

for(let i=0;i<6;i++)
  for(let j=0;j<8;j++)

for(let i=0;i<4;i++)

return res;


Your browser information:

User Agent is: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36.

Challenge: Deal cards for FreeCell

Link to the challenge:

rand is state divided by 2**16, not mod of it.

seed is directly used for calculating only first state (seed is kind of state 0 or even state -1), later with each iteration, nth state is calculated based on n - 1 state.

1 Like

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.