2
1
There's a board with n squares in a horizontal row.
You start in the leftmost square, and roll a 3-faced dice.
3 possible outcomes for a single roll of the die:
- Left: you move 1 step to the left, if possible.
- None: you stay where you are
- Right: you move 1 step to the right, if possible.
You want to roll the dice exactly t times, and end up at the rightmost square on the last roll.
edit: If you arrive at the rightmost square before t rolls, your only valid move is None.
You need to determine the number of valid (meaning, for instance, that you don't count sequences that try to move left or right from the rightmost square), unique sequences of dice rolls, for given (t,n) pairs. As the answer may be large, give it modulo 1000000007 (ie. 10^9+7).
- t is a positive integer s.t. t <= 1000
- n is a positive integer s.t. 2 <= n <= 1000
Sample testcases:
- t=1, n=2, answer=1
- t=3, n=2, answer=3
- t=4, n=3, answer=7
The Shortest code in
Bytes
wins
2
Seems like you were redirected here from Stack Overflow. It's a good question, but there's two things I'd like to ask: 1) PPCG questions need an objective winning criterion - how are you going to decide the winner here? (My suggestion would be code-golf), and 2) Is this a question from an ongoing contest?
– Sp3000 – 2015-02-23T04:16:05.753This question will get put on hold or closed as off topic if you don't give it an objective winning criterion. I would suggest code-golf (shortest code, in bytes) as it will be easy to determine the winner. Fastest code is likely to attract less answers (though they might be more interesting) and it requires you to test the answers to determine the winner. – Level River St – 2015-02-23T05:53:42.993
I'm getting an answer of 4, not 3, for
t=3, n=2
, with the sequencesRSS, SRS, SSR, RLR
. Am I missing a rule? – xnor – 2015-02-23T06:52:33.667@xnor: yep, you're absolutely right; added it in as an edit. – StChong8 – 2015-02-23T07:40:03.073
@Sp3000: done, as suggested; no, the contest is not ongoing. it's different from the typical programming contest that is open for a specified duration, this one is self-initiated as and when you please, and then a countdown timer starts from that time of your choosing. – StChong8 – 2015-02-23T07:43:51.947
@StChong8 I'm also getting 8 for
t=4, n=3
. – xnor – 2015-02-23T07:43:54.727@xnor t=4,n=3: the 7 that i get - RRLR, RRNN, RNRN, NNRR, NRRN, RNNR, RLRR – StChong8 – 2015-02-23T07:54:45.983
@StChong8 OK, I'm now getting the same values with the edit that you must stand still after arriving at the rightmost square, including 7 for
t=4, n=3
. – xnor – 2015-02-23T07:56:35.1633If this is from another contest, permanent or not, I still don't think it's a good idea to post it here, in particular, because it might violate their copyright. – Martin Ender – 2015-02-23T07:56:53.553
@xnor: yea, sorry about that. – StChong8 – 2015-02-23T07:56:57.473
@StChong8 "@xnor t=4,n=3: the 7 that i get -
RRLR
" How isRRLR
supposed to be valid ? – Mukul Kumar – 2015-02-23T11:34:43.987@StChong8 can we move left on leftmost pos'n?Plz be quick as I cannot post my code unless you answer. – Mukul Kumar – 2015-02-23T12:21:59.777
1
In view of our policy on posting challenges from competitions, I'm putting this on hold for now.
– Doorknob – 2015-02-23T12:49:42.233@Doorknob is that enough to reopen this question ? – Mukul Kumar – 2015-02-23T15:22:17.333
@MukulKumar The winning criterion has nothing to do with Doorknob's close vote. That was the close reason es1024 and I chose before a winning criterion was added. While this is no longer the appropriate close reason, I thought the challenge should still be closed, as stated in a comment above, and linked to by Doorknob - since I can't retract my close vote and recast it with another reason I just left it as it is. – Martin Ender – 2015-02-23T15:40:00.610
@MukulKumar: no, moving left from the leftmost pos (ie. starting square) is not allowed. – StChong8 – 2015-02-23T15:53:24.577
@StChong8 "@xnor t=4,n=3: the 7 that i get - RRLR" How is RRLR supposed to be valid ? – Mukul Kumar – 2015-02-23T16:02:53.287
Is this from a "virtual contest" for practicing purpose in preparation of real contests? In that case I think it is fine. – jimmy23013 – 2015-02-24T04:35:23.987