Shift list elements to left by 3: Difference between revisions

m
→‎{{header|Wren}}: Changed to Wren S/H
(Added PL/0)
m (→‎{{header|Wren}}: Changed to Wren S/H)
(6 intermediate revisions by 4 users not shown)
Line 9:
=={{header|11l}}==
{{trans|Python}}
 
<syntaxhighlight lang="11l">F rotate(l, n)
V k = (l.len + n) % l.len
Line 621 ⟶ 620:
 
=={{header|Arturo}}==
 
<syntaxhighlight lang="rebol">lst: [1 2 3 4 5 6 7 8 9]
print rotate.left lst 3</syntaxhighlight>
 
{{out}}
 
<pre>4 5 6 7 8 9 1 2 3</pre>
 
Line 679 ⟶ 676:
new: b;c;d;a
</pre>
 
 
 
=={{header|BASIC}}==
Line 802 ⟶ 797:
</pre>
 
=={{header|BQN}}==
<syntaxhighlight lang="eulerbqn">data ← 1 + ↕9
 
3 ⌽ data</syntaxhighlight>
{{out}}
<pre>⟨ 4 5 6 7 8 9 1 2 3 ⟩</pre>
 
=={{header|C}}==
Line 943 ⟶ 944:
 
=={{header|Euler}}==
'''begin'''
<syntaxhighlight lang="euler">
'''new''' shl; '''new''' shl3;
begin
new shl; new shl3;
shl <&lt;- ` '''formal''' ls;
 
'''if''' '''length''' ls &lt; 2 '''then''' ls
shl <- ` formal ls;
if length ls < 2 then ls '''else''' '''begin'''
else begin '''new''' L;
new L &lt;- ls;
L <-'''tail''' lsL &amp; ( L[ 1 ] )
tail L & ( L[ 1 ] )'''end'''
end&apos;;
shl3 <&lt;- ` '''formal''' ls; shl( shl( shl( ls ) ) ) '&apos;;
';
shl3 <- ` formal ls; shl( shl( shl( ls ) ) ) ';
'''out''' shl3( ( 1, 2, 3, 4, 5, 6, 7, 8 ) )
 
'''end'''
out shl3( ( 1, 2, 3, 4, 5, 6, 7, 8 ) )
$
end
</syntaxhighlight>
 
=={{header|Excel}}==
Line 1,156 ⟶ 1,155:
next i</syntaxhighlight>
{{out}}<pre>4, 5, 6, 7, 8, 9, 1, 2, 3</pre>
 
=={{header|Go}}==
{{trans|Wren}}
Line 1,224:
 
=={{header|J}}==
 
<syntaxhighlight lang=J> 3 |. 1 2 3 4 5 6 7 8 9
4 5 6 7 8 9 1 2 3</syntaxhighlight>
 
However, while this matches the task example, it does not match the task title. In most contexts, a shift is different from a rotate:
 
<syntaxhighlight lang=J> 3 |.(!.0) 1 2 3 4 5 6 7 8 9
4 5 6 7 8 9 0 0 0</syntaxhighlight>
Line 1,330 ⟶ 1,328:
"123456789" | rotateLeft(3) #=> "456789123"
</pre>
 
=={{header|Julia}}==
<syntaxhighlight lang="julia">list = [1, 2, 3, 4, 5, 6, 7, 8, 9]
Line 1,342 ⟶ 1,341:
{{out}}
<pre>{4, 5, 6, 7, 8, 9, 1, 2, 3}</pre>
 
=={{header|Maxima}}==
<syntaxhighlight lang="maxima">
list:[1,2,3,4,5,6,7,8,9]$
append(rest(list,3),rest(list,-(length(list)-3)));
</syntaxhighlight>
{{out}}
<pre>
[4,5,6,7,8,9,1,2,3]
</pre>
 
=={{header|Nim}}==
Line 1,399 ⟶ 1,408:
PL/0 has no data structures, not even arrays. This sample simulates an array using separate variables for each element. The simulated array is then used to represent the list.
<br>
The output shows the original list (one element per line) and the shifted list, separated by -111.
<br>
Note that PL/0 was intended as an educational tool for teaching compiler writing - so, e.g.: adding arrays might be an exercise for the students.
<syntaxhighlight lang="pascal">
const maxlist = 8;
Line 1,567 ⟶ 1,578:
 
=={{header|Quackery}}==
 
<syntaxhighlight lang="quackery">' [ 1 2 3 4 5 6 7 8 9 ] 3 split swap join echo</syntaxhighlight>
 
{{out}}
 
<pre>[ 4 5 6 7 8 9 1 2 3 ]</pre>
 
Line 1,652 ⟶ 1,661:
 
=={{header|RPL}}==
====Using the stack (idiomatic)====
≪ LIST→ → size
<span style="color:red">1 3</span> '''START''' size ROLL '''NEXT'''
size →LIST
≫ ≫ '<span style="color:blue">SLL3</span>' STO
≫ ≫
'SLL3' STO
 
====Following ''Programming Pearls''' Problem B algorithm====
{ 1 2 3 4 5 6 7 8 } SLL3
{{works with|HP|48G}}
≪ <span style="color:red">3</span> DUP2 <span style="color:red">1</span> SWAP SUB REVLIST
ROT ROT <span style="color:red">1</span> + OVER SIZE SUB REVLIST
+ REVLIST
≫ ‘<span style="color:blue">SLL3</span>’ STO
 
{ 1 2 3 4 5 6 7 8 } <span style="color:blue">SLL3</span>
{{out}}
<pre>
Line 1,686 ⟶ 1,702:
After: [4, 5, 6, 7, 8, 9, 1, 2, 3]
</pre>
 
=={{header|Scheme}}==
{{works with|Chez Scheme}}
Line 1,715 ⟶ 1,732:
 
=={{header|Wren}}==
<syntaxhighlight lang="ecmascriptwren">// in place left shift by 1
var lshift = Fn.new { |l|
var n = l.count
Line 1,737 ⟶ 1,754:
{{libheader|Wren-seq}}
Alternatively, using a library method to produce the same output as before.
<syntaxhighlight lang="ecmascriptwren">import "./seq" for Lst
var l = (1..9).toList
9,482

edits