Differences

This shows you the differences between two versions of the page.

programiranje:python_challenge:nivo_10 [2009/11/23 09:07] (current)
delboy created
Line 1: Line 1:
 +===== Python Challenge - Nivo 10 =====
 +U [[http://www.pythonchallenge.com/pc/return/bull.html|ovom nivou]] treba pronaci dužinu 30. člana niza koji je započet i koji može da se vidi klikom na vola na slici. Prvih 5 članova niza su 1, 11, 21, 1211, 111221.
 +U pitanju je [[http://en.wikipedia.org/wiki/Look-and-say_sequence|look-and-say sekvenca]].
 +
 +Kod je dosta prljav, ali radi :D
 +
 +<code python>
 +#!/usr/bin/env python
 +
 +def count(cur, dig, start):
 +    i = start
 +    count = 0
 +    while cur[i] == dig:
 +        i = i+1
 +        count = count + 1
 +        if i == len(cur): break
 +    return count, i
 +
 +
 +def next(cur):
 +    rez = ""
 +    i = 0
 +    while i < len(cur):
 +        dig = cur[i]
 +        c, i = count(cur, cur[i], i)
 +        rez = rez + str(c)
 +        rez = rez + dig
 +    return rez
 +
 +rez = "1"
 +for i in xrange(30):
 +    rez = next(rez)
 +
 +print len(rez)
 +</code>
 +
 +**Rešenje**: http://www.pythonchallenge.com/pc/return/5808.html
 
programiranje/python_challenge/nivo_10.txt · Last modified: 2009/11/23 09:07 by delboy
 
Except where otherwise noted, content on this wiki is licensed under the following license:CC Attribution-Noncommercial-Share Alike 3.0 Unported
Recent changes RSS feed Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki