-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
12146cf
commit 84e9bd6
Showing
5 changed files
with
44 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,22 @@ | ||
type List; | ||
|
||
def List_size: (l:List) -> Int = uninterpreted; | ||
def List_length: (l:List) -> Int = native "lambda list: len(list)"; | ||
def List_new : {x:List | List_size(x) == 0} = native "[]" ; | ||
def List_append: (l:List) -> (i: Int) -> {l2:List | List_size(l2) == (List_size(l) + 1)} = native "lambda xs: lambda x: xs + [x]"; | ||
|
||
def sum: (l:List) -> Int = native "lambda xs: sum(xs)"; | ||
def Math_max : (i:Int) -> (j:Int) -> Int = native "lambda i: lambda j: max(i,j)" ; | ||
def Math_floor_division : (i:Int) -> (j:Int)-> Int = native "lambda i: lambda j: i // j" ; | ||
|
||
def map_Int_Int_List: (function:(a: Int) -> Int) -> (l: List) -> List = native "lambda f, xs: map(f, xs)"; | ||
def map_Int_Int_List: (function:(a: Int) -> Int) -> (l: List) -> List = native "lambda f:lambda xs: map(f, xs)"; | ||
|
||
def fuel_cost (xs: List) : Int { | ||
sum( | ||
map_Int_Int_List (( \x -> Math_max (Math_floor_division(x)(3) - 2)(0)) : (x: Int) -> Int) (xs) | ||
) | ||
} | ||
|
||
def main (args:Int) : Unit { | ||
print(fuel_cost(List_append(List_append(List_new)(1))(9))) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,28 @@ | ||
type List; | ||
type Map; | ||
|
||
def List_size: (l:List) -> Int = uninterpreted; | ||
def List_length: (l:List) -> Int = native "lambda list: len(list)"; | ||
def List_new : {x:List | List_size(x) == 0} = native "[]" ; | ||
def List_append: (l:List) -> (i: Int) -> {l2:List | List_size(l2) == (List_size(l) + 1)} = native "lambda xs: lambda x: xs + [x]"; | ||
|
||
def sum: (l:List) -> Int = native "lambda xs: sum(xs)"; | ||
def Math_max : (i:Int) -> (j:Int) -> Int = native "lambda i: lambda j: max(i,j)" ; | ||
def Math_floor_division : (i:Int) -> (j:Int)-> Int = native "lambda i: lambda j: i // j" ; | ||
def map_Int_Int_Int_List_List: (function: (a: Int) -> (b: Int) -> Int) -> (l: List) -> (l2: List) -> List = native "lambda f, xs: map(f, xs)"; | ||
def Map_Int_Int_Int_List_List: (function: (a: Int) -> (b: Int) -> Int) -> (l: List) -> (l2: List) -> Map = native "lambda f: lambda xs: map(f, xs)"; | ||
def Map_to_list: (m: Map) -> List = native "lambda m: list(m)"; | ||
|
||
def shopping (prices: List, discounts: List) : Int { | ||
sum( | ||
map_Int_Int_Int_List_List | ||
(( \x -> (\y -> x * (1 - y / 100))): (x:Int) -> (y:Int) -> Int) (prices) (discounts) | ||
) | ||
m: Map= Map_Int_Int_Int_List_List(( \x -> (\y -> x * (1 - y / 100))): (x:Int) -> (y:Int) -> Int) (prices) (discounts); | ||
l: List = Map_to_list(m); | ||
sum(l) | ||
|
||
} | ||
|
||
# Type not freshable: ?t <class 'aeon.core.types.TypeVar'> | ||
def main (args:Int) : Unit { | ||
l1: List = List_append(List_append(List_new) (50)) (0); | ||
l2: List = List_append(List_append(List_new) (10)) (0); | ||
print (shopping(l1)(l2)) | ||
} | ||
|
||
# TypeError: 'map' object is not callable |