haskell - 循环遍历二维数组和记录位置的 Haskell 等价性
问题描述
我如何在haskell中编写这个java代码。我想遍历一个二维数组来检查一个人(机器)和工作对并记录机器的位置。
int col = 0;
int row = 0;
int count = 0; // accumulator
// a loop to check 2D array for m and t pairs
for(int i = 0; i < input.length; i++) {
for(int j = 0; j < m.length; j++) {
if(input[i].charAt(0) == m[j]) {
col = j; // recording position of m for 2D array
break;
}
}
for(int j = 0; j < t.length; j++) {
if(input[i].charAt(1) == t[j]) {
row = j;
break;
}
}
解决方案
您可以使用findIndex
来查找列表中与谓词匹配的第一个元素的索引(如果存在)。
推荐阅读
- javascript - Value.match(/[^0-9|\/]/gi) 不适用于数字?
- java - 无法从 mysql 获取数据以显示在我的 jList 中
- vba - 如何在不调用该列表的每个索引的情况下从下拉列表中选择 Vba?
- python - 如果用户没有输入可选值,如何通过表单(不是 django 表单)接收 django 视图中的可选值?
- java - 如何修复此错误?:线程“main”中的异常 java.lang.ArrayIndexOutOfBoundsException: 3
- amazon-web-services - AWS 上的弹性搜索服务。或者别的地方
- javascript - 将 div 与可点击翻转卡的底部对齐(引导程序 4)
- java - 在我的聊天应用程序中,我有这个错误 java.lang.NullPointerException
- javascript - React, Redux, TypeError: undefined is not an object, if 语句
- go - 多次运行同一个 go 程序会引发恐慌:在关闭的通道上发送