def rotateLeft(array): return [list(x) for x in zip(*array)[::-1]] def rotateRight(array): return [list(x[::-1]) for x in zip(*array)]
- def rotateLeft(array):
return [[x[-i-1] for x in array] for i in range(len(array[0]))]- return [list(x) for x in zip(*array)[::-1]]
- def rotateRight(array):
return [[x[i] for x in array][::-1] for i in range(len(array[0]))]- return [list(x[::-1]) for x in zip(*array)]
getIDS <- function(string) { sum(as.integer(unlist(strsplit(string, "")))) }
def getIDS(string):return sum(int(x) for x in string)- getIDS <- function(string) {
- sum(as.integer(unlist(strsplit(string, ""))))
- }
testing1 <- function(nb, expected) { actual <- getIDS(nb) expect_equal(actual, expected) } test_that("Basic Test", { testing1('1345', 13) testing1('1', 1) testing1('12', 3) testing1('110', 2) testing1('011', 2) }) test_that("Complex Test", { testing1('134124325', 25) testing1('13245675', 33) testing1('1908765112', 40) testing1('110000', 2) testing1('04720011', 15) }) test_that("Random Test", { s <- sample(0:9, 50 * 100, replace=T) s <- matrix(s, ncol=50, byrow=T) s <- apply( s, 1, function(x) { substr(paste(x, collapse=''), sample(1:25), 50) } ) ex <- sapply(s, function(x) {sum(as.integer(unlist(strsplit(x, ''))))}) apply(cbind(s, ex), 1, function(x) {testing1(x[1], as.integer(x[2]) )}) })
from random import randint- testing1 <- function(nb, expected) {
- actual <- getIDS(nb)
- expect_equal(actual, expected)
- }
test.describe("Basic Test")Test.assert_equals(getIDS('1345'), 13)Test.assert_equals(getIDS('1'), 1)Test.assert_equals(getIDS('12'), 3)Test.assert_equals(getIDS('110'), 2)Test.assert_equals(getIDS('011'), 2)- test_that("Basic Test", {
- testing1('1345', 13)
- testing1('1', 1)
- testing1('12', 3)
- testing1('110', 2)
- testing1('011', 2)
- })
test.describe("Complex Test")Test.assert_equals(getIDS('134124325'), 25)Test.assert_equals(getIDS('13245675'), 33)Test.assert_equals(getIDS('1908765112'), 40)Test.assert_equals(getIDS('110000'), 2)Test.assert_equals(getIDS('04720011'), 15)- test_that("Complex Test", {
- testing1('134124325', 25)
- testing1('13245675', 33)
- testing1('1908765112', 40)
- testing1('110000', 2)
- testing1('04720011', 15)
- })
test.describe("Random Test")for x in range(0, 100):string = "".join([str(randint(0, 9)) for x in range(randint(25, 50))])Test.assert_equals(getIDS(string), sum([int(x) for x in string]))- test_that("Random Test", {
- s <- sample(0:9, 50 * 100, replace=T)
- s <- matrix(s, ncol=50, byrow=T)
- s <- apply(
- s, 1,
- function(x) {
- substr(paste(x, collapse=''), sample(1:25), 50)
- }
- )
- ex <- sapply(s, function(x) {sum(as.integer(unlist(strsplit(x, ''))))})
- apply(cbind(s, ex), 1, function(x) {testing1(x[1], as.integer(x[2]) )})
- })