Supporta il tuo Forum su Patreon!
 
  > Register  
  > Calendar  
  > Member List  
 
  > Support your Forum  
  > Today's Posts  
   

Go Back   netgamers.it > Tech & Tech > Developer's Zone

Reply
 
Thread Tools Rate Thread
Old 29th May 2007, 23:14   #31
The Big
Armata Baccanale
 
The Big's Avatar
 
Join Date: Apr 2003
Location: /home/carlesso
Posts: 4,129
1342/10%10%10 non ti piace vero?
__________________
The Big: the e.gmail filler Xperience
OK, so you're a Ph.D. Just don't touch anything.
Il mio sito, e il mio blog
The Big is offline   Reply With Quote
Old 29th May 2007, 23:18   #32
The Big
Armata Baccanale
 
The Big's Avatar
 
Join Date: Apr 2003
Location: /home/carlesso
Posts: 4,129
Ah, mettetevi in Italia, il mio nick e' carlesso... voi?
__________________
The Big: the e.gmail filler Xperience
OK, so you're a Ph.D. Just don't touch anything.
Il mio sito, e il mio blog
The Big is offline   Reply With Quote
Old 30th May 2007, 00:44   #33
Aresio
Soft computer
 
Aresio's Avatar
 
Join Date: Feb 2000
Posts: 540
Code:
int pow (int n, int e) {
    if (e)  return n*pow(n, e-1);
    else    return 1;
}

int lun (int n) {
    if (n)  return 1+lun(n/10);
    else    return 0; 
}

void main() {
  int risultato = input/pow(10, lun(input)-quale)%10;
}
con input e quale le due variabili in ingresso?
__________________
Lode a Bacco, in saecula saeculorum.
Emergent
Aresio is offline   Reply With Quote
Old 30th May 2007, 00:51   #34
.Z.
fork()
 
.Z.'s Avatar
 
Join Date: Jan 2002
Location: Bologna
Posts: 13,783
lun la definirei come
Code:
int lun (int n) {
    if (n < 10) return 1;
    return 1 + lun (n / 10);
}
Per il resto è perfetto, devo solo capire come fare a non usare un double, senò ovviamente non gli garba il %.

Qual'è l'int più lungo secondo l'ansi C?
__________________
Personally, I would never want to be a member of any group where you either have to wear a hat, or you can't wear a hat.
.Z. is offline   Reply With Quote
Old 30th May 2007, 00:54   #35
Aresio
Soft computer
 
Aresio's Avatar
 
Join Date: Feb 2000
Posts: 540
dipende dal processore c'è anche long long int... puoi usare sizeof di un puntatore per saperlo.
__________________
Lode a Bacco, in saecula saeculorum.
Emergent
Aresio is offline   Reply With Quote
Old 30th May 2007, 01:17   #36
.Z.
fork()
 
.Z.'s Avatar
 
Join Date: Jan 2002
Location: Bologna
Posts: 13,783
Devo farci stare il fattoriale di 100:
Code:
93326215443944152681699238856266700490715968264381621468592963895217599993229915608941463976156518286253697920827223758251185210916864000000000000000000000000


Non ci sta mi tocca uscire dall'ansi C

Userò floor
__________________
Personally, I would never want to be a member of any group where you either have to wear a hat, or you can't wear a hat.

Last edited by .Z.; 30th May 2007 at 01:19.
.Z. is offline   Reply With Quote
Old 30th May 2007, 01:57   #37
.Z.
fork()
 
.Z.'s Avatar
 
Join Date: Jan 2002
Location: Bologna
Posts: 13,783
Non ci sta in un long double?
__________________
Personally, I would never want to be a member of any group where you either have to wear a hat, or you can't wear a hat.
.Z. is offline   Reply With Quote
Old 30th May 2007, 09:14   #38
Aresio
Soft computer
 
Aresio's Avatar
 
Join Date: Feb 2000
Posts: 540
http://en.wikipedia.org/wiki/Long_double

"dipende"
__________________
Lode a Bacco, in saecula saeculorum.
Emergent
Aresio is offline   Reply With Quote
Old 30th May 2007, 10:12   #39
.Z.
fork()
 
.Z.'s Avatar
 
Join Date: Jan 2002
Location: Bologna
Posts: 13,783
Su un long double a 12 byte non ci sta.

Comincio a pensare che sia fatto apposta: il problema non è recuperare le singole cifre dato il numero, ma saper calcolare l'i-esima cifra di un fattoriale senza calcolare il fattoriale completo.

__________________
Personally, I would never want to be a member of any group where you either have to wear a hat, or you can't wear a hat.
.Z. is offline   Reply With Quote
Old 30th May 2007, 13:07   #40
The Big
Armata Baccanale
 
The Big's Avatar
 
Join Date: Apr 2003
Location: /home/carlesso
Posts: 4,129
Io che sono lamer, e soprattutto poco esperto di ci, certe cose le faccio in java
__________________
The Big: the e.gmail filler Xperience
OK, so you're a Ph.D. Just don't touch anything.
Il mio sito, e il mio blog
The Big is offline   Reply With Quote
Old 31st May 2007, 09:14   #41
Analizzator
Mobster
 
Analizzator's Avatar
 
Join Date: Feb 2000
Location: vietnam
Posts: 6,390
n= numero di cifre
1) ultima cifra = numero/10^n
2) numero = numero % 10^n
3) n--
sennò cerca delle implementazioni di itoa(int to ascii in c) e vedi varie soluzioni a codesto problema.
Il floor serve solo se hai un float e lo vuoi dividere eprendere la parte intera inferiore se dividi un intero i decimali spariscono e basta.
ciao.
__________________
[FICT]Analizzator in T2
[FICT]GrandeYogurt in Jk2
11^analamma in T2 Classic

Analizzator is offline   Reply With Quote
Old 3rd June 2007, 01:43   #42
Darklord
lupetto supremo
 
Darklord's Avatar
 
Join Date: Mar 1999
Location: Bari
Posts: 12,829
tornato a casa stanotte non sapevo che fare ed ho riaperto il sito di project euler

Mia soluzione superveloce al 7° quesito:
Code:
def findPrime(limit):
    import math
    n=3
    pList = [2,]
    while len(pList)<limit:
        for x in pList[:int(math.sqrt(len(pList)))]:
            if not(n%x): break
        else: pList.append(n)
        n+=2
    return max(pList)


print findPrime(10001)
troppo elegante python

edit: Quesito nove...usando un po' di nerdume python come i generatori, le list comprehnsions e le funzie lambda
Code:
def tpIterator():
    m,n=2,1
    while True:
        while m>n:
            yield m**2-n**2, 2*m*n, m**2+n**2
            n+=1
        m,n = m+1,1
        
mul = lambda x,y,z:x*y*z

if __name__ == '__main__':
    tp = tpIterator()
    n=(0,0,0)
    while sum(n) <> 1000: n=tp.next()
    
    print mul(*[x for x in n])
__________________
Python-foo Black Belt
NGI Forum
» Tech & Tech » Developer's Zone

Last edited by Darklord; 3rd June 2007 at 18:31.
Darklord is offline   Reply With Quote
Old 3rd June 2007, 23:31   #43
The Big
Armata Baccanale
 
The Big's Avatar
 
Join Date: Apr 2003
Location: /home/carlesso
Posts: 4,129
Quando la bash e' secoli avanti...

Problema 40:
Code:
#!/bin/bash

CHAIN=$(seq -s '' 250000)

echo ${CHAIN:0:1} \* ${CHAIN:9:1} \* ${CHAIN:99:1} \* ${CHAIN:999:1} \* ${CHAIN:9999:1} \* ${CHAIN:99999:1} \* ${CHAIN:999999:1} | bc
__________________
The Big: the e.gmail filler Xperience
OK, so you're a Ph.D. Just don't touch anything.
Il mio sito, e il mio blog
The Big is offline   Reply With Quote
Old 4th June 2007, 18:42   #44
Darklord
lupetto supremo
 
Darklord's Avatar
 
Join Date: Mar 1999
Location: Bari
Posts: 12,829
risolvere il quesito 16 con python è praticamente un cit

Code:
reduce(lambda x,y:int(x)+int(y),list(str(2**1000)))
edit...anche il 20 ed il 48 sono degli one-liners in python
ecco il 48:
Code:
str(sum([x**x for x in xrange(1,1001)]))[-10:]
__________________
Python-foo Black Belt
NGI Forum
» Tech & Tech » Developer's Zone

Last edited by Darklord; 4th June 2007 at 19:37.
Darklord is offline   Reply With Quote
Old 8th June 2007, 11:05   #45
ksn
:3
 
ksn's Avatar
 
Join Date: Apr 2003
Location: ಠ_ಠ
Posts: 16,640
non capisco perche' lo stesso programma per il 12 fatto in c ci mette 7.02 secondi a trovare il numero con almeno 500 divisori invece in python dopo 20 secondi inizia ad impallarmi tutto il pc
programma identico eh, semplicemente portato con le due sintassi
__________________
- If you're playing poker and you're also drunk then by many conventional measures you're already a winner.
ksn is offline   Reply With Quote
Reply

Tags
euler, matematica

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 03:17.



Copyright 2017-2024 by netgamers.it