从列表中找出方阵的对角线 [英] Finding the diagonals of square matrix made from lists

查看:121
本文介绍了从列表中找出方阵的对角线的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在尝试定义一个函数,该函数接受一个列表列表,将这些列表列表为一个正方形矩阵并返回该矩阵的对角线的模型.

I am currently trying to define a function that takes a list of lists, models that list as a square matrix and returns the diagonal of said matrix.

例如,输入((a b c) (d e f) (g h i))给出(a e i).

我对如何解决这个问题有一个模糊的想法(取最后一个列表的最后一个元素,然后取倒数第二个列表的倒数第二个元素,依此类推),但是我不确定如何解决这个问题.在Scheme中对此进行编程.

I have a vague idea of how to go about solving this (taking the last element of the last list then the second to last element of the second to last list etc.) but I am not really sure of how to go about programming this in Scheme.

如果有人能指出我正确的方向,我将不胜感激.

I would appreciate it if somebody could point me in the right direction.

谢谢.

推荐答案

(对 Nethack 粉丝)

(With apologies to Nethack fans)

从坛上后退时,您会发现地板上有一小块纸,您可以从中解密以下文本:

As you step back from the altar, you find a little piece of paper lying on the floor from which you can decipher the following text:

0> Calling (DIAG ((A B C) (D E F) (G H I))) 
 1> Calling (DIAG ((E F) (H I))) 
  2> Calling (DIAG ((I))) 
   3> Calling (DIAG NIL) 
   <3 DIAG returned NIL
  <2 DIAG returned (I)
 <1 DIAG returned (E I)
<0 DIAG returned (A E I)

这看起来不错,但是当您开始大声朗读滚动条时,您会闻到附近垃圾的恶臭味. 在变态魔杖的帮助下,您可以使被诅咒的物体灭顶. 前面的文本消失了,并且出现了另一个文本:

This looks good, but as you start reading the scroll aloud, you smell a foul scent of garbage nearby. With the help of your wand of metamorphosis, you zap the cursed object. The previous text vanishes and another one appears:

0> Calling (DIAG ((A B C) (D E F) (G H I))) 
 1> Calling (DIAG% ((A B C) (D E F) (G H I)) 0) 
  2> Calling (DIAG% ((D E F) (G H I)) 1) 
   3> Calling (DIAG% ((G H I)) 2) 
    4> Calling (DIAG% NIL 3) 
    <4 DIAG% returned NIL
   <3 DIAG% returned (I)
  <2 DIAG% returned (E I)
 <1 DIAG% returned (A E I)
<0 DIAG returned (A E I)

一个明亮的领域围绕着你!

A lit field surrounds you!

这篇关于从列表中找出方阵的对角线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆