Skip to content

Commit c9576e8

Browse files
committed
ml code
Signed-off-by: Saurabh Misra <[email protected]>
1 parent 558e975 commit c9576e8

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

codeflash/after_ml.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import jax.numpy as jnp
2+
3+
4+
def sum_hand(hand):
5+
"""Returns the total points in a hand."""
6+
return jnp.sum(hand) + (10 * usable_ace(hand))
7+
8+
9+
def usable_ace(hand):
10+
"""Checks to se if a hand has a usable ace."""
11+
return jnp.logical_and(jnp.any(hand == 1), jnp.sum(hand) + 10 <= 21)

codeflash/before_ml.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import jax.numpy as jnp
2+
3+
4+
def sum_hand(hand):
5+
"""Returns the total points in a hand."""
6+
return sum(hand) + (10 * usable_ace(hand))
7+
8+
9+
def usable_ace(hand):
10+
"""Checks to se if a hand has a usable ace."""
11+
return jnp.logical_and((jnp.count_nonzero(hand == 1) > 0), (sum(hand) + 10 <= 21))

0 commit comments

Comments
 (0)