Middle three digits: Difference between revisions

m
imported>Arakov
 
(5 intermediate revisions by 2 users not shown)
Line 452:
</pre>
<p>VERSION 2:</p>
<syntaxhighlight lang="c">
#include <basico.h>
 
algoritmo
n=0, c="",
temp = 0, candidatos={}
'123, 12345, 1234567, 987654321, 10001, -10001,-123'
'-100, 100, -12345,1, 2, -1, -10, 2002, -2002, 0'
enlistar en 'candidatos'
decimales '0'
tomar 'candidatos' ---retener---, obtenerquitar el signo, multiplicar
convertir a cadena ---retener---, guardarobtener enlargo, mover a 'tempn' ,
guardar en 'temp'
guardar ' replicar ( temp, #(n>=3 && not(is even(n))))' en 'c'
token.separador(NL)
justificar derecha(11,#(string(candidatos))), " : ", concatenar esto
#( copy( 3, (n/2-1), c ) ), unir esto
luego imprime
terminar
</syntaxhighlight>
{{out}}
<pre>
123 : 123
12345 : 234
1234567 : 345
987654321 : 654
10001 : 000
-10001 : 000
-123 : 123
-100 : 100
100 : 100
-12345 : 234
1 :
2 :
-1 :
-10 :
2002 :
-2002 :
0 :
</pre>
 
<p>VERSION 3:</p>
<syntaxhighlight lang="c">
#include <basico.h>
Line 458 ⟶ 507:
n=0, c="", m=0,
temp = 0, candidatos={}
'123, 12345, 1234567, 987654321, 10001, -10001,-123'
'-100, 100, -12345,1, 2, -1, -10, 2002, -2002, 0'
enlistar en 'candidatos'
tomar 'candidatos' ---retener---, obtener signo, multiplicar
convertir a cadena, guardar en 'temp'
decimales '0'
para cada elemento (v,candidatos,17)
tomar'v' ---retener; copiar en 'm'---, obtenerquitar el signo, multiplicar,
guardar en 'v'
Line 2,656 ⟶ 2,702:
if(len<3)
{
InvalidArgumentException.new:("n must have 3 digits or more").raise()
}
else if(len.isEven())
{
InvalidArgumentException.new:("n must have an odd number of digits").raise()
};
Line 2,671 ⟶ 2,717:
{
new int[]{123, 12345, 1234567, 987654321, 10001, -10001, -123, -100, 100, -12345, 1, 2, -1, -10, 2002, -2002, 0}
.forEach::(n)
{
console.printLine("middleThreeDigits(",n,"):",middleThreeDigits(n) \\ on::(e => e.Message))
}
}</syntaxhighlight>
Line 6,448 ⟶ 6,494:
=={{header|Wren}}==
{{libheader|Wren-fmt}}
<syntaxhighlight lang="ecmascriptwren">import "./fmt" for Fmt
 
var middle3 = Fn.new { |n|
Line 6,465 ⟶ 6,511:
 
for (e in a) {
SystemFmt.print("%(Fmt.s(9$9d -> $n", e)), -> %(middle3.call(e))")
}</syntaxhighlight>
 
Anonymous user