由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Programming版 - 数八皇后解法数目:python只要9行
相关主题
程序员薪水也谈谈语言之争
问-最近几年流行的计算机语言会是什么?想学 (转载)俺老10年前关于语言未来的论述
C++ vs Javac++正在向夕阳语言大幅度迈进
读Bjarne Stroustrup写得The C++ programming language 是不是经常有不知所谓的感觉。看到那么多Java黑
从今天开始起,学C++!我现在常用语言是LABVIEW和ACCESS
c++逐渐没落?c++就像一个贼船
这么好的帖子没人转?C++虽然工作机会少一些,但没有新毕业生和你抢饭碗
怎么efficiently实现next_combination?JAVA还是挺可爱的
相关话题的讨论汇总
话题: fullpos话题: range话题: abs
进入Programming版参与讨论
1 (共1页)
t*s
发帖数: 1504
1
刚刚无聊,想练练python, 就随便做了这个题。。。结果只用了9行代码,还是蛮有成
就感的
from itertools import permutations,combinations
c=0
for fullpos in permutations(range(1,9),8):
for i,j in combinations(range(1,9),2):
if abs(i-j)==abs(fullpos[i-1]-fullpos[j-1]):
break
else:
c+=1
print(c)
A**u
发帖数: 2458
2
super cow
EM
发帖数: 715
3
啥是数八皇后?

【在 t*s 的大作中提到】
: 刚刚无聊,想练练python, 就随便做了这个题。。。结果只用了9行代码,还是蛮有成
: 就感的
: from itertools import permutations,combinations
: c=0
: for fullpos in permutations(range(1,9),8):
: for i,j in combinations(range(1,9),2):
: if abs(i-j)==abs(fullpos[i-1]-fullpos[j-1]):
: break
: else:
: c+=1

w***g
发帖数: 5958
4
要求加入剪枝,打回去重写。

【在 t*s 的大作中提到】
: 刚刚无聊,想练练python, 就随便做了这个题。。。结果只用了9行代码,还是蛮有成
: 就感的
: from itertools import permutations,combinations
: c=0
: for fullpos in permutations(range(1,9),8):
: for i,j in combinations(range(1,9),2):
: if abs(i-j)==abs(fullpos[i-1]-fullpos[j-1]):
: break
: else:
: c+=1

a*w
发帖数: 4495
5
数(((八皇后)解法)数目)

【在 EM 的大作中提到】
: 啥是数八皇后?
t*s
发帖数: 1504
6
count the number of solutions to the 8 queen puzzle

【在 EM 的大作中提到】
: 啥是数八皇后?
t*s
发帖数: 1504
7
that makes it less pythonic ,ha

【在 w***g 的大作中提到】
: 要求加入剪枝,打回去重写。
f*******n
发帖数: 12623
8
why not
from itertools import permutations,combinations
c=sum(all(abs(i-j)!=abs(fullpos[i-1]-fullpos[j-1]) for i,j in combinations(range(8),2)) for fullpos in permutations(range(8)))
print(c)
t*s
发帖数: 1504
9
eval(...)
one line, ha

(range(8),2)) for fullpos in permutations(range(8)))

【在 f*******n 的大作中提到】
: why not
: from itertools import permutations,combinations
: c=sum(all(abs(i-j)!=abs(fullpos[i-1]-fullpos[j-1]) for i,j in combinations(range(8),2)) for fullpos in permutations(range(8)))
: print(c)

g******n
发帖数: 253
10
茴香豆有四种写法。。。。。

【在 t*s 的大作中提到】
: 刚刚无聊,想练练python, 就随便做了这个题。。。结果只用了9行代码,还是蛮有成
: 就感的
: from itertools import permutations,combinations
: c=0
: for fullpos in permutations(range(1,9),8):
: for i,j in combinations(range(1,9),2):
: if abs(i-j)==abs(fullpos[i-1]-fullpos[j-1]):
: break
: else:
: c+=1

相关主题
c++逐渐没落?也谈谈语言之争
这么好的帖子没人转?俺老10年前关于语言未来的论述
怎么efficiently实现next_combination?c++正在向夕阳语言大幅度迈进
进入Programming版参与讨论
g*****g
发帖数: 34805
11
It's the thinking behind the code, not typing of the code that's
time consuming, particularly with modern IDE.
LOC is not that important.
n******t
发帖数: 4406
12
没啥意思,要想代码段,python完全不是functional programming language 的对手,
很容易写个1行的。

【在 t*s 的大作中提到】
: 刚刚无聊,想练练python, 就随便做了这个题。。。结果只用了9行代码,还是蛮有成
: 就感的
: from itertools import permutations,combinations
: c=0
: for fullpos in permutations(range(1,9),8):
: for i,j in combinations(range(1,9),2):
: if abs(i-j)==abs(fullpos[i-1]-fullpos[j-1]):
: break
: else:
: c+=1

l********a
发帖数: 1154
13
python在代码简洁和运行高效之间取到了较好的平衡
光短也不行,还得好理解点

【在 n******t 的大作中提到】
: 没啥意思,要想代码段,python完全不是functional programming language 的对手,
: 很容易写个1行的。

S*******s
发帖数: 13043
14
with C++:
std::cout<<12;
X****r
发帖数: 3557
15
And I would argue that readability is exactly
where functional programming language shines:
you can't write any code in it without totally
understanding how the code is supposed to work.
Not only it helps to reduce the number of bugs,
it also screens out incompetent programmers.
The only problem is that there aren't enough
competent programmers interested in using it. :P

【在 l********a 的大作中提到】
: python在代码简洁和运行高效之间取到了较好的平衡
: 光短也不行,还得好理解点

t*s
发帖数: 1504
16
lol, 一行代码也能被你整出个bug来

【在 S*******s 的大作中提到】
: with C++:
: std::cout<<12;

m*****e
发帖数: 4193
17

It's not the writer's understanding of the code that is the issue. It's the
reader's.

【在 X****r 的大作中提到】
: And I would argue that readability is exactly
: where functional programming language shines:
: you can't write any code in it without totally
: understanding how the code is supposed to work.
: Not only it helps to reduce the number of bugs,
: it also screens out incompetent programmers.
: The only problem is that there aren't enough
: competent programmers interested in using it. :P

X****r
发帖数: 3557
18
Of course it is reader's. But only readers that already know the programing
language count. Thus, by shutting out those who would incorrectly understand
the code, the readability of the code improves.

the

【在 m*****e 的大作中提到】
:
: It's not the writer's understanding of the code that is the issue. It's the
: reader's.

g*****g
发帖数: 34805
19
Software engineering is all about getting the job done
in shortest time with lowest budget. Functional programming
just does neither.

【在 X****r 的大作中提到】
: And I would argue that readability is exactly
: where functional programming language shines:
: you can't write any code in it without totally
: understanding how the code is supposed to work.
: Not only it helps to reduce the number of bugs,
: it also screens out incompetent programmers.
: The only problem is that there aren't enough
: competent programmers interested in using it. :P

L***n
发帖数: 6727
20
and the size of the talent pool who can maintain the code significantly
drops

programing
understand

【在 X****r 的大作中提到】
: Of course it is reader's. But only readers that already know the programing
: language count. Thus, by shutting out those who would incorrectly understand
: the code, the readability of the code improves.
:
: the

相关主题
看到那么多Java黑C++虽然工作机会少一些,但没有新毕业生和你抢饭碗
我现在常用语言是LABVIEW和ACCESSJAVA还是挺可爱的
c++就像一个贼船自己看c++是不是夕阳语言
进入Programming版参与讨论
n******t
发帖数: 4406
21
not true...FP can be extremely easy to write, I am at very low level of FP l
anguage, and I can solve these kind of problem in 1 line without much effort
.
I think the biggest problem for functional programming is the efficiency.

【在 g*****g 的大作中提到】
: Software engineering is all about getting the job done
: in shortest time with lowest budget. Functional programming
: just does neither.

g*****g
发帖数: 34805
22
You can do that because the problem isn't complex enough.
Try 100K LOC project it will be very different. And 100K
is by no means big.

l
effort

【在 n******t 的大作中提到】
: not true...FP can be extremely easy to write, I am at very low level of FP l
: anguage, and I can solve these kind of problem in 1 line without much effort
: .
: I think the biggest problem for functional programming is the efficiency.

r*g
发帖数: 3159
23
多长的一行?超过80个字符就要换行...

l
effort

【在 n******t 的大作中提到】
: not true...FP can be extremely easy to write, I am at very low level of FP l
: anguage, and I can solve these kind of problem in 1 line without much effort
: .
: I think the biggest problem for functional programming is the efficiency.

t*s
发帖数: 1504
24
别光说不练,写一个?

l
effort

【在 n******t 的大作中提到】
: not true...FP can be extremely easy to write, I am at very low level of FP l
: anguage, and I can solve these kind of problem in 1 line without much effort
: .
: I think the biggest problem for functional programming is the efficiency.

S*******s
发帖数: 13043
25
from itertools import permutations
n = 8
cols = range(n)
for vec in permutations(cols):
if (n == len(set(vec[i]+i for i in cols))
== len(set(vec[i]-i for i in cols))):
print vec
a*w
发帖数: 4495
26

l
effort
要说efficiency,OOP有更多overhead,效率应该更低啊。

【在 n******t 的大作中提到】
: not true...FP can be extremely easy to write, I am at very low level of FP l
: anguage, and I can solve these kind of problem in 1 line without much effort
: .
: I think the biggest problem for functional programming is the efficiency.

a****l
发帖数: 8211
27
totally right. You might even be able to write the entire windows in one
line.

【在 r*g 的大作中提到】
: 多长的一行?超过80个字符就要换行...
:
: l
: effort

S*******s
发帖数: 13043
28
what bug?

【在 t*s 的大作中提到】
: lol, 一行代码也能被你整出个bug来
n******t
发帖数: 4406
29


【在 r*g 的大作中提到】
: 多长的一行?超过80个字符就要换行...
:
: l
: effort

n******t
发帖数: 4406
30
大部分这些语言用的人少。比如说用K写:
p@&{a:{(#x)=#?x};i:!#x;a[x[i]+i]&a[x[i]-i]}'p:{:[1:'(x,x)#1,x#0)[;0,'
1+_f x-1];,!x]}8
这个还自带了一个permutation.

【在 t*s 的大作中提到】
: 别光说不练,写一个?
:
: l
: effort

相关主题
没道理看不起Java 程序员问-最近几年流行的计算机语言会是什么?想学 (转载)
这个行当真是没落了C++ vs Java
程序员薪水读Bjarne Stroustrup写得The C++ programming language 是不是经常有不知所谓的感觉。
进入Programming版参与讨论
t*s
发帖数: 1504
31
readability hell

,'

【在 n******t 的大作中提到】
: 大部分这些语言用的人少。比如说用K写:
: p@&{a:{(#x)=#?x};i:!#x;a[x[i]+i]&a[x[i]-i]}'p:{:[1:'(x,x)#1,x#0)[;0,'
: 1+_f x-1];,!x]}8
: 这个还自带了一个permutation.

n******t
发帖数: 4406
32
If you know the language, actually it is very easy to read...

【在 t*s 的大作中提到】
: readability hell
:
: ,'

q*c
发帖数: 9453
33
大家都是小民工, 一个个确都站在资本家的立场上考虑问题, lol.
"and the size of the talent pool who can maintain the code significantly
drops"
This is exactly what we needed -- Thus the job pay and security
significantly increases!!!!
这才是重要的。 我宁可从来没人发明除了unix 命令行和 C 以外的任何语言。
pointer 满天飞, script 遍地跑。学 CS 需要大把的精神和特别的聪明, 就像理论
物理学博士一样。
这比 ICC 几天催肥出来的面试高手到处抢工作的局面好多了。 呵呵。

【在 L***n 的大作中提到】
: and the size of the talent pool who can maintain the code significantly
: drops
:
: programing
: understand

g*****g
发帖数: 34805
34
I beg to differ. When you don't have the talent pool, the
language may just die or you can't find your next job.
Cobol is still well paid but good luck to find an opportunity.

【在 q*c 的大作中提到】
: 大家都是小民工, 一个个确都站在资本家的立场上考虑问题, lol.
: "and the size of the talent pool who can maintain the code significantly
: drops"
: This is exactly what we needed -- Thus the job pay and security
: significantly increases!!!!
: 这才是重要的。 我宁可从来没人发明除了unix 命令行和 C 以外的任何语言。
: pointer 满天飞, script 遍地跑。学 CS 需要大把的精神和特别的聪明, 就像理论
: 物理学博士一样。
: 这比 ICC 几天催肥出来的面试高手到处抢工作的局面好多了。 呵呵。

q*c
发帖数: 9453
35
那是因为有了这么多语言啊!
要是只有 cobol, 所有的 job 都是 opportunity...
就像医学院成了垄断, 通过法律禁止你其他人干我这行,
干我这行的必须都用这些玩意, 哈哈。

【在 g*****g 的大作中提到】
: I beg to differ. When you don't have the talent pool, the
: language may just die or you can't find your next job.
: Cobol is still well paid but good luck to find an opportunity.

g*****g
发帖数: 34805
36
编程语言简单,容易维护,才可以开发大型的软件。才可以开发便宜
的软件。才能把各行各业都吸引过来产生软件需求,产生工作。中国人
所说的薄利多销。如果你比90%的程序员强,行内的工作越多,不就更安全。
把蛋糕做大对大家都有好处。
医生行业不同,没有太多潜力可以挖掘。就那么多病人。价格便宜整体
要少挣钱。涨价太多又看不起。

【在 q*c 的大作中提到】
: 那是因为有了这么多语言啊!
: 要是只有 cobol, 所有的 job 都是 opportunity...
: 就像医学院成了垄断, 通过法律禁止你其他人干我这行,
: 干我这行的必须都用这些玩意, 哈哈。

b***i
发帖数: 3043
37
并不是大家把自己当资本家,而是资本家这样考虑并且竞争,才有了这样的平台比如
windows,让你开发软件,多样的语言,提高效率。这是竞争的结果。
而民工别无选择。资本家让你用java,python,C#等来提高效率,你不会就少很多工作
机会。不积极学习,参与竞争,成为胜利者,超越其他90%的民工,就是失业一条路。

【在 q*c 的大作中提到】
: 大家都是小民工, 一个个确都站在资本家的立场上考虑问题, lol.
: "and the size of the talent pool who can maintain the code significantly
: drops"
: This is exactly what we needed -- Thus the job pay and security
: significantly increases!!!!
: 这才是重要的。 我宁可从来没人发明除了unix 命令行和 C 以外的任何语言。
: pointer 满天飞, script 遍地跑。学 CS 需要大把的精神和特别的聪明, 就像理论
: 物理学博士一样。
: 这比 ICC 几天催肥出来的面试高手到处抢工作的局面好多了。 呵呵。

e**********n
发帖数: 359
38
import eight_queens
print eight_queens.solve()
n******t
发帖数: 4406
39
我觉得Java/Python/C#这些东西也还好把,其实这些算是创造新的工作机会。原来系统
级的开发,还是那些语言,职位也没减少,但是在开发这一行业的比重的确是变少了。
就我所知很多人是没法写出一个超过50000行能用的C程序的,但是能写出一个同样功能
的Java/Pyton/C#的人还是要多好多的.

【在 b***i 的大作中提到】
: 并不是大家把自己当资本家,而是资本家这样考虑并且竞争,才有了这样的平台比如
: windows,让你开发软件,多样的语言,提高效率。这是竞争的结果。
: 而民工别无选择。资本家让你用java,python,C#等来提高效率,你不会就少很多工作
: 机会。不积极学习,参与竞争,成为胜利者,超越其他90%的民工,就是失业一条路。

t****t
发帖数: 6806
40
50000行很多了, 我在公司做的这个项目做了好几年了也就四万行多点. 当然基本上就
我一个人维护.

【在 n******t 的大作中提到】
: 我觉得Java/Python/C#这些东西也还好把,其实这些算是创造新的工作机会。原来系统
: 级的开发,还是那些语言,职位也没减少,但是在开发这一行业的比重的确是变少了。
: 就我所知很多人是没法写出一个超过50000行能用的C程序的,但是能写出一个同样功能
: 的Java/Pyton/C#的人还是要多好多的.

相关主题
读Bjarne Stroustrup写得The C++ programming language 是不是经常有不知所谓的感觉。这么好的帖子没人转?
从今天开始起,学C++!怎么efficiently实现next_combination?
c++逐渐没落?也谈谈语言之争
进入Programming版参与讨论
n******t
发帖数: 4406
41
你的这个项目肯定是比较实在的东西吧。
我上一个东西大概只有8000多行,其中真正核心的地方只有不到2000行。
但是做application level的程序员,尤其是business application方面你得,50000行
其实不算大的,很多code还是generator生成的。很多时候都是business logic。

【在 t****t 的大作中提到】
: 50000行很多了, 我在公司做的这个项目做了好几年了也就四万行多点. 当然基本上就
: 我一个人维护.

t****t
发帖数: 6806
42
啥叫实在的东西...我是传统型码工, 不大用/不会用生成器, 可以算生成器的是lex/
yacc, 不过那个生成的代码我没算. 这个项目三部分: 一个运行引擎+脚本解释器(有完
整语法/语义), 13K行, 一个公用库(主要是滤波器), 14K行, 一堆分离的模块, 20K左
右. 第一部分算是核心. 对了这个是C++的, 会比C简洁很多.

【在 n******t 的大作中提到】
: 你的这个项目肯定是比较实在的东西吧。
: 我上一个东西大概只有8000多行,其中真正核心的地方只有不到2000行。
: 但是做application level的程序员,尤其是business application方面你得,50000行
: 其实不算大的,很多code还是generator生成的。很多时候都是business logic。

n******t
发帖数: 4406
43
就是和传统型码工差不多的意思。
大部分的application level的code是没有什么算法的,也不会直接做系统调用,基本上
主要是填写business logic,还有一些数据库的操作。

【在 t****t 的大作中提到】
: 啥叫实在的东西...我是传统型码工, 不大用/不会用生成器, 可以算生成器的是lex/
: yacc, 不过那个生成的代码我没算. 这个项目三部分: 一个运行引擎+脚本解释器(有完
: 整语法/语义), 13K行, 一个公用库(主要是滤波器), 14K行, 一堆分离的模块, 20K左
: 右. 第一部分算是核心. 对了这个是C++的, 会比C简洁很多.

t****t
发帖数: 6806
44
这分类...难道算法和系统调用就不是实在的东西? 我这个核心是多线程的, 算不算实
在的东西...

本上

【在 n******t 的大作中提到】
: 就是和传统型码工差不多的意思。
: 大部分的application level的code是没有什么算法的,也不会直接做系统调用,基本上
: 主要是填写business logic,还有一些数据库的操作。

b***i
发帖数: 3043
45
你这样想啊,本来java出现前,计算机产业就是发展迅速的,假设每年社会需要的C++
程序员都成指数增长,现在java, python, c#一下子把新的需求满足了,你原来C/C++
的程序员是还在维护原来的项目,但是职位的增长少多了。你再看java,从0需求到世界
第一语言了。所以不能光看绝对需求,要看相对的增长趋势。
而很多人能够写出超过5万行能用的java程序,确实是因为这就是技术进步,把工具做
方便了,而不是我们这些码工比以前人强。这就是我跟qxc说,这些新的语言对资本家
是真的有用的,所有大量的工作机会就在这里。
而对functional programming,我很不感冒。不过,以后主流语言或者新兴语言肯定会
逐渐加入一些functional programming。以后应该会有更多的需求的。

【在 n******t 的大作中提到】
: 我觉得Java/Python/C#这些东西也还好把,其实这些算是创造新的工作机会。原来系统
: 级的开发,还是那些语言,职位也没减少,但是在开发这一行业的比重的确是变少了。
: 就我所知很多人是没法写出一个超过50000行能用的C程序的,但是能写出一个同样功能
: 的Java/Pyton/C#的人还是要多好多的.

g*****g
发帖数: 34805
46
5万行不多,eclipse最新版本的源码有17Million行,21个项目,
310个程序员,19个不同国家。
Java最大的优势在于重用。任何有点可重用的东西都有现成开源
的可以用。软件的价值在于商业逻辑,而基础性的架构,或者utility
性质的东西,拿出来在开源社区维护是大家都有好处的事情。
我现在的项目里第三方的类库动辄超过100个。没有这些我没可能
把东西做出来。

【在 n******t 的大作中提到】
: 你的这个项目肯定是比较实在的东西吧。
: 我上一个东西大概只有8000多行,其中真正核心的地方只有不到2000行。
: 但是做application level的程序员,尤其是business application方面你得,50000行
: 其实不算大的,很多code还是generator生成的。很多时候都是business logic。

n******t
发帖数: 4406
47
你貌似没听懂我的意思。我觉得算法和系统调用比较密集的code算实在的。大部分的ap
plication level的programmer,几年下来会比40000行代码多很多,但是里面没有多少
是比较实在的东西。

【在 t****t 的大作中提到】
: 这分类...难道算法和系统调用就不是实在的东西? 我这个核心是多线程的, 算不算实
: 在的东西...
:
: 本上

c***d
发帖数: 996
48
留个名。。
我以前以为我自己是个程序员, 看了各位的讨论, 觉得自己离程序员这个行当是越来
越远了。

【在 t*s 的大作中提到】
: 刚刚无聊,想练练python, 就随便做了这个题。。。结果只用了9行代码,还是蛮有成
: 就感的
: from itertools import permutations,combinations
: c=0
: for fullpos in permutations(range(1,9),8):
: for i,j in combinations(range(1,9),2):
: if abs(i-j)==abs(fullpos[i-1]-fullpos[j-1]):
: break
: else:
: c+=1

t*s
发帖数: 1504
49
not a programmer myself...

【在 c***d 的大作中提到】
: 留个名。。
: 我以前以为我自己是个程序员, 看了各位的讨论, 觉得自己离程序员这个行当是越来
: 越远了。

j*********n
发帖数: 74
50


【在 g******n 的大作中提到】
: 茴香豆有四种写法。。。。。
相关主题
俺老10年前关于语言未来的论述我现在常用语言是LABVIEW和ACCESS
c++正在向夕阳语言大幅度迈进c++就像一个贼船
看到那么多Java黑C++虽然工作机会少一些,但没有新毕业生和你抢饭碗
进入Programming版参与讨论
s****m
发帖数: 160
51
+1

【在 c***d 的大作中提到】
: 留个名。。
: 我以前以为我自己是个程序员, 看了各位的讨论, 觉得自己离程序员这个行当是越来
: 越远了。

r********n
发帖数: 7441
52
六种!

【在 g******n 的大作中提到】
: 茴香豆有四种写法。。。。。
1 (共1页)
进入Programming版参与讨论
相关主题
JAVA还是挺可爱的从今天开始起,学C++!
自己看c++是不是夕阳语言c++逐渐没落?
没道理看不起Java 程序员这么好的帖子没人转?
这个行当真是没落了怎么efficiently实现next_combination?
程序员薪水也谈谈语言之争
问-最近几年流行的计算机语言会是什么?想学 (转载)俺老10年前关于语言未来的论述
C++ vs Javac++正在向夕阳语言大幅度迈进
读Bjarne Stroustrup写得The C++ programming language 是不是经常有不知所谓的感觉。看到那么多Java黑
相关话题的讨论汇总
话题: fullpos话题: range话题: abs