Source

7li7w / Haskell / day2.hs

Full commit
module Main where

import Data.List
import Char

-- Takes a list and returns a sorted list
mySort aList = sort aList

-- Takes a list and a function that compares its 2 arguments and the
-- returns a sorted list

mySortBy aFunction aList = (sortBy aFunction aList)

myInverseCompare a b |  a > b = LT
                     | otherwise = GT
                            
oddFirstCompare a b  | odd a = LT
                     | otherwise = GT
                                   
-- Convert a string of the type $2,345,678.99 to a number with
-- possibly leading zeros


toDecimal x = x/((10)^((x `mod` 10)+1))

recursiveConvert "" c l = c
recursiveConvert [a] c l = (digitToInt a)*10^l + c
recursiveConvert aString carryValue level 
  | (last aString) == ',' = recursiveConvert (init aString) carryValue level
  | (last aString) == '.' = recursiveConvert (init aString) (toDecimal carryValue) 0
  |otherwise = recursiveConvert (init aString) (((digitToInt (last aString)) * (10^level)) + carryValue) (level+1)
                            
convertToNumber aString = recursiveConvert (tail aString) 0 0