Ad
Code
Diff
  • 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

Alternative solution

Code
Diff
  • 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
Code
Diff
  • 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)))
Code
Diff
  • module RemoveNumbers where
    
    import Data.Char (isDigit)
    
    removeNumbers :: String -> String
    removeNumbers = filter (not . isDigit)
    • import re
    • def remove_numbers(string):
    • return re.sub(r"[0-9]","",string)
    • module RemoveNumbers where
    • import Data.Char (isDigit)
    • removeNumbers :: String -> String
    • removeNumbers = filter (not . isDigit)
Code
Diff
  • 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
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

Code
Diff
  • module Palindrome where
    
    palindrome :: Eq a => [a] -> Bool
    palindrome = (==) <*> reverse
    • def palindrome(word):
    • if word[::-1] == word:
    • return True
    • else:
    • return False
    • module Palindrome where
    • palindrome :: Eq a => [a] -> Bool
    • palindrome = (==) <*> reverse
Fundamentals
Functional Programming
Declarative Programming
Programming Paradigms
Higher-order Functions
Functions
Control Flow
Basic Language Features

Haskell one-liner

Code
Diff
  • 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])