File tree Expand file tree Collapse file tree 4 files changed +71
-3
lines changed Expand file tree Collapse file tree 4 files changed +71
-3
lines changed Original file line number Diff line number Diff line change 1+ import gleam/list
2+ import gleam/int
3+ import gleam/io
4+ import gleam/string
5+
6+ pub fn main ( ) {
7+ let print_triple = fn ( triple : List ( Int ) ) {
8+ triple
9+ |> list . map ( int . to_string )
10+ |> string . join ( ", " )
11+ |> io . println
12+ }
13+
14+ list . range ( 1 , 40 ) |> list . each ( fn ( c ) {
15+ list . range ( 1 , c ) |> list . each ( fn ( b ) {
16+ list . range ( 1 , b ) |> list . each ( fn ( a ) {
17+ case { a * a + b * b == c * c } {
18+ True -> print_triple ( [ a , b , c ] )
19+ False -> Nil
20+ }
21+ } )
22+ } )
23+ } )
24+ }
Original file line number Diff line number Diff line change 1+ import gleam/float
2+ import gleam/list
3+ import gleam/int
4+ import gleam/io
5+ import gleam/result
6+ import gleam/string
7+
8+ pub fn main ( ) {
9+
10+ let valid_triple = fn ( triple : List ( Int ) ) {
11+ let target = triple
12+ |> list . last
13+ |> result . unwrap ( 0 )
14+ |> int . to_float
15+
16+ triple
17+ |> list . map ( fn ( n ) { n * n } )
18+ |> int . sum
19+ |> int . to_float
20+ |> float . divide ( by : 2.0 )
21+ |> result . unwrap ( 0.0 )
22+ |> float . square_root
23+ |> result . unwrap ( 0.0 )
24+ |> float . loosely_equals ( with : target , tolerating : 0.0 )
25+ }
26+
27+ let print_triple = fn ( triple : List ( Int ) ) {
28+ triple
29+ |> list . map ( int . to_string )
30+ |> string . join ( ", " )
31+ |> io . println
32+ }
33+
34+ list . range ( 1 , 40 )
35+ |> list . combinations ( 3 )
36+ |> list . filter ( valid_triple )
37+ |> list . each ( print_triple )
38+ }
Original file line number Diff line number Diff line change 1- import gleam/io
1+ import gleam/io . { println }
22
33pub fn main ( ) {
4- io . println ( "Hello Sandra!" )
5- io . println ( "Hello to you too, Bob!" )
4+ println ( "Hello Sandra!" )
5+ println ( "Hello to you too, Bob!" )
66}
Original file line number Diff line number Diff line change @@ -20,6 +20,12 @@ gleam run -m factorial &&
2020gleam run - m generics &&
2121gleam run - m hello &&
2222gleam run - m pipelines &&
23+ gleam run - m triple_pipelines |
24+ Compare-Object (Get-Content " $PSScriptRoot \..\test\triple_expected" ) |
25+ Assert-MatchTests &&
26+ gleam run - m triple |
27+ Compare-Object (Get-Content " $PSScriptRoot \..\test\triple_expected" ) |
28+ Assert-MatchTests &&
2329gleam run - m unqualified_imports &&
2430ForEach-Object ' foo' ;
2531
You can’t perform that action at this time.
0 commit comments