зш, 100 98 байт
for i ({$1..$2})((i%8))||i=`tr -dc !-/:-~</*/ur*|head -c$#i`&&<<<$i
Два входных аргумента передаются как аргументы командной строки, а числа выводятся в отдельных строках.
{r:IntRange->var s=""
for(i in r){for(c in "$i"){var n=java.util.Random().nextInt(83)
if(n>14)n+=10
s+=if(i%8>0)c
else '!'+n}
s+=" "}
s}
||answer||
Пайк, 22 21 байт
function c8( $a, $b ) {
for( ; $a<=$b; $a++ ) { // loop between a -> b
echo $a % 8 ? $a : // every 8, call anon func instead of value
(function($l) {
while( $l-- ) { // repeat length of value
$x = rand( 44, 128 ); // range size is printable chars [33,47][58,127]
$x-= $x > 58 ?: 11; // Subtract one from x. If x was less than or
// equal to 58, subtract a further ten from it
// so that it now falls within the 33-47 range
echo chr( $x ); // echo ASCII value
}
})( strlen( $a ) )," ";
}
}
Попробуйте здесь!
Принимает ввод в форме: function($a,$b){for(;$a<=$b;$a++)echo$a%8?$a:(function($l){while($l--)echo chr(($x=rand(44,128))-($x>58?:11));})(strlen($a))," ";}
, include random.fs
\ get the length (in digits) of a number
: num-length 0 <# #s #> nip ;
\ check if a number is a multiple of another
: is-multiple mod 0= ;
\ get a random printable non-digit ascii char
: random-char 84 random 33 + dup 47 > 10 * - ;
\ get a "random" string of printable ascii chars the same length as a number
: rand-str num-length 0 do random-char emit loop space ;
\ print numbers from a to b, replacing multiple of 8 with a random ascii string of the same length
: crazy-eights 1+ swap do i 8 is-multiple if i rand-str else i . then loop ;
include random.fs \ include/import the random module
: f \ start new word definition
1+ swap \ add 1 to end number, because forth loops are [start, end), and swap order
do \ start counted loop form start to end
i 8 mod \ get the remainder of dividing i (loop index) by 8
if \ if true (not 0, therefore not multiple of 8)
i . \ print the index
else \ otherwise
i 0 \ convert index to double-length number
<# #s #> \ use formatted numeric output to convert number to a string
0 do \ loop from 0 to (string-length - 1)
84 random \ get random number between 0 and 83
33 + \ add 33
dup 47 > \ check if result is larger than 47
10 * - \ if it is add 10 to result (results in number in range: 33-47,58-126)
emit \ output ascii char corresponding with number
loop \ end inner loop
." "then \ output a space and then close the if/else
loop \ end the outer loop
; \ end the word definition
||answer||
Математика, 96 байт
include random.fs
: f 1+ swap do i 8 mod if i . else i 0 <# #s #> 0 do 83 random 33 + dup 47 > 10 * - emit loop ." "then loop ;
Объяснение
Для входов ;òV ®%8?Z:EÅk9ò)öZìl :Implicit input of integers U & V
òV :Range [U,V]
® :Map each Z
%8 : Modulo 8
?Z: : If truthy, return Z, else
; E : Printable ASCII
Å : Slice off first character
k : Remove
9ò : Range [0,9]
) : End remove
Zì : Digit array of Z
l : Length
ö : Get that many random characters from the string
и ;òV ®%8?Z:EÅk9ò)öZìl
:
Ÿ # Create a list in the range [low (implicit) input, high (implicit) input]
ε # Map each value to:
D # Duplicate the value
8Öi # If it's divisible by 8:
žQ # Push all printable ASCII characters (" " through "~")
žhK # Remove all digits
¦ # Remove the first character (the space)
.r # Randomly shuffle the remaining characters
s # Swap to take the map value again
g # Get its length
£ # And leave that many characters from the string
# (and implicitly output the resulting list after we're done mapping)
Генерировать highest\nlowest
ŸεD8ÖižQžhK¦.rsg£
Для всех чисел, которые делятся на 8 (назовем это :: Get inputs 'a' and 'b' from the command line
[a,b| FOR(c=a; c<=b; c++)
~c%8=0| IF c is cleanly divisible by 8 THEN
_l!c$| Take the length (_l) of the string representation (! ... $) of c
[ | FOR (d = 1; d<= length(c); d++)
_R33,116| Set e to a random value in the range 33 - 116 (all the printable ascii's - 10)
~e>47 IF e falls between 47
and e<58| and 58 (ASCII code for 0-9) THEN
e=e+z e = e + 10 (z == 10 in QBIC)
] END IF
Z=Z+ Add to Z$
chr$(e)] ASCII character e
\ ELSE if c is not cleanly divisible by 8
Z=Z+!c$ Add to Z the string representation of c
] NEXT
Z=Z+@ Add a space to Z$ (@ is an implicitly delimited string literal with 1 significant space)
( Z$ is implicitly printed at end of program )
), apply this replacement rule:
1 2 3 4 5 6 7 U 9 10 11 12 13 14 15 M9 17 18 19 20 21 22 23 ^L 25 26 27 28 29 30
31 <U 33 34 35 36 37 38 39 gH 41 42 43 44 45 46 47 aJ 49 50 51 52 53 54 55 1b 57 58 59 60
61 62 63 ,C 65 66 67 68 69 70 71 ]; 73 74 75 76 77 78 79 [B 81 82 83 84 85 86 87 Ix 89
Получите список всех печатных символов ASCII, кроме цифр.
1, 89
Псевдослучайный выбор ::[a,b|~c%8=0|[len(!c$)|Z=Z+chr$(_r33,126|)]\Z=Z+!c$]Z=Z+@
characters from the list, allowing duplicates.
0-9
Присоединяйтесь к персонажам.