这段代码对我来说似乎有点迟钝......有人想通过解释来帮助我吗?
uniq_c l = [ nl (tam l) i s | (s,i) <- uniq_c' l]
tam = maximum . map snd . uniq_c'
uniq_c' [] = []
uniq_c' (h:t) = let (list,rest) = span (==h) t
n = length list + 1
in (h,n) : uniq_c' rest
nl tam n line = let l = length $ show n
l_tam = length $ show tam
n' = replicate (l_tam-l) " "
in concat n' ++ show n ++ " " …Run Code Online (Sandbox Code Playgroud) 我已经做了一个谜题,玩家滑动到目标 - 规则相当简单:
我认为这是规则所涵盖的.以下是一些截图:

在这里玩家必须移动块,以便他们必须互相击打以解决难题.

其中的难题是近乎解决的状态.注意块是如何击中另一个块并停止的
这是另一个包含推块功能的谜题:

如果我们向右滑动右上方的块,会发生以下情况:

如您所见,当块碰到箭头块时,块已移动到左侧,并停在木块顶部.
我想编写一个解决这些难题的AI解决方案 - 我认为这将是某种深度优先搜索,但我不知道从哪里开始.实现这一目标的任何指针都将是一件好事!
如果我有一个64长度的java数组i [],有没有一种快速的方法可以找出该数组中的每个位置是否都是"满",而不是循环整个数组?我正在编写一个Reversi AI,我需要知道整个阵列是否已满.
我开发了一个迷你shell,接受来自stdin的文本.它到目前为止工作,但我需要让它返回(在>之前的小东西)
他们登录的机器名称和当前工作目录.
我有
#include <unistd.h>
Run Code Online (Sandbox Code Playgroud)
在代码中,当前的工作目录是使用getcwd(2)得到的,它工作正常,但gethostname(2)似乎不起作用.它不会在MINGW32上使用gcc进行编译,给出错误:未定义的引用到'gethostname'colle2:ld重新出现1退出状态.
到目前为止,这是我的代码.
#include <stdio.h>
#include <string.h>
#include <unistd.h>
static int LINE_MAX = 10000;
static char *cmdLine = "Samcmd --> ";
int main( int argc, char *argv[] )
{
char cwd[LINE_MAX];
char hostName[LINE_MAX];
int looper = 1;
char *token = NULL;
char line[LINE_MAX];
char *placehold = NULL;
getcwd(cwd, LINE_MAX - 1);
gethostname(hostName, LINE_MAX - 1);
while ( looper == 1 )
{
printf( "%s | %s", hostName, cmdLine );
if( fgets( line, LINE_MAX, stdin ) != …Run Code Online (Sandbox Code Playgroud) 我知道HashSet.contains()方法使用.equals方法来检查相等性,因为它检查指针以查看它们是否相等.
我需要它来检查指针上的实际对象是否相等 - 在我的具体情况下,我需要查看HashSet中是否已经存在打开的"Node"(一个int []数组).这对我的搜索算法至关重要,因此我的双向迭代深化搜索的实现并不那么天真.
如果可能的话,我仍然喜欢线性搜索时间,或者我应该使用不同的类?
谢谢你的帮助.
所以我在Ubuntu上使用zlib包.我正在试图弄清楚如何正确使用gzopen和gzread,这是我到目前为止所拥有的
#include <stdio.h>
#include <string.h>
#include <assert.h>
#include <zlib.h>
#define NUM_BUFFERS 8
#define BUFFER_LENGTH 1024
char buf[BUFFER_LENGTH];
int main(int argc, const char* argv[])
{
int status;
gzFile file;
file = gzopen("beowulf.txt", "w");
int counter = 0; /*when the counter reachers BUFFERS_FULL, stop*/
if(file == NULL)
{
printf("COULD NOT OPEN FILE\n");
return 1;
}
while(counter < NUM_BUFFERS)
{
status = gzread(file, buf, BUFFER_LENGTH - 2);
printf("STATUS: %d\n", status);
buf[BUFFER_LENGTH - 1] = "\0";
printf("%s\n", buf);
counter++;
}
gzclose(file);
printf("STATUS: %d\n", status); …Run Code Online (Sandbox Code Playgroud)