module ForbesRoute where numbers :: [Float] -> Int numbers = floor . (/ 1.6) . maximum
def numbers(n):pass- module ForbesRoute where
- numbers :: [Float] -> Int
- numbers = floor . (/ 1.6) . maximum
module ForbesRouteSpec where import Test.Hspec import ForbesRoute spec :: Spec spec = do describe "Tests" $ do it "Fixed Tests" $ do numbers [4.828032,8.04672, 16.09344] `shouldBe` 10 numbers [8.04672, 3.218688, 37.014912, 24.14016, 32.18688] `shouldBe` 23 numbers [1.609344, 3.218688, 0] `shouldBe` 2 main = hspec spec
import codewars_test as testfrom solution import numbers@test.describe("Example")def test_group():@test.it("test case")def test_case():test.assert_equals(numbers([4.828032,8.04672, 16.09344]), 10)test.assert_equals(numbers([8.04672, 3.218688, 37.014912, 24.14016, 32.18688]), 23)test.assert_equals(numbers([1.609344, 3.218688, 0]), 2)- module ForbesRouteSpec where
- import Test.Hspec
- import ForbesRoute
- spec :: Spec
- spec = do
- describe "Tests" $ do
- it "Fixed Tests" $ do
- numbers [4.828032,8.04672, 16.09344] `shouldBe` 10
- numbers [8.04672, 3.218688, 37.014912, 24.14016, 32.18688] `shouldBe` 23
- numbers [1.609344, 3.218688, 0] `shouldBe` 2
- main = hspec spec
Alternative solution
module AreThereThree where import Control.Monad (liftM2) solution :: Int -> Bool solution = (elem '3') . show
- module AreThereThree where
- import Control.Monad (liftM2)
- solution :: Int -> Bool
solution = liftM2 (&&) (/= 0) (liftM2 (||) ((== 3) . (`mod` 10)) (solution . (`div` 10)))- solution = (elem '3') . show
module AreThereThree where import Control.Monad (liftM2) solution :: Int -> Bool solution = liftM2 (&&) (/= 0) (liftM2 (||) ((== 3) . (`mod` 10)) (solution . (`div` 10)))
fn solution(x: i32) -> bool {x.to_string().chars().any(|x| x == '3')}- module AreThereThree where
- import Control.Monad (liftM2)
- solution :: Int -> Bool
- solution = liftM2 (&&) (/= 0) (liftM2 (||) ((== 3) . (`mod` 10)) (solution . (`div` 10)))
module AreThereThreeSpec where import Test.Hspec import AreThereThree spec :: Spec spec = do describe "Tests" $ do it "Fixed Tests" $ do solution 525458 `shouldBe` False solution 2222 `shouldBe` False solution 354523 `shouldBe` True main = hspec spec
// Add your tests here.// See https://doc.rust-lang.org/stable/rust-by-example/testing/unit_testing.html- module AreThereThreeSpec where
#[cfg(test)]mod tests {use super::*;- import Test.Hspec
- import AreThereThree
#[test]fn test_add() {assert_eq!(solution(525458), false);assert_eq!(solution(2222), false);assert_eq!(solution(354523), true)}}- spec :: Spec
- spec = do
- describe "Tests" $ do
- it "Fixed Tests" $ do
- solution 525458 `shouldBe` False
- solution 2222 `shouldBe` False
- solution 354523 `shouldBe` True
- main = hspec spec
module RemoveNumbers where import Data.Char (isDigit) removeNumbers :: String -> String removeNumbers = filter (not . isDigit)
import redef remove_numbers(string):return re.sub(r"[0-9]","",string)- module RemoveNumbers where
- import Data.Char (isDigit)
- removeNumbers :: String -> String
- removeNumbers = filter (not . isDigit)
module RemoveNumbersSpec where import Test.Hspec import RemoveNumbers spec :: Spec spec = do describe "Tests" $ do it "Fixed Tests" $ do removeNumbers "Hello world!" `shouldBe` "Hello world!" removeNumbers "2 times 2 is 4" `shouldBe` " times is " removeNumbers "this is the year 2021" `shouldBe` "this is the year " main = hspec spec
import codewars_test as test# TODO Write testsimport solution # or from solution import example- module RemoveNumbersSpec where
# test.assert_equals(actual, expected, [optional] message)@test.describe("Example")def test_group():@test.it("Tests")def test_case():test.assert_equals(remove_numbers("Hello world!"), "Hello world!")test.assert_equals(remove_numbers("2 times 2 is 4"), " times is ")test.assert_equals(remove_numbers("this is the year 2021"), "this is the year ")- import Test.Hspec
- import RemoveNumbers
- spec :: Spec
- spec = do
- describe "Tests" $ do
- it "Fixed Tests" $ do
- removeNumbers "Hello world!" `shouldBe` "Hello world!"
- removeNumbers "2 times 2 is 4" `shouldBe` " times is "
- removeNumbers "this is the year 2021" `shouldBe` "this is the year "
- main = hspec spec
module RemoveMarked where remove :: Eq a => [a] -> [a] -> [a] remove xs ms = filter (not . flip elem ms) xs
import java.util.Arrays;import java.util.List;import java.util.stream.Collectors;public class Kata{public static int[] Remove(int[] integerList,int[] valuesList){if (integerList==null||integerList.length<1) return new int[0];if (valuesList==null||valuesList.length<1) return integerList;List<Integer> list= Arrays.stream(valuesList).boxed().collect(Collectors.toList());return Arrays.stream(integerList).filter(i->!list.contains(i)).toArray();}}- module RemoveMarked where
- remove :: Eq a => [a] -> [a] -> [a]
- remove xs ms = filter (not . flip elem ms) xs
module RemoveMarkedSpec where import Test.Hspec import RemoveMarked spec :: Spec spec = do describe "Tests" $ do it "Fixed Tests" $ do ([1, 1, 2, 3, 1, 2, 3, 4] `remove` [1, 3]) `shouldBe` [2, 2, 4] ([1, 1, 2, 3, 1, 2 ,3 , 4, 4, 3 ,5, 6, 7, 2, 8] `remove` [1, 3, 4, 2]) `shouldBe` [5, 6 ,7 ,8] ([8, 2, 7, 2, 3, 4, 6, 5, 4, 4, 1, 2 , 3] `remove` [2, 4, 3]) `shouldBe` [8, 7, 6, 5, 1] ([] `remove` [2, 4, 3]) `shouldBe` [] ([8, 2, 7, 2, 3, 4, 6, 5, 4, 4, 1, 2 , 3] `remove` []) `shouldBe` [8, 2, 7, 2, 3, 4, 6, 5, 4, 4, 1, 2 , 3] ("abcdefgh" `remove` "cef") `shouldBe` "abdgh"
import org.junit.Test;import static org.junit.Assert.*;import org.junit.runners.JUnit4;import java.util.Arrays;- module RemoveMarkedSpec where
- import Test.Hspec
- import RemoveMarked
// TODO: Replace examples and use TDD development by writing your own testspublic class SolutionTest {@Testpublic void test1(){int[] integerList = new int[]{ 1, 1, 2, 3, 1, 2, 3, 4 };int[] valuesList = new int[]{ 1, 3 };assertTrue(Arrays.equals(new int[]{ 2, 2, 4 },Kata.Remove(integerList,valuesList)));}@Testpublic void test2(){int[] integerList = new int[]{1, 1, 2, 3, 1, 2 ,3 , 4, 4, 3 ,5, 6, 7, 2, 8 };int[] valuesList = new int[]{1, 3, 4, 2 };assertTrue(Arrays.equals(new int[]{ 5, 6 ,7 ,8 },Kata.Remove(integerList,valuesList)));}@Testpublic void test3(){int[] integerList = new int[]{8, 2, 7, 2, 3, 4, 6, 5, 4, 4, 1, 2 , 3 };int[] valuesList = new int[]{2, 4, 3 };assertTrue(Arrays.equals(new int[]{ 8, 7, 6, 5, 1 },Kata.Remove(integerList,valuesList)));}@Testpublic void nullTest1(){int[] integerList = null;int[] valuesList = new int[]{2, 4, 3 };assertTrue(Arrays.equals(new int[]{},Kata.Remove(integerList,valuesList)));}@Testpublic void nullTest2(){int[] integerList = new int[]{8, 2, 7, 2, 3, 4, 6, 5, 4, 4, 1, 2 , 3 };int[] valuesList = null;assertTrue(Arrays.equals(new int[]{8, 2, 7, 2, 3, 4, 6, 5, 4, 4, 1, 2 , 3 },Kata.Remove(integerList,valuesList)));}}- spec :: Spec
- spec = do
- describe "Tests" $ do
- it "Fixed Tests" $ do
- ([1, 1, 2, 3, 1, 2, 3, 4] `remove` [1, 3]) `shouldBe` [2, 2, 4]
- ([1, 1, 2, 3, 1, 2 ,3 , 4, 4, 3 ,5, 6, 7, 2, 8] `remove` [1, 3, 4, 2]) `shouldBe` [5, 6 ,7 ,8]
- ([8, 2, 7, 2, 3, 4, 6, 5, 4, 4, 1, 2 , 3] `remove` [2, 4, 3]) `shouldBe` [8, 7, 6, 5, 1]
- ([] `remove` [2, 4, 3]) `shouldBe` []
- ([8, 2, 7, 2, 3, 4, 6, 5, 4, 4, 1, 2 , 3] `remove` []) `shouldBe` [8, 2, 7, 2, 3, 4, 6, 5, 4, 4, 1, 2 , 3]
- ("abcdefgh" `remove` "cef") `shouldBe` "abdgh"
Fundamentals
Strings
Data Types
Algorithms
Logic
Functional Programming
Declarative Programming
Programming Paradigms
Higher-order Functions
Functions
Control Flow
Basic Language Features
Haskell solution which works for lists of any type implementing Eq typeclass
module Palindrome where palindrome :: Eq a => [a] -> Bool palindrome = (==) <*> reverse
def palindrome(word):if word[::-1] == word:return Trueelse:return False- module Palindrome where
- palindrome :: Eq a => [a] -> Bool
- palindrome = (==) <*> reverse
module PalindromeSpec where import Test.Hspec import Palindrome spec :: Spec spec = do describe "Tests" $ do it "Fixed Tests" $ do palindrome "A" `shouldBe` True palindrome "a" `shouldBe` True palindrome "aa" `shouldBe` True palindrome "aba" `shouldBe` True palindrome "acca" `shouldBe` True palindrome "adda" `shouldBe` True palindrome "affa" `shouldBe` True palindrome "aga" `shouldBe` True palindrome "aha" `shouldBe` True palindrome "ajaja" `shouldBe` True palindrome "aka" `shouldBe` True palindrome "ala" `shouldBe` True palindrome "alala" `shouldBe` True palindrome "alula" `shouldBe` True palindrome "ama" `shouldBe` True palindrome "amma" `shouldBe` True palindrome "ana" `shouldBe` True palindrome "anana" `shouldBe` True palindrome "anna" `shouldBe` True palindrome "apa" `shouldBe` True palindrome "ara" `shouldBe` True palindrome "arara" `shouldBe` True palindrome "atta" `shouldBe` True palindrome "ava" `shouldBe` True palindrome "awa" `shouldBe` True palindrome "B" `shouldBe` True palindrome "b" `shouldBe` True palindrome "bib" `shouldBe` True palindrome "bob" `shouldBe` True palindrome "boob" `shouldBe` True palindrome "bub" `shouldBe` True palindrome "C" `shouldBe` True palindrome "c" `shouldBe` True palindrome "civic" `shouldBe` True palindrome "D" `shouldBe` True palindrome "d" `shouldBe` True palindrome "dad" `shouldBe` True palindrome "deed" `shouldBe` True palindrome "deedeed" `shouldBe` True palindrome "degged" `shouldBe` True palindrome "did" `shouldBe` True palindrome "dod" `shouldBe` True palindrome "dud" `shouldBe` True palindrome "E" `shouldBe` True palindrome "e" `shouldBe` True palindrome "eke" `shouldBe` True palindrome "elle" `shouldBe` True palindrome "eme" `shouldBe` True palindrome "ere" `shouldBe` True palindrome "eve" `shouldBe` True palindrome "ewe" `shouldBe` True palindrome "eye" `shouldBe` True palindrome "F" `shouldBe` True palindrome "f" `shouldBe` True palindrome "G" `shouldBe` True palindrome "g" `shouldBe` True palindrome "gag" `shouldBe` True palindrome "gig" `shouldBe` True palindrome "gog" `shouldBe` True palindrome "H" `shouldBe` True palindrome "h" `shouldBe` True palindrome "hah" `shouldBe` True palindrome "hallah" `shouldBe` True palindrome "huh" `shouldBe` True palindrome "I" `shouldBe` True palindrome "i" `shouldBe` True palindrome "ihi" `shouldBe` True palindrome "imi" `shouldBe` True palindrome "immi" `shouldBe` True palindrome "J" `shouldBe` True palindrome "j" `shouldBe` True palindrome "K" `shouldBe` True palindrome "k" `shouldBe` True palindrome "kakkak" `shouldBe` True palindrome "kayak" `shouldBe` True palindrome "keek" `shouldBe` True palindrome "kelek" `shouldBe` True palindrome "L" `shouldBe` True palindrome "l" `shouldBe` True palindrome "lemel" `shouldBe` True palindrome "level" `shouldBe` True palindrome "M" `shouldBe` True palindrome "m" `shouldBe` True palindrome "maam" `shouldBe` True palindrome "madam" `shouldBe` True palindrome "mem" `shouldBe` True palindrome "mesem" `shouldBe` True palindrome "mim" `shouldBe` True palindrome "minim" `shouldBe` True palindrome "mum" `shouldBe` True palindrome "murdrum" `shouldBe` True palindrome "N" `shouldBe` True palindrome "n" `shouldBe` True palindrome "nan" `shouldBe` True palindrome "non" `shouldBe` True palindrome "noon" `shouldBe` True palindrome "nun" `shouldBe` True palindrome "O" `shouldBe` True palindrome "o" `shouldBe` True palindrome "oho" `shouldBe` True palindrome "otto" `shouldBe` True palindrome "P" `shouldBe` True palindrome "p" `shouldBe` True palindrome "pap" `shouldBe` True palindrome "peep" `shouldBe` True palindrome "pep" `shouldBe` True palindrome "pip" `shouldBe` True palindrome "poop" `shouldBe` True palindrome "pop" `shouldBe` True palindrome "pup" `shouldBe` True palindrome "Q" `shouldBe` True palindrome "q" `shouldBe` True palindrome "R" `shouldBe` True palindrome "r" `shouldBe` True palindrome "radar" `shouldBe` True palindrome "redder" `shouldBe` True palindrome "refer" `shouldBe` True palindrome "repaper" `shouldBe` True palindrome "retter" `shouldBe` True palindrome "rever" `shouldBe` True palindrome "reviver" `shouldBe` True palindrome "rotator" `shouldBe` True palindrome "rotor" `shouldBe` True palindrome "S" `shouldBe` True palindrome "s" `shouldBe` True palindrome "siris" `shouldBe` True palindrome "sis" `shouldBe` True palindrome "sooloos" `shouldBe` True palindrome "T" `shouldBe` True palindrome "t" `shouldBe` True palindrome "tat" `shouldBe` True palindrome "tebbet" `shouldBe` True palindrome "teet" `shouldBe` True palindrome "tenet" `shouldBe` True palindrome "terret" `shouldBe` True palindrome "tit" `shouldBe` True palindrome "toot" `shouldBe` True palindrome "tot" `shouldBe` True palindrome "tst" `shouldBe` True palindrome "tut" `shouldBe` True palindrome "tyt" `shouldBe` True palindrome "U" `shouldBe` True palindrome "u" `shouldBe` True palindrome "ulu" `shouldBe` True palindrome "ululu" `shouldBe` True palindrome "umu" `shouldBe` True palindrome "utu" `shouldBe` True palindrome "V" `shouldBe` True palindrome "v" `shouldBe` True palindrome "W" `shouldBe` True palindrome "w" `shouldBe` True palindrome "waw" `shouldBe` True palindrome "wow" `shouldBe` True palindrome "X" `shouldBe` True palindrome "x" `shouldBe` True palindrome "Y" `shouldBe` True palindrome "y" `shouldBe` True palindrome "yaray" `shouldBe` True palindrome "yoy" `shouldBe` True palindrome "Z" `shouldBe` True palindrome "z" `shouldBe` True palindrome "Absence" `shouldBe` False palindrome "Justify" `shouldBe` False palindrome "Academic" `shouldBe` False palindrome "kitchen" `shouldBe` False palindrome "Accompany" `shouldBe` False palindrome "knee" `shouldBe` False palindrome "Accomplish" `shouldBe` False palindrome "knife" `shouldBe` False palindrome "Acknowledge" `shouldBe` False palindrome "knock" `shouldBe` False palindrome "Adapt" `shouldBe` False palindrome "know" `shouldBe` False palindrome "Administration" `shouldBe` False palindrome "Knowledge" `shouldBe` False palindrome "Affect" `shouldBe` False palindrome "land" `shouldBe` False palindrome "Afford " `shouldBe` False palindrome "landscape" `shouldBe` False palindrome "Analysis" `shouldBe` False palindrome "language" `shouldBe` False palindrome "Apparently" `shouldBe` False palindrome "lap" `shouldBe` False palindrome "Background" `shouldBe` False palindrome "large" `shouldBe` False palindrome "Balance" `shouldBe` False palindrome "largely" `shouldBe` False palindrome "Besides" `shouldBe` False palindrome "Last" `shouldBe` False palindrome "Beside" `shouldBe` False palindrome "manufacturing" `shouldBe` False palindrome "Beyond" `shouldBe` False palindrome "many" `shouldBe` False palindrome "Borrow" `shouldBe` False palindrome "map" `shouldBe` False palindrome "Boundary" `shouldBe` False palindrome "margin" `shouldBe` False palindrome "Budget" `shouldBe` False palindrome "mark" `shouldBe` False palindrome "Building" `shouldBe` False palindrome "market" `shouldBe` False palindrome "Business" `shouldBe` False palindrome "Marketing" `shouldBe` False palindrome "Calculate" `shouldBe` False palindrome "negotiation" `shouldBe` False palindrome "Campaign" `shouldBe` False palindrome "neighbor" `shouldBe` False palindrome "Campus" `shouldBe` False palindrome "neighborhood" `shouldBe` False palindrome "Capability" `shouldBe` False palindrome "neither" `shouldBe` False palindrome "Capacity" `shouldBe` False palindrome "Nerve" `shouldBe` False palindrome "Category" `shouldBe` False palindrome "objective" `shouldBe` False palindrome "Challenge" `shouldBe` False palindrome "obligation" `shouldBe` False palindrome "Characteristic" `shouldBe` False palindrome "observation" `shouldBe` False palindrome "Civil" `shouldBe` False palindrome "Observe" `shouldBe` False palindrome "Coalition" `shouldBe` False palindrome "opportunity" `shouldBe` False palindrome "Colonial" `shouldBe` False palindrome "Oppose" `shouldBe` False palindrome "Deal" `shouldBe` False palindrome "porch" `shouldBe` False palindrome "Defensive" `shouldBe` False palindrome "port" `shouldBe` False palindrome "Democracy" `shouldBe` False palindrome "portion" `shouldBe` False palindrome "Description" `shouldBe` False palindrome "portrait" `shouldBe` False palindrome "Dialogue" `shouldBe` False palindrome "portray" `shouldBe` False palindrome "Dimension" `shouldBe` False palindrome "pose" `shouldBe` False palindrome "Discrimination" `shouldBe` False palindrome "Position" `shouldBe` False palindrome "Distinction" `shouldBe` False palindrome "qualify" `shouldBe` False palindrome "Distinguish" `shouldBe` False palindrome "quality" `shouldBe` False palindrome "elementary" `shouldBe` False palindrome "Quarter" `shouldBe` False palindrome "eliminate" `shouldBe` False palindrome "quit" `shouldBe` False palindrome "elite" `shouldBe` False palindrome "quite" `shouldBe` False palindrome "else" `shouldBe` False palindrome "Quote" `shouldBe` False palindrome "elsewhere" `shouldBe` False palindrome "recipe" `shouldBe` False palindrome "e-mail" `shouldBe` False palindrome "Recognition" `shouldBe` False palindrome "embrace" `shouldBe` False palindrome "refugee" `shouldBe` False palindrome [1, 2, 3, 2, 1] `shouldBe` True palindrome [1, 2, 3] `shouldBe` False palindrome ["ab", "cd", "cd", "ab"] `shouldBe` True palindrome ["ab", "ba"] `shouldBe` False main = hspec spec
test.assert_equals(palindrome('A'), True)test.assert_equals(palindrome('a'), True)test.assert_equals(palindrome('aa'), True)test.assert_equals(palindrome('aba'), True)test.assert_equals(palindrome('acca'), True)test.assert_equals(palindrome('adda'), True)test.assert_equals(palindrome('affa'), True)test.assert_equals(palindrome('aga'), True)test.assert_equals(palindrome('aha'), True)test.assert_equals(palindrome('ajaja'), True)test.assert_equals(palindrome('aka'), True)test.assert_equals(palindrome('ala'), True)test.assert_equals(palindrome('alala'), True)test.assert_equals(palindrome('alula'), True)test.assert_equals(palindrome('ama'), True)test.assert_equals(palindrome('amma'), True)test.assert_equals(palindrome('ana'), True)test.assert_equals(palindrome('anana'), True)test.assert_equals(palindrome('anna'), True)test.assert_equals(palindrome('apa'), True)test.assert_equals(palindrome('ara'), True)test.assert_equals(palindrome('arara'), True)test.assert_equals(palindrome('atta'), True)test.assert_equals(palindrome('ava'), True)test.assert_equals(palindrome('awa'), True)test.assert_equals(palindrome('B'), True)test.assert_equals(palindrome('b'), True)test.assert_equals(palindrome('bib'), True)test.assert_equals(palindrome('bob'), True)test.assert_equals(palindrome('boob'), True)test.assert_equals(palindrome('bub'), True)test.assert_equals(palindrome('C'), True)test.assert_equals(palindrome('c'), True)test.assert_equals(palindrome('civic'), True)test.assert_equals(palindrome('D'), True)test.assert_equals(palindrome('d'), True)test.assert_equals(palindrome('dad'), True)test.assert_equals(palindrome('deed'), True)test.assert_equals(palindrome('deedeed'), True)test.assert_equals(palindrome('degged'), True)test.assert_equals(palindrome('did'), True)test.assert_equals(palindrome('dod'), True)test.assert_equals(palindrome('dud'), True)test.assert_equals(palindrome('E'), True)test.assert_equals(palindrome('e'), True)test.assert_equals(palindrome('eke'), True)test.assert_equals(palindrome('elle'), True)test.assert_equals(palindrome('eme'), True)test.assert_equals(palindrome('ere'), True)test.assert_equals(palindrome('eve'), True)test.assert_equals(palindrome('ewe'), True)test.assert_equals(palindrome('eye'), True)test.assert_equals(palindrome('F'), True)test.assert_equals(palindrome('f'), True)test.assert_equals(palindrome('G'), True)test.assert_equals(palindrome('g'), True)test.assert_equals(palindrome('gag'), True)test.assert_equals(palindrome('gig'), True)test.assert_equals(palindrome('gog'), True)test.assert_equals(palindrome('H'), True)test.assert_equals(palindrome('h'), True)test.assert_equals(palindrome('hah'), True)test.assert_equals(palindrome('hallah'), True)test.assert_equals(palindrome('huh'), True)test.assert_equals(palindrome('I'), True)test.assert_equals(palindrome('i'), True)test.assert_equals(palindrome('ihi'), True)test.assert_equals(palindrome('imi'), True)test.assert_equals(palindrome('immi'), True)test.assert_equals(palindrome('J'), True)test.assert_equals(palindrome('j'), True)test.assert_equals(palindrome('K'), True)test.assert_equals(palindrome('k'), True)test.assert_equals(palindrome('kakkak'), True)test.assert_equals(palindrome('kayak'), True)test.assert_equals(palindrome('keek'), True)test.assert_equals(palindrome('kelek'), True)test.assert_equals(palindrome('L'), True)test.assert_equals(palindrome('l'), True)test.assert_equals(palindrome('lemel'), True)test.assert_equals(palindrome('level'), True)test.assert_equals(palindrome('M'), True)test.assert_equals(palindrome('m'), True)test.assert_equals(palindrome('maam'), True)test.assert_equals(palindrome('madam'), True)test.assert_equals(palindrome('mem'), True)test.assert_equals(palindrome('mesem'), True)test.assert_equals(palindrome('mim'), True)test.assert_equals(palindrome('minim'), True)test.assert_equals(palindrome('mum'), True)test.assert_equals(palindrome('murdrum'), True)test.assert_equals(palindrome('N'), True)test.assert_equals(palindrome('n'), True)test.assert_equals(palindrome('nan'), True)test.assert_equals(palindrome('non'), True)test.assert_equals(palindrome('noon'), True)test.assert_equals(palindrome('nun'), True)test.assert_equals(palindrome('O'), True)test.assert_equals(palindrome('o'), True)test.assert_equals(palindrome('oho'), True)test.assert_equals(palindrome('otto'), True)test.assert_equals(palindrome('P'), True)test.assert_equals(palindrome('p'), True)test.assert_equals(palindrome('pap'), True)test.assert_equals(palindrome('peep'), True)test.assert_equals(palindrome('pep'), True)test.assert_equals(palindrome('pip'), True)test.assert_equals(palindrome('poop'), True)test.assert_equals(palindrome('pop'), True)test.assert_equals(palindrome('pup'), True)test.assert_equals(palindrome('Q'), True)test.assert_equals(palindrome('q'), True)test.assert_equals(palindrome('R'), True)test.assert_equals(palindrome('r'), True)test.assert_equals(palindrome('radar'), True)test.assert_equals(palindrome('redder'), True)test.assert_equals(palindrome('refer'), True)test.assert_equals(palindrome('repaper'), True)test.assert_equals(palindrome('retter'), True)test.assert_equals(palindrome('rever'), True)test.assert_equals(palindrome('reviver'), True)test.assert_equals(palindrome('rotator'), True)test.assert_equals(palindrome('rotor'), True)test.assert_equals(palindrome('S'), True)test.assert_equals(palindrome('s'), True)test.assert_equals(palindrome('siris'), True)test.assert_equals(palindrome('sis'), True)test.assert_equals(palindrome('sooloos'), True)test.assert_equals(palindrome('T'), True)test.assert_equals(palindrome('t'), True)test.assert_equals(palindrome('tat'), True)test.assert_equals(palindrome('tebbet'), True)test.assert_equals(palindrome('teet'), True)test.assert_equals(palindrome('tenet'), True)test.assert_equals(palindrome('terret'), True)test.assert_equals(palindrome('tit'), True)test.assert_equals(palindrome('toot'), True)test.assert_equals(palindrome('tot'), True)test.assert_equals(palindrome('tst'), True)test.assert_equals(palindrome('tut'), True)test.assert_equals(palindrome('tyt'), True)test.assert_equals(palindrome('U'), True)test.assert_equals(palindrome('u'), True)test.assert_equals(palindrome('ulu'), True)test.assert_equals(palindrome('ululu'), True)test.assert_equals(palindrome('umu'), True)test.assert_equals(palindrome('utu'), True)test.assert_equals(palindrome('V'), True)test.assert_equals(palindrome('v'), True)test.assert_equals(palindrome('W'), True)test.assert_equals(palindrome('w'), True)test.assert_equals(palindrome('waw'), True)test.assert_equals(palindrome('wow'), True)test.assert_equals(palindrome('X'), True)test.assert_equals(palindrome('x'), True)test.assert_equals(palindrome('Y'), True)test.assert_equals(palindrome('y'), True)test.assert_equals(palindrome('yaray'), True)test.assert_equals(palindrome('yoy'), True)test.assert_equals(palindrome('Z'), True)test.assert_equals(palindrome('z'), True)test.assert_equals(palindrome('Absence'), False)test.assert_equals(palindrome('Justify'), False)test.assert_equals(palindrome('Academic'), False)test.assert_equals(palindrome('kitchen'), False)test.assert_equals(palindrome('Accompany'), False)test.assert_equals(palindrome('knee'), False)test.assert_equals(palindrome('Accomplish'), False)test.assert_equals(palindrome('knife'), False)test.assert_equals(palindrome('Acknowledge'), False)test.assert_equals(palindrome('knock'), False)test.assert_equals(palindrome('Adapt'), False)test.assert_equals(palindrome('know'), False)test.assert_equals(palindrome('Administration'), False)test.assert_equals(palindrome('Knowledge'), False)test.assert_equals(palindrome('Affect'), False)test.assert_equals(palindrome('land'), False)test.assert_equals(palindrome('Afford '), False)test.assert_equals(palindrome('landscape'), False)test.assert_equals(palindrome('Analysis'), False)test.assert_equals(palindrome('language'), False)test.assert_equals(palindrome('Apparently'), False)test.assert_equals(palindrome('lap'), False)test.assert_equals(palindrome('Background'), False)test.assert_equals(palindrome('large'), False)test.assert_equals(palindrome('Balance'), False)test.assert_equals(palindrome('largely'), False)test.assert_equals(palindrome('Besides'), False)test.assert_equals(palindrome('Last'), False)test.assert_equals(palindrome('Beside'), False)test.assert_equals(palindrome('manufacturing'), False)test.assert_equals(palindrome('Beyond'), False)test.assert_equals(palindrome('many'), False)test.assert_equals(palindrome('Borrow'), False)test.assert_equals(palindrome('map'), False)test.assert_equals(palindrome('Boundary'), False)test.assert_equals(palindrome('margin'), False)test.assert_equals(palindrome('Budget'), False)test.assert_equals(palindrome('mark'), False)test.assert_equals(palindrome('Building'), False)test.assert_equals(palindrome('market'), False)test.assert_equals(palindrome('Business'), False)test.assert_equals(palindrome('Marketing'), False)test.assert_equals(palindrome('Calculate'), False)test.assert_equals(palindrome('negotiation'), False)test.assert_equals(palindrome('Campaign'), False)test.assert_equals(palindrome('neighbor'), False)test.assert_equals(palindrome('Campus'), False)test.assert_equals(palindrome('neighborhood'), False)test.assert_equals(palindrome('Capability'), False)test.assert_equals(palindrome('neither'), False)test.assert_equals(palindrome('Capacity'), False)test.assert_equals(palindrome('Nerve'), False)test.assert_equals(palindrome('Category'), False)test.assert_equals(palindrome('objective'), False)test.assert_equals(palindrome('Challenge'), False)test.assert_equals(palindrome('obligation'), False)test.assert_equals(palindrome('Characteristic'), False)test.assert_equals(palindrome('observation'), False)test.assert_equals(palindrome('Civil'), False)test.assert_equals(palindrome('Observe'), False)test.assert_equals(palindrome('Coalition'), False)test.assert_equals(palindrome('opportunity'), False)test.assert_equals(palindrome('Colonial'), False)test.assert_equals(palindrome('Oppose'), False)test.assert_equals(palindrome('Deal'), False)test.assert_equals(palindrome('porch'), False)test.assert_equals(palindrome('Defensive'), False)test.assert_equals(palindrome('port'), False)test.assert_equals(palindrome('Democracy'), False)test.assert_equals(palindrome('portion'), False)test.assert_equals(palindrome('Description'), False)test.assert_equals(palindrome('portrait'), False)test.assert_equals(palindrome('Dialogue'), False)test.assert_equals(palindrome('portray'), False)test.assert_equals(palindrome('Dimension'), False)test.assert_equals(palindrome('pose'), False)test.assert_equals(palindrome('Discrimination'), False)test.assert_equals(palindrome('Position'), False)test.assert_equals(palindrome('Distinction'), False)test.assert_equals(palindrome('qualify'), False)test.assert_equals(palindrome('Distinguish'), False)test.assert_equals(palindrome('quality'), False)test.assert_equals(palindrome('elementary'), False)test.assert_equals(palindrome('Quarter'), False)test.assert_equals(palindrome('eliminate'), False)test.assert_equals(palindrome('quit'), False)test.assert_equals(palindrome('elite'), False)test.assert_equals(palindrome('quite'), False)test.assert_equals(palindrome('else'), False)test.assert_equals(palindrome('Quote'), False)test.assert_equals(palindrome('elsewhere'), False)test.assert_equals(palindrome('recipe'), False)test.assert_equals(palindrome('e-mail'), False)test.assert_equals(palindrome('Recognition'), False)test.assert_equals(palindrome('embrace'), False)test.assert_equals(palindrome('refugee'), False)- module PalindromeSpec where
- import Test.Hspec
- import Palindrome
- spec :: Spec
- spec = do
- describe "Tests" $ do
- it "Fixed Tests" $ do
- palindrome "A" `shouldBe` True
- palindrome "a" `shouldBe` True
- palindrome "aa" `shouldBe` True
- palindrome "aba" `shouldBe` True
- palindrome "acca" `shouldBe` True
- palindrome "adda" `shouldBe` True
- palindrome "affa" `shouldBe` True
- palindrome "aga" `shouldBe` True
- palindrome "aha" `shouldBe` True
- palindrome "ajaja" `shouldBe` True
- palindrome "aka" `shouldBe` True
- palindrome "ala" `shouldBe` True
- palindrome "alala" `shouldBe` True
- palindrome "alula" `shouldBe` True
- palindrome "ama" `shouldBe` True
- palindrome "amma" `shouldBe` True
- palindrome "ana" `shouldBe` True
- palindrome "anana" `shouldBe` True
- palindrome "anna" `shouldBe` True
- palindrome "apa" `shouldBe` True
- palindrome "ara" `shouldBe` True
- palindrome "arara" `shouldBe` True
- palindrome "atta" `shouldBe` True
- palindrome "ava" `shouldBe` True
- palindrome "awa" `shouldBe` True
- palindrome "B" `shouldBe` True
- palindrome "b" `shouldBe` True
- palindrome "bib" `shouldBe` True
- palindrome "bob" `shouldBe` True
- palindrome "boob" `shouldBe` True
- palindrome "bub" `shouldBe` True
- palindrome "C" `shouldBe` True
- palindrome "c" `shouldBe` True
- palindrome "civic" `shouldBe` True
- palindrome "D" `shouldBe` True
- palindrome "d" `shouldBe` True
- palindrome "dad" `shouldBe` True
- palindrome "deed" `shouldBe` True
- palindrome "deedeed" `shouldBe` True
- palindrome "degged" `shouldBe` True
- palindrome "did" `shouldBe` True
- palindrome "dod" `shouldBe` True
- palindrome "dud" `shouldBe` True
- palindrome "E" `shouldBe` True
- palindrome "e" `shouldBe` True
- palindrome "eke" `shouldBe` True
- palindrome "elle" `shouldBe` True
- palindrome "eme" `shouldBe` True
- palindrome "ere" `shouldBe` True
- palindrome "eve" `shouldBe` True
- palindrome "ewe" `shouldBe` True
- palindrome "eye" `shouldBe` True
- palindrome "F" `shouldBe` True
- palindrome "f" `shouldBe` True
- palindrome "G" `shouldBe` True
- palindrome "g" `shouldBe` True
- palindrome "gag" `shouldBe` True
- palindrome "gig" `shouldBe` True
- palindrome "gog" `shouldBe` True
- palindrome "H" `shouldBe` True
- palindrome "h" `shouldBe` True
- palindrome "hah" `shouldBe` True
- palindrome "hallah" `shouldBe` True
- palindrome "huh" `shouldBe` True
- palindrome "I" `shouldBe` True
- palindrome "i" `shouldBe` True
- palindrome "ihi" `shouldBe` True
- palindrome "imi" `shouldBe` True
- palindrome "immi" `shouldBe` True
- palindrome "J" `shouldBe` True
- palindrome "j" `shouldBe` True
- palindrome "K" `shouldBe` True
- palindrome "k" `shouldBe` True
- palindrome "kakkak" `shouldBe` True
- palindrome "kayak" `shouldBe` True
- palindrome "keek" `shouldBe` True
- palindrome "kelek" `shouldBe` True
- palindrome "L" `shouldBe` True
- palindrome "l" `shouldBe` True
- palindrome "lemel" `shouldBe` True
- palindrome "level" `shouldBe` True
- palindrome "M" `shouldBe` True
- palindrome "m" `shouldBe` True
- palindrome "maam" `shouldBe` True
- palindrome "madam" `shouldBe` True
- palindrome "mem" `shouldBe` True
- palindrome "mesem" `shouldBe` True
- palindrome "mim" `shouldBe` True
- palindrome "minim" `shouldBe` True
- palindrome "mum" `shouldBe` True
- palindrome "murdrum" `shouldBe` True
- palindrome "N" `shouldBe` True
- palindrome "n" `shouldBe` True
- palindrome "nan" `shouldBe` True
- palindrome "non" `shouldBe` True
- palindrome "noon" `shouldBe` True
- palindrome "nun" `shouldBe` True
- palindrome "O" `shouldBe` True
- palindrome "o" `shouldBe` True
- palindrome "oho" `shouldBe` True
- palindrome "otto" `shouldBe` True
- palindrome "P" `shouldBe` True
- palindrome "p" `shouldBe` True
- palindrome "pap" `shouldBe` True
- palindrome "peep" `shouldBe` True
- palindrome "pep" `shouldBe` True
- palindrome "pip" `shouldBe` True
- palindrome "poop" `shouldBe` True
- palindrome "pop" `shouldBe` True
- palindrome "pup" `shouldBe` True
- palindrome "Q" `shouldBe` True
- palindrome "q" `shouldBe` True
- palindrome "R" `shouldBe` True
- palindrome "r" `shouldBe` True
- palindrome "radar" `shouldBe` True
- palindrome "redder" `shouldBe` True
- palindrome "refer" `shouldBe` True
- palindrome "repaper" `shouldBe` True
- palindrome "retter" `shouldBe` True
- palindrome "rever" `shouldBe` True
- palindrome "reviver" `shouldBe` True
- palindrome "rotator" `shouldBe` True
- palindrome "rotor" `shouldBe` True
- palindrome "S" `shouldBe` True
- palindrome "s" `shouldBe` True
- palindrome "siris" `shouldBe` True
- palindrome "sis" `shouldBe` True
- palindrome "sooloos" `shouldBe` True
- palindrome "T" `shouldBe` True
- palindrome "t" `shouldBe` True
- palindrome "tat" `shouldBe` True
- palindrome "tebbet" `shouldBe` True
- palindrome "teet" `shouldBe` True
- palindrome "tenet" `shouldBe` True
- palindrome "terret" `shouldBe` True
- palindrome "tit" `shouldBe` True
- palindrome "toot" `shouldBe` True
- palindrome "tot" `shouldBe` True
- palindrome "tst" `shouldBe` True
- palindrome "tut" `shouldBe` True
- palindrome "tyt" `shouldBe` True
- palindrome "U" `shouldBe` True
- palindrome "u" `shouldBe` True
- palindrome "ulu" `shouldBe` True
- palindrome "ululu" `shouldBe` True
- palindrome "umu" `shouldBe` True
- palindrome "utu" `shouldBe` True
- palindrome "V" `shouldBe` True
- palindrome "v" `shouldBe` True
- palindrome "W" `shouldBe` True
- palindrome "w" `shouldBe` True
- palindrome "waw" `shouldBe` True
- palindrome "wow" `shouldBe` True
- palindrome "X" `shouldBe` True
- palindrome "x" `shouldBe` True
- palindrome "Y" `shouldBe` True
- palindrome "y" `shouldBe` True
- palindrome "yaray" `shouldBe` True
- palindrome "yoy" `shouldBe` True
- palindrome "Z" `shouldBe` True
- palindrome "z" `shouldBe` True
- palindrome "Absence" `shouldBe` False
- palindrome "Justify" `shouldBe` False
- palindrome "Academic" `shouldBe` False
- palindrome "kitchen" `shouldBe` False
- palindrome "Accompany" `shouldBe` False
- palindrome "knee" `shouldBe` False
- palindrome "Accomplish" `shouldBe` False
- palindrome "knife" `shouldBe` False
- palindrome "Acknowledge" `shouldBe` False
- palindrome "knock" `shouldBe` False
- palindrome "Adapt" `shouldBe` False
- palindrome "know" `shouldBe` False
- palindrome "Administration" `shouldBe` False
- palindrome "Knowledge" `shouldBe` False
- palindrome "Affect" `shouldBe` False
- palindrome "land" `shouldBe` False
- palindrome "Afford " `shouldBe` False
- palindrome "landscape" `shouldBe` False
- palindrome "Analysis" `shouldBe` False
- palindrome "language" `shouldBe` False
- palindrome "Apparently" `shouldBe` False
- palindrome "lap" `shouldBe` False
- palindrome "Background" `shouldBe` False
- palindrome "large" `shouldBe` False
- palindrome "Balance" `shouldBe` False
- palindrome "largely" `shouldBe` False
- palindrome "Besides" `shouldBe` False
- palindrome "Last" `shouldBe` False
- palindrome "Beside" `shouldBe` False
- palindrome "manufacturing" `shouldBe` False
- palindrome "Beyond" `shouldBe` False
- palindrome "many" `shouldBe` False
- palindrome "Borrow" `shouldBe` False
- palindrome "map" `shouldBe` False
- palindrome "Boundary" `shouldBe` False
- palindrome "margin" `shouldBe` False
- palindrome "Budget" `shouldBe` False
- palindrome "mark" `shouldBe` False
- palindrome "Building" `shouldBe` False
- palindrome "market" `shouldBe` False
- palindrome "Business" `shouldBe` False
- palindrome "Marketing" `shouldBe` False
- palindrome "Calculate" `shouldBe` False
- palindrome "negotiation" `shouldBe` False
- palindrome "Campaign" `shouldBe` False
- palindrome "neighbor" `shouldBe` False
- palindrome "Campus" `shouldBe` False
- palindrome "neighborhood" `shouldBe` False
- palindrome "Capability" `shouldBe` False
- palindrome "neither" `shouldBe` False
- palindrome "Capacity" `shouldBe` False
- palindrome "Nerve" `shouldBe` False
- palindrome "Category" `shouldBe` False
- palindrome "objective" `shouldBe` False
- palindrome "Challenge" `shouldBe` False
- palindrome "obligation" `shouldBe` False
- palindrome "Characteristic" `shouldBe` False
- palindrome "observation" `shouldBe` False
- palindrome "Civil" `shouldBe` False
- palindrome "Observe" `shouldBe` False
- palindrome "Coalition" `shouldBe` False
- palindrome "opportunity" `shouldBe` False
- palindrome "Colonial" `shouldBe` False
- palindrome "Oppose" `shouldBe` False
- palindrome "Deal" `shouldBe` False
- palindrome "porch" `shouldBe` False
- palindrome "Defensive" `shouldBe` False
- palindrome "port" `shouldBe` False
- palindrome "Democracy" `shouldBe` False
- palindrome "portion" `shouldBe` False
- palindrome "Description" `shouldBe` False
- palindrome "portrait" `shouldBe` False
- palindrome "Dialogue" `shouldBe` False
- palindrome "portray" `shouldBe` False
- palindrome "Dimension" `shouldBe` False
- palindrome "pose" `shouldBe` False
- palindrome "Discrimination" `shouldBe` False
- palindrome "Position" `shouldBe` False
- palindrome "Distinction" `shouldBe` False
- palindrome "qualify" `shouldBe` False
- palindrome "Distinguish" `shouldBe` False
- palindrome "quality" `shouldBe` False
- palindrome "elementary" `shouldBe` False
- palindrome "Quarter" `shouldBe` False
- palindrome "eliminate" `shouldBe` False
- palindrome "quit" `shouldBe` False
- palindrome "elite" `shouldBe` False
- palindrome "quite" `shouldBe` False
- palindrome "else" `shouldBe` False
- palindrome "Quote" `shouldBe` False
- palindrome "elsewhere" `shouldBe` False
- palindrome "recipe" `shouldBe` False
- palindrome "e-mail" `shouldBe` False
- palindrome "Recognition" `shouldBe` False
- palindrome "embrace" `shouldBe` False
- palindrome "refugee" `shouldBe` False
- palindrome [1, 2, 3, 2, 1] `shouldBe` True
- palindrome [1, 2, 3] `shouldBe` False
- palindrome ["ab", "cd", "cd", "ab"] `shouldBe` True
- palindrome ["ab", "ba"] `shouldBe` False
- main = hspec spec
Fundamentals
Functional Programming
Declarative Programming
Programming Paradigms
Higher-order Functions
Functions
Control Flow
Basic Language Features
Haskell one-liner
module NumberPrint where numberprint :: Int -> Integer numberprint = read . (>>= id) . ((++) <*> (reverse . init)) . (\x -> show <$> [1..x])
numberprint=lambda x:int(''.join(map(str,__import__("itertools").chain((m:=range(1, x + 1)),m[-2::-1]))))- module NumberPrint where
- numberprint :: Int -> Integer
- numberprint = read . (>>= id) . ((++) <*> (reverse . init)) . (\x -> show <$> [1..x])
module NumberPrintSpec where import Test.Hspec import NumberPrint spec :: Spec spec = do describe "Tests" $ do it "Fixed Tests" $ do numberprint 1 `shouldBe` 1 numberprint 2 `shouldBe` 121 numberprint 10 `shouldBe` 12345678910987654321 main = hspec spec
import codewars_test as testfrom solution import numberprint- module NumberPrintSpec where
@test.describe("Fixed Tests")def basic_tests():@test.it("Fixed tests")def fixed_tests():test.assert_equals(numberprint(1), 1)test.assert_equals(numberprint(2), 121)test.assert_equals(numberprint(10), 12345678910987654321)- import Test.Hspec
- import NumberPrint
- spec :: Spec
- spec = do
- describe "Tests" $ do
- it "Fixed Tests" $ do
- numberprint 1 `shouldBe` 1
- numberprint 2 `shouldBe` 121
- numberprint 10 `shouldBe` 12345678910987654321
- main = hspec spec