Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-

can anybody who knows c++ help me with this?

Name: Anonymous 2011-03-07 22:03

Write a program that initializes an array with ten random integers and then prints four lines of output containing:
-every element at an even index
-every even element
-all elements in reverse order
-only the first and last element.

Name: Anonymous 2011-03-07 22:12

Sure.

import random
xs = [random.randint(1, 100) for i in xrange(10)]
print xs[::2]
print [x for x in xs if x % 2 == 0]
print xs[::-1]
print xs[0], xs[-1]

Name: Anonymous 2011-03-07 22:29

thank you

Name: Anonymous 2011-03-07 22:34


(let* ((count 10)
       (randoms (loop repeat count collect (random #.(1- (expt 2 32)))))
       (r-array (map 'vector #'identity randoms)))
  (mapc #'(lambda (list) (format t "~{~A ~}~&" list))
        (list
         (loop for i from 0 to (1- count) by 2 collect (aref r-array i))
         (remove-if-not #'evenp randoms)
         (reverse randoms)
         (list (first randoms) (last randoms)))))

Inefficient implementation for a toy problem.

Name: Anonymous 2011-03-07 23:58

initializes an array with ten random integers
array=: 10 ?@$ 100

-every element at an even index
(2 * i. (($array) % 2)) { array

-every even element
(#~ 1 - 2&|) array

-all elements in reverse order
|. array

-only the first and last element.
({. array), {: array

Name: Anonymous 2011-03-08 0:40

>>2
print [variable for some_sequence]
print $variable for @some_sequence;


PYTHON IS PERL

Name: Anonymous 2011-03-08 0:57

>>6
The semantics are slighly different. The first statement is executed once, printing a single array, while the second statement is executed n times, printing n scalar values.

Name: Anonymous 2011-03-08 2:08

>>2

ONE WORD

Name: Anonymous 2011-03-08 4:53

>>5-6
ONE WORD: THE FORCED VALIDATION OF INDENTED PERL CODE. THREAD OVER

Don't change these.
Name: Email:
Entire Thread Thread List