-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrisan3.R
More file actions
55 lines (49 loc) · 850 Bytes
/
risan3.R
File metadata and controls
55 lines (49 loc) · 850 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
step1 = function(n)
{
choice = n %% 6
n = n - choice
text = paste("I take",as.character(choice),", n =",as.character(n))
print(text)
return(n)
}
steps = function(n,get_num)
{
if(get_num > 5|get_num < 1)
{
print("Please input correct number!")
return (n)
}
n = n - as.integer( get_num)
if(n < 0)
{
print(paste("n =",as.character(n)))
print("you lost")
return(999999)
}
n = step1(n)
return(n)
}
games = function(n)
{
if(n%%6 == 0)
{
print("You first")
print("Input your num:")
get_num = as.integer(readline())
n = steps(n,get_num)
}
else
{
print("I first")
n = step1(n)
}
while(n != 999999)
{
print("Input your num:")
get_num = as.integer(readline())
n = steps(n,get_num)
}
}
print("Please input n")
n = as.integer(readline())
games(n)