반응형
Terminal game move function
In this game, the hero moves from left to right. The player rolls the dice and moves the number of spaces indicated by the dice two times.
In SQL, you will be given a table moves with columns position and roll. Return a table which uses the current position of the hero and the roll (1-6) and returns the new position in a column res.
Example:
move(3, 6) should equal 15
Solution:
SELECT
position + (roll * 2) as res
FROM
moves
Result:
res |
8 |
15 |
12 |
반응형
'나는 이렇게 학습한다 > Algorithm & SQL' 카테고리의 다른 글
Easy SQL: Rounding Decimals (0) | 2022.05.30 |
---|---|
Easy SQL: Moving Values (0) | 2022.05.29 |
Easy SQL: Cube Root and Natural Log (0) | 2022.05.27 |
Grasshopper - Check for factor (0) | 2022.05.26 |
SQL Basics: Maths with String Manipulations (0) | 2022.05.25 |