首页 > 其他分享 >sicp每日一题[2.52]

sicp每日一题[2.52]

时间:2024-10-22 10:45:29浏览次数:5  
标签:2.52 每日 sicp vect 65 85 segment painter split

Exercise 2.52

Make changes to the square limit of wave shown in Figure 2.9 by working at each of the levels described above. In particular:

a. Add some segments to the primitive wave painter of Exercise 2.49 (to add a smile, for example).
b. Change the paern constructed by corner-split (for example, by using only one copy of the up-split and right-split images instead of two).
c. Modify the version of square-limit that uses square-of-four so as to assemble the corners in a different pateern. (For example, you might make the big Mr.Rogers look outward from each corner of the square.)


对于我来说,这道题最大的难度在于理解题意,我根据自己的理解修改之后想:就这么简单?然后去查了其他人的答案,发现还真就这么简单 :)

(#%require sicp-pict)


(define wave 
  (segments->painter (list 
                      (segment (vect .25 0) (vect .35 .5)) 
                      (segment (vect .35 .5) (vect .3 .6)) 
                      (segment (vect .3 .6) (vect .15 .4)) 
                      (segment (vect .15 .4) (vect 0 .65)) 
                      (segment (vect 0 .65) (vect 0 .85)) 
                      (segment (vect 0 .85) (vect .15 .6)) 
                      (segment (vect .15 .6) (vect .3 .65)) 
                      (segment (vect .3 .65) (vect .4 .65)) 
                      (segment (vect .4 .65) (vect .35 .85)) 
                      (segment (vect .35 .85) (vect .4 1)) 
                      (segment (vect .4 1) (vect .6 1)) 
                      (segment (vect .6 1) (vect .65 .85)) 
                      (segment (vect .65 .85) (vect .6 .65)) 
                      (segment (vect .6 .65) (vect .75 .65)) 
                      (segment (vect .75 .65) (vect 1 .35)) 
                      (segment (vect 1 .35) (vect 1 .15)) 
                      (segment (vect 1 .15) (vect .6 .45)) 
                      (segment (vect .6 .45) (vect .75 0)) 
                      (segment (vect .75 0) (vect .6 0)) 
                      (segment (vect .6 0) (vect .5 .3)) 
                      (segment (vect .5 .3) (vect .4 0)) 
                      (segment (vect .4 0) (vect .25 0)) 
                      )))

(define (right-split painter n)
  (if (= n 0)
      painter
      (let ((smaller (right-split painter (- n 1))))
        (beside painter (below smaller smaller)))))

(define (up-split painter n)
  (if (= n 0)
      painter
      (let ((smaller (up-split painter (- n 1))))
        (beside painter (below smaller smaller)))))

; a
(define wave-with-smile
  (segments->painter (list 
                      (segment (vect .25 0) (vect .35 .5)) 
                      (segment (vect .35 .5) (vect .3 .6)) 
                      (segment (vect .3 .6) (vect .15 .4)) 
                      (segment (vect .15 .4) (vect 0 .65)) 
                      (segment (vect 0 .65) (vect 0 .85)) 
                      (segment (vect 0 .85) (vect .15 .6)) 
                      (segment (vect .15 .6) (vect .3 .65)) 
                      (segment (vect .3 .65) (vect .4 .65)) 
                      (segment (vect .4 .65) (vect .35 .85))
                      (segment (vect .35 .85) (vect .4 1))
                      (segment (vect .4 1) (vect .6 1)) 
                      (segment (vect .6 1) (vect .65 .85))
                      (segment (vect .65 .85) (vect .6 .65)) 
                      (segment (vect .6 .65) (vect .75 .65)) 
                      (segment (vect .75 .65) (vect 1 .35)) 
                      (segment (vect 1 .35) (vect 1 .15)) 
                      (segment (vect 1 .15) (vect .6 .45)) 
                      (segment (vect .6 .45) (vect .75 0)) 
                      (segment (vect .75 0) (vect .6 0)) 
                      (segment (vect .6 0) (vect .5 .3)) 
                      (segment (vect .5 .3) (vect .4 0)) 
                      (segment (vect .4 0) (vect .25 0))
                      (segment (vect .45 .76) (vect .5 0.72))
                      (segment (vect .5 0.72) (vect .55 .76))
                      )))

(paint wave-with-smile)


(define (corner-split painter n)
  (if (= n 0)
      painter
      (let ((up (up-split painter (- n 1)))
            (right (right-split painter (- n 1))))
        (let ((top-left up)
              (bottom-right (below right right))
              (corner (corner-split painter (- n 1))))
          (beside (below painter top-left)
                  (below bottom-right corner))))))

(paint (corner-split wave-with-smile 1))

(define (square-of-four tl tr bl br)
  (lambda (painter)
    (let ((top (beside (tl painter) (tr painter)))
          (bottom (beside (bl painter) (br painter))))
      (below bottom top))))

(define (square-limit painter n)
  (let ((combine4 (square-of-four flip-vert rotate180
                                  identity flip-horiz)))
    (combine4 (corner-split painter n))))

(paint (square-limit wave-with-smile 1))

执行结果如下图所示:

标签:2.52,每日,sicp,vect,65,85,segment,painter,split
From: https://www.cnblogs.com/think2times/p/18492094

相关文章

  • 2024-10-21每日一题
    P1223排队接水题目描述有\(n\)个人在一个水龙头前排队接水,假如每个人接水的时间为\(T_i\),请编程找出这\(n\)个人排队的一种顺序,使得\(n\)个人的平均等待时间最小。输入格式第一行为一个整数\(n\)。第二行\(n\)个整数,第\(i\)个整数\(T_i\)表示第\(i\)个人的......
  • 1107. 每日新用户统计
    力扣题目跳转(1107.每日新用户统计-力扣(LeetCode))Traffic 表:+---------------+---------+|ColumnName|Type|+---------------+---------+|user_id|int||activity|enum||activity_date|date|+---------------+---------+......
  • 10.21日每日收获
    1、扇区擦除时按首地址擦除,若设定地址不是首地址也从首地址开始擦除,每512个字节为一组,如00H-200H为一组,200H-400H为一组,擦除数据时按组擦除,若果设置擦除开始地址为100h,则仍然会从00H-200H擦除,而不是100H-300H2、有些芯片的FLASHROM结构是类RAM结构,也就是无需擦除可以直接覆盖......
  • 每日一道算法题(栈)
     What'spastisprologue. 凡是过去,皆为序章。题目 分析 1.我们可以用栈的结构来解决这道题。2.我们使用while循环,每次读取字符串中一个元素进行操作,直到最后读取到'\0'为止。3.如果遇见'(','[','{' 这三种左括号,则把该左括号入栈;如果遇见')',']','}......
  • sicp每日一题[2.51]
    Exercise2.51Definethebelowoperationforpainters.belowtakestwopaintersasarguments.Theresultingpainter,givenaframe,drawswiththefirstpainterinthebottomoftheframeandwiththesecondpainterinthetop.Definebelowintwodiffere......
  • 代码随想录算法训练营 | 739. 每日温度,496.下一个更大元素 I ,503.下一个更大元素II
    739.每日温度题目链接:739.每日温度文档讲解︰代码随想录(programmercarl.com)视频讲解︰每日温度日期:2024-10-20想法:遍历一遍数组,用栈来存数组下标做记录,因为要找更高得温度,当当前遍历的温度大于栈头存储(存的下标)的温度时,就可以知道栈头要过多少天遇到高温,低的时候直接入栈。J......
  • sicp每日一题[2.50]
    Exercise2.50Definethetransformationflip-horiz,whichflipspaintershorizontally,andtransformationsthatrotatepainterscounterclockwiseby180degreesand270degrees.这道题挺有意思的,搞明白这道题就明白了frame的3个点的位置。如上图所示,为了更好......
  • sicp每日一题[2.49]
    Exercise2.49Usesegments->paintertodefinethefollowingprimitivepainters:a.Thepainterthatdrawstheoutlineofthedesignatedframe.b.Thepainterthatdrawsan“X”byconnectingoppositecornersoftheframe.c.Thepainterthatdrawsad......
  • 20241018每日一题洛谷P2386
    普及每日一题信息学竞赛1206:放苹果把M个同样的苹果放在N个同样的盘子里,允许有的盘子空着不放,问共有多少种不同的分法?(用K表示)5,1,1和1,5,1是同一种分法。第一行是测试数据的数目t(0<=t<=20)。以下每行均包含二个整数M和N,以空格分开。1<=M,N<=10。对输入的每组数据M和N,用一行输出相......
  • sicp每日一题[2.48]
    Exercise2.48Adirectedlinesegmentintheplanecanberepresentedasapairofvectors—thevectorrunningfromtheorigintothestart-pointofthesegment,andthevectorrunningfromtheorigintotheend-pointofthesegment.Useyourvectorrepre......