You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/index.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -5,6 +5,6 @@ layout: default
5
5
title: Sample Programs in Every Language
6
6
---
7
7
8
-
Welcome to Sample Programs in Every Language, a collection of code snippets in as many languages as possible. Thanks for taking an interest in our collection which currently contains 1490 articles written by 281 authors.
8
+
Welcome to Sample Programs in Every Language, a collection of code snippets in as many languages as possible. Thanks for taking an interest in our collection which currently contains 1493 articles written by 281 authors.
9
9
10
10
If you'd like to contribute to this growing collection, check out our [contributing document](https://github.com/TheRenegadeCoder/sample-programs/blob/master/.github/CONTRIBUTING.md) for more information. In addition, you can explore our documentation which is organized by [project](/projects) and by [language](/languages). If you don't find what you're look for, check out our list of related [open-source projects](/related). Finally, if code isn't your thing but you'd still like to help, there are plenty of other ways to [support the project](https://therenegadecoder.com/updates/5-ways-you-can-support-the-renegade-coder/).
Copy file name to clipboardExpand all lines: docs/languages/index.md
+18-18Lines changed: 18 additions & 18 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -6,7 +6,7 @@ layout: default
6
6
title: Programming Languages
7
7
---
8
8
9
-
Welcome to the Languages page! Here, you'll find a list of all of the languages represented in the collection. At this time, there are 156 languages, of which 155 are tested, 1 is untestable, and 1296 code snippets.
9
+
Welcome to the Languages page! Here, you'll find a list of all of the languages represented in the collection. At this time, there are 156 languages, of which 155 are tested, 1 is untestable, and 1299 code snippets.
10
10
11
11
## Language Breakdown
12
12
@@ -18,43 +18,43 @@ Here are the percentages for each language in the collection:
Welcome to the [Josephus Problem](https://sampleprograms.io/projects/josephus-problem) in [Tcl](https://sampleprograms.io/languages/tcl) page! Here, you'll find the source code for this program as well as a description of how the program works.
26
+
27
+
## Current Solution
28
+
29
+
{% raw %}
30
+
31
+
```tcl
32
+
proc usage {} {
33
+
puts stderr {Usage: please input the total number of people and number of people to skip.}
34
+
exit 1
35
+
}
36
+
37
+
proc parseInt {s} {
38
+
set s [string trim $s]
39
+
if {[string is integer -strict $s]} { return $s }
40
+
usage
41
+
}
42
+
43
+
proc josephus {total skip} {
44
+
if {$skip < 1 || $total < 1} { usage }
45
+
46
+
# If skip = 1, survivor is the last person
47
+
if {$skip == 1} { return $total }
48
+
49
+
# Optimized case for skip = 2
50
+
if {$skip == 2} {
51
+
set power 1
52
+
while {($power << 1) <= $total} {
53
+
set power [expr {$power << 1}]
54
+
}
55
+
return [expr {2 * ($total - $power) + 1}]
56
+
}
57
+
58
+
set result 0
59
+
for {set i 2} {$i <= $total} {incr i} {
60
+
set result [expr {($result + $skip) % $i}]
61
+
}
62
+
63
+
return [expr {$result + 1}]
64
+
}
65
+
66
+
if {$argc != 2} { usage }
67
+
68
+
set total [parseInt [lindex $argv 0]]
69
+
set skip [parseInt [lindex $argv 1]]
70
+
71
+
puts [josephus $total $skip]
72
+
73
+
```
74
+
75
+
{% endraw %}
76
+
77
+
Josephus Problem in [Tcl](https://sampleprograms.io/languages/tcl) was written by:
78
+
79
+
- Ștefan-Iulian Alecu
80
+
81
+
If you see anything you'd like to change or update, [please consider contributing](https://github.com/TheRenegadeCoder/sample-programs).
82
+
83
+
## How to Implement the Solution
84
+
85
+
No 'How to Implement the Solution' section available. [Please consider contributing](https://github.com/TheRenegadeCoder/sample-programs-website).
86
+
87
+
## How to Run the Solution
88
+
89
+
No 'How to Run the Solution' section available. [Please consider contributing](https://github.com/TheRenegadeCoder/sample-programs-website).
Welcome to the [Linear Search](https://sampleprograms.io/projects/linear-search) in [Tcl](https://sampleprograms.io/languages/tcl) page! Here, you'll find the source code for this program as well as a description of how the program works.
26
+
27
+
## Current Solution
28
+
29
+
{% raw %}
30
+
31
+
```tcl
32
+
proc usage {} {
33
+
puts stderr {Usage: please provide a list of integers ("1, 4, 5, 11, 12") and the integer to find ("11")}
34
+
exit 1
35
+
}
36
+
37
+
proc parseList {s} {
38
+
set tokens [split [string trim $s] ","]
39
+
if {[llength $tokens] < 1} { usage }
40
+
41
+
set result {}
42
+
43
+
set result {}
44
+
foreach token $tokens {
45
+
set t [string trim $token]
46
+
if {$t eq "" || [catch {expr {int($t)}} val]} usage
0 commit comments