<jupyter_start><jupyter_text>練習問題 1.3三つの数値を引数として取り、そのうち⼤きいほうから⼆つの数値の⼆乗の和を返す⼿続きを定義せよ。<jupyter_code>; 3つの整数のうち、一番小さい整数を確定させ、
; それ以外の2つの整数で2乗和を計算すればよい。
(define (square x) (* x x))
(define (square-add x y) (+ (square x) (square y)))
(define (f-cond x y z)
  (cond
   ((and (>= x y) (>= y z))(square-add x y))
   ((and (>= x z) (>= z y))(square-add x z))
   ((and (>= y x) (>= x z))(square-add y x))
   ((and (>= y z) (>= z x))(square-add y z))
   ((and (>= z x) (>= x y))(square-add z x))
   ((and (>= z y) (>= y x))(square-add z y))
   )
)
; 動作確認
(display (f-cond -1 2 3))
(newline)
(display (f-cond -1 3 2))
(newline)
(display (f-cond 2 -1 3))
(newline)
(display (f-cond 2 3 -1))
(newline)
(display (f-cond 3 -1 2))
(newline)
(display (f-cond 3 2 -1))
(newline)
(display (f-cond 5 -4 -7))
(newline)
; if文の場合
(define (f-if x y z)
  (if (>= x y)
   (if (>= y z) (square-add x y) (square-add x z))
   (if (>= x z) (square-add y x) (square-add y z))
   )
)
; 動作確認
(display (f-if 1 2 3))
(newline)
(display (f-if 1 3 2))
(newline)
(display (f-if 2 1 3))
(newline)
(display (f-if 2 3 1))
(newline)
(display (f-if 3 1 2))
(newline)
(display (f-if 3 2 1))
(newline)
(display (f-if 5 4 7))
(newline)<jupyter_output>13
13
13
13
13
13
74
{'fraction_non_alphanumeric': 0.22875816993464052, 'fraction_numerical': 0.049836601307189546, 'mean_word_length': 3.390681003584229, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '471454', 'license': 'CC0-1.0', 'n_tokens_mistral': 706, 'n_tokens_neox': 668, 'n_words': 184, 'path': 'exercises/1.03.ipynb', 'repo_name': 'tokits/sicp-study', 'size': '1224'}