-
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.
Merge pull request #52 from alcides/psb2
PSB2 examples
- Loading branch information
Showing
7 changed files
with
38 additions
and
83 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
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,28 +1,25 @@ | ||
type List; | ||
|
||
def List_size: (l:List) -> Int = uninterpreted; | ||
|
||
def List_len: (l:List) -> Int = native "lambda x: len(x)"; | ||
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 List_get: (l:List) -> (i: Int) -> Int = native"lambda xs: lambda i: xs[i]"; | ||
|
||
def get_fst: (l:List) -> Int = native "lambda xs: xs[0]"; | ||
def get_snd: (l:List) -> Int = native "lambda xs: xs[1]"; | ||
|
||
def accumulate_prefix_sum: (l:List)-> (i:Int) -> List = \l -> \i -> | ||
extra : Int = if get_fst l + get_snd l >= 0 then 1 else 0; | ||
List_append (List_append List_new (get_fst l + get_snd l)) (get_snd l + extra) | ||
; | ||
|
||
def aeon_reduce: (function: (a: List) -> (b: Int) -> List) -> (l: List) -> (l2: List) -> List = native "lambda f: lambda xs: lambda ys: __import__('functools').reduce(lambda x, y:f(x)(y), xs, ys)"; | ||
def fst_negative (l:List) (i:Int)(u:Int) : Int { | ||
if (i >= (List_len l)) then | ||
i | ||
else if (u < 0) then | ||
i | ||
else | ||
fst_negative l (i + 1) (u + (List_get l (i + 1))) | ||
} | ||
|
||
def basement (nums: List) : Int { | ||
get_snd ( | ||
aeon_reduce accumulate_prefix_sum nums (List_append (List_append List_new 0) 0) | ||
) | ||
} | ||
fst_negative nums 0 (List_get nums 0) | ||
} | ||
|
||
|
||
def main (args:Int): Unit { | ||
print (aeon_reduce (accumulate_prefix_sum) (List_append List_new 0) (List_append (List_append List_new 0) 0 )) | ||
print (basement (List_append List_new (-100)) ) | ||
} |
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