Upgrade to Pro — share decks privately, control downloads, hide ads and more …

PLT-03 Haskell

kanaya
April 27, 2024
65

PLT-03 Haskell

kanaya

April 27, 2024
Tweet

Transcript

  1. pineapple.cc 5*0#&*OEFY April 2024  1ZUIPO    $

       $     +BWB    $    +BWB4DSJQU &$."4DSJQU     (P    7JTVBM#BTJD    42-    'PSUSBO    %FMQIJ 0CKFDU1BTDBM     "TTFNCMZMBOHVBHF    3VCZ    4XJGU    4DSBUDI    ."5-"#    1)1    ,PUMJO    3VTU    3 
  2. pineapple.cc program kyoto; uses math; function f(n: real): real; var

    r: real; d: real; begin r := floor(n / 7); d := r * 7; f := n - d end; { f } function g(n: integer): real; function expt(k, n: integer): real; var i: integer; r: real; begin r := 1; for i := 1 to n do r := r * k; expt := r end; var k: integer; a: real; begin a := 0; for k := 1 to 7 do a := a + expt(k, n); g := 3 * f(a) end; { g } var i: integer; begin for i := 1 to 11 do writeln(g(i)) end. Pascal
  3. pineapple.cc (use srfi-1) (define (f n) (remainder n 7)) (define

    (g n) (* 3 (f (fold (lambda (k a) (+ a (expt k n))) 0 (iota 7 1))))) (print (map g (iota 13 1))) Scheme
  4. pineapple.cc f :: Int -> Int f n = n

    `mod` 7 g :: Int -> Int g n = 3 * f (sum (map (\k -> k^n) [1..7])) main = print (map g [1..13]) f(n) = n (mod 7) g(n) = 3f ( 7 ∑ k=1 kn ) Haskell