We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent ba88ad2 commit 8eac4e5Copy full SHA for 8eac4e5
archive/t/ti-basic/josephus-problem.bas
@@ -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
27
+ N+1->N
28
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
42
+ Disp G+1
43
0 commit comments