Add tasks for all the new languages
This commit is contained in:
parent
9dc3c2bb62
commit
bba7bfd280
13208 changed files with 134745 additions and 0 deletions
24
Task/Stem-and-leaf-plot/Ceylon/stem-and-leaf-plot.ceylon
Normal file
24
Task/Stem-and-leaf-plot/Ceylon/stem-and-leaf-plot.ceylon
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
"Run the module `thestemandleafplot`."
|
||||
shared void run() {
|
||||
|
||||
value data ="12 127 28 42 39 113 42 18 44 118 44 37 113 124 37 48 127 36 29 31 125 139 131 115 105 132 104 123 35
|
||||
113 122 42 117 119 58 109 23 105 63 27 44 105 99 41 128 121 116 125 32 61 37 127 29 113 121 58 114
|
||||
126 53 114 96 25 109 7 31 141 46 13 27 43 117 116 27 7 68 40 31 115 124 42 128 52 71 118 117 38 27
|
||||
106 33 117 116 111 40 119 47 105 57 122 109 124 115 43 120 43 27 27 18 28 48 125 107 114 34 133 45
|
||||
120 30 127 31 116 146";
|
||||
|
||||
value numbers = data
|
||||
.split()
|
||||
.map(parseInteger)
|
||||
.coalesced;
|
||||
|
||||
value stemsToLeaves = numbers
|
||||
.group((Integer element) => element / 10)
|
||||
.mapItems((Integer key, [Integer+] item) => item.map((Integer element) => element % 10))
|
||||
.mapItems((Integer key, {Integer+} item) => sort(item));
|
||||
|
||||
value lastStem = stemsToLeaves.keys.last else 0;
|
||||
for(i in 0..lastStem) {
|
||||
print("``formatInteger(i).padLeading(2)``| ``" ".join(stemsToLeaves[i] else [])``");
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,79 @@
|
|||
' version 22-06-2015
|
||||
' compile with: fbc -s console
|
||||
' for boundry checks on array's compile with: fbc -s console -exx
|
||||
' from the rosetta code FreeBASIC entry
|
||||
#Define out_of_data 99999999 ' any number that is not in the set will do
|
||||
|
||||
Sub shellsort(s() As Integer)
|
||||
' from the FreeBASIC entry at rosetta code
|
||||
' sort from lower bound to the highter bound
|
||||
Dim As Integer lb = LBound(s)
|
||||
Dim As Integer ub = UBound(s)
|
||||
Dim As Integer done, i, inc = ub - lb
|
||||
|
||||
Do
|
||||
inc = inc / 2.2
|
||||
If inc < 1 Then inc = 1
|
||||
Do
|
||||
done = 0
|
||||
For i = lb To ub - inc
|
||||
If s(i) > s(i + inc) Then
|
||||
Swap s(i), s(i + inc)
|
||||
done = 1
|
||||
End If
|
||||
Next
|
||||
Loop Until done = 0
|
||||
Loop Until inc = 1
|
||||
|
||||
End Sub
|
||||
|
||||
' ------=< TASK DATA >=------
|
||||
|
||||
Data 12, 127, 28, 42, 39, 113, 42, 18, 44, 118, 44, 37, 113, 124
|
||||
Data 37, 48, 127, 36, 29, 31, 125, 139, 131, 115, 105, 132, 104, 123
|
||||
Data 35, 113, 122, 42, 117, 119, 58, 109, 23, 105, 63, 27, 44, 105
|
||||
Data 99, 41, 128, 121, 116, 125, 32, 61, 37, 127, 29, 113, 121, 58
|
||||
Data 114, 126, 53, 114, 96, 25, 109, 7, 31, 141, 46, 13, 27, 43
|
||||
Data 117, 116, 27, 7, 68, 40, 31, 115, 124, 42, 128, 52, 71, 118
|
||||
Data 117, 38, 27, 106, 33, 117, 116, 111, 40, 119, 47, 105, 57, 122
|
||||
Data 109, 124, 115, 43, 120, 43, 27, 27, 18, 28, 48, 125, 107, 114
|
||||
Data 34, 133, 45, 120, 30, 127, 31, 116, 146
|
||||
Data out_of_data
|
||||
|
||||
' ------=< MAIN >=------
|
||||
|
||||
Dim As String read_in
|
||||
Dim As Integer i, x, y, count = -1 ' to let the index start on 0
|
||||
Dim As Integer d()
|
||||
ReDim d(300) ' big enough to hold data index start at 0
|
||||
|
||||
Do
|
||||
Read i
|
||||
If i = out_of_data Then Exit Do
|
||||
count = count + 1
|
||||
d(count) = i
|
||||
Loop
|
||||
|
||||
ReDim Preserve d(count) ' trim the data array
|
||||
shellsort(d()) ' sort data array
|
||||
|
||||
i = 0
|
||||
For y = d(0) \ 10 To d(UBound(d)) \ 10
|
||||
Print Using "#### |"; y;
|
||||
Do
|
||||
x = d(i) \ 10 ' \ = integer division
|
||||
If y = x Then
|
||||
Print Using "##"; d(i) Mod 10;
|
||||
i = i + 1
|
||||
Else
|
||||
Exit Do
|
||||
End If
|
||||
Loop While i <= UBound(d)
|
||||
Print ' force linefeed
|
||||
Next
|
||||
|
||||
' empty keyboard buffer
|
||||
While Inkey <> "" : Wend
|
||||
Print : Print "hit any key to end program"
|
||||
Sleep
|
||||
End
|
||||
26
Task/Stem-and-leaf-plot/Phix/stem-and-leaf-plot.phix
Normal file
26
Task/Stem-and-leaf-plot/Phix/stem-and-leaf-plot.phix
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
procedure leaf_plot(sequence s)
|
||||
sequence stem
|
||||
s = sort(s)
|
||||
stem = repeat({},floor(s[$]/10)+1)
|
||||
for i=1 to length(s) do
|
||||
stem[floor(s[i]/10)+1] &= remainder(s[i],10)
|
||||
end for
|
||||
for i=1 to length(stem) do
|
||||
printf(1, "%3d | ", i-1)
|
||||
for j=1 to length(stem[i]) do
|
||||
printf(1, "%d ", stem[i][j])
|
||||
end for
|
||||
puts(1,'\n')
|
||||
end for
|
||||
end procedure
|
||||
|
||||
constant data = { 12, 127, 28, 42, 39, 113, 42, 18, 44, 118, 44, 37, 113, 124,
|
||||
37, 48, 127, 36, 29, 31, 125, 139, 131, 115, 105, 132, 104, 123, 35, 113,
|
||||
122, 42, 117, 119, 58, 109, 23, 105, 63, 27, 44, 105, 99, 41, 128, 121,
|
||||
116, 125, 32, 61, 37, 127, 29, 113, 121, 58, 114, 126, 53, 114, 96, 25,
|
||||
109, 7, 31, 141, 46, 13, 27, 43, 117, 116, 27, 7, 68, 40, 31, 115, 124,
|
||||
42, 128, 52, 71, 118, 117, 38, 27, 106, 33, 117, 116, 111, 40, 119, 47,
|
||||
105, 57, 122, 109, 124, 115, 43, 120, 43, 27, 27, 18, 28, 48, 125, 107,
|
||||
114, 34, 133, 45, 120, 30, 127, 31, 116, 146 }
|
||||
|
||||
leaf_plot(data)
|
||||
24
Task/Stem-and-leaf-plot/Sidef/stem-and-leaf-plot.sidef
Normal file
24
Task/Stem-and-leaf-plot/Sidef/stem-and-leaf-plot.sidef
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
var data = %i(
|
||||
12 127 28 42 39 113 42 18 44 118 44
|
||||
37 113 124 37 48 127 36 29 31 125 139
|
||||
131 115 105 132 104 123 35 113 122 42 117
|
||||
119 58 109 23 105 63 27 44 105 99 41
|
||||
128 121 116 125 32 61 37 127 29 113 121
|
||||
58 114 126 53 114 96 25 109 7 31 141
|
||||
46 13 27 43 117 116 27 7 68 40 31
|
||||
115 124 42 128 52 71 118 117 38 27 106
|
||||
33 117 116 111 40 119 47 105 57 122 109
|
||||
124 115 43 120 43 27 27 18 28 48 125
|
||||
107 114 34 133 45 120 30 127 31 116 146
|
||||
).sort;
|
||||
|
||||
var stem_unit = 10;
|
||||
var h = data.group_by { |i| i / stem_unit -> int }
|
||||
|
||||
var rng = RangeNum(h.keys.map{.to_i}.minmax);
|
||||
var stem_format = "%#{rng.min.len.max(rng.max.len)}d";
|
||||
|
||||
rng.each { |stem|
|
||||
var leafs = (h{stem} \\ [])
|
||||
say(stem_format % stem, ' | ', leafs.map { _ % stem_unit }.join(' '))
|
||||
}
|
||||
18
Task/Stem-and-leaf-plot/jq/stem-and-leaf-plot-1.jq
Normal file
18
Task/Stem-and-leaf-plot/jq/stem-and-leaf-plot-1.jq
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
def stem_and_leaf:
|
||||
|
||||
# align-right:
|
||||
def right: tostring | (4-length) * " " + .;
|
||||
|
||||
sort
|
||||
| .[0] as $min
|
||||
| .[length-1] as $max
|
||||
| "\($min/10|floor|right) | " as $stem
|
||||
| reduce .[] as $d
|
||||
# state: [ stem, string ]
|
||||
( [ 0, $stem ];
|
||||
.[0] as $stem
|
||||
| if ($d/10) | floor == $stem
|
||||
then [ $stem, (.[1] + "\($d % 10)" )]
|
||||
else [ $stem + 1, (.[1] + "\n\($stem+1|right) | \($d % 10)" )]
|
||||
end )
|
||||
| .[1] ;
|
||||
11
Task/Stem-and-leaf-plot/jq/stem-and-leaf-plot-2.jq
Normal file
11
Task/Stem-and-leaf-plot/jq/stem-and-leaf-plot-2.jq
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
def data:
|
||||
[ 12,127,28,42,39,113, 42,18,44,118,44,37,113,124,37,48,127,36,29,31,
|
||||
125,139,131,115,105,132,104,123,35,113,122,42,117,119,58,109,23,105,
|
||||
63,27,44,105,99,41,128,121,116,125,32,61,37,127,29,113,121,58,114,126,
|
||||
53,114,96,25,109,7,31,141,46,13,27,43,117,116,27,7,68,40,31,115,124,42,
|
||||
128,52,71,118,117,38,27,106,33,117,116,111,40,119,47,105,57,122,109,
|
||||
124,115,43,120,43,27,27,18,28,48,125,107,114,34,133,45,120, 30,127,
|
||||
31,116,146
|
||||
];
|
||||
|
||||
data | stem_and_leaf
|
||||
16
Task/Stem-and-leaf-plot/jq/stem-and-leaf-plot-3.jq
Normal file
16
Task/Stem-and-leaf-plot/jq/stem-and-leaf-plot-3.jq
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
$ jq -n -r -f stem-and-leaf_plot.jq
|
||||
0 | 77
|
||||
1 | 2388
|
||||
2 | 357777778899
|
||||
3 | 011112345677789
|
||||
4 | 001222233344456788
|
||||
5 | 23788
|
||||
6 | 138
|
||||
7 | 1
|
||||
8 | 6
|
||||
9 | 9
|
||||
10 | 4555567999
|
||||
11 | 13333444555666677778899
|
||||
12 | 00112234445556777788
|
||||
13 | 1239
|
||||
14 | 16
|
||||
Loading…
Add table
Add a link
Reference in a new issue