Skip to content

Commit 8eac4e5

Browse files
authored
Add Josephus Problem in TI Basic (#4462)
1 parent ba88ad2 commit 8eac4e5

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
"0123456789"->Str2
2+
2->dim(l1)
3+
1->M
4+
0->E
5+
While E=0 and M<=2
6+
Input "",Str1
7+
length(Str1)->L
8+
L<1->E
9+
0->D
10+
0->V
11+
1->N
12+
1->S
13+
While E=0 and N<=L
14+
sub(Str1,N,1)->C
15+
inString(Str2,C)-1->K
16+
If C="+" or C="-"
17+
Then
18+
D>0->E
19+
If C="-"
20+
Then 0-S->S
21+
End
22+
Else
23+
K<0->E
24+
D+1->D
25+
V*10+K*S->V
26+
End
27+
N+1->N
28+
End
29+
E or D<1->E
30+
V->l1(M)
31+
M+1->M
32+
End
33+
If E Then Disp "Usage: please input the total number of people and number of people to skip."
34+
Else
35+
:"Source: https://en.wikipedia.org/wiki/Josephus_problem#The_general_case"
36+
0->G
37+
l1(1)->N
38+
l1(2)->K
39+
For(M,2,N)
40+
remainder(G+K,M)->G
41+
End
42+
Disp G+1
43+
End

0 commit comments

Comments
 (0)