10 or more phones order

Flemming Richter Mikkelsen quatrox at gmail.com
Mon Apr 28 16:20:23 CEST 2008


On 4/28/08, Pietro m0nt0 Montorfano <monto84 at gmail.com> wrote:
> Ilja O. ha scritto:
> >
> > >  So why's it not in Perl then,
> > >  You could do all that in a simple one-liner...
> > >
> > >  ;o)
> > >
> > >
> > >
> >
> > I don't know Perl :(
> > But I could try to write on z/OS HLASM. Or Erlang...
> >
> > Btw, it could be simple one-liner in Python too.
> > Like this:
> >  phone_count = 42
> >  _orders = ["BOX" for _i in xrange(phone_count // 10)] + ["SINGLE"
> > for _i in xrange(phone_count % 10)]
> >  print("Please, order %s" % ", ".join(_orders))
> >
> > Or if you want REALLY python one-liner:
> >
> exec("eJwryMjPS41Pzi/NK1GwVTAx4orPL0pJLSoGcqKVnPwjlBTS8osU4jMVMvMUKooS89JTNQqQtOjrKxgaaMYqaANVB3v6ufu4EtCgClbPVVCUmVeioRSQk5pYnKqjALZTQbVYCSivpKOgpJeVn5mnAXWKpiYAGp0z4g==".decode("base64").decode("zip"))
> >
> >
>
> Oh My God!!!!
>
> It was just the moment, it was because it's passed some time since i stopped
> using C at work i think, it could be python, perl, bash, php, c, c++, basic,
> javascript, ASM, also java (i don't like it),..... :D
>
> It was the moment :D

All the code can be written with standard cut (the Unix command).
But here is the C code:

/* input: the number of Freerunners */
/* returns the total netto Openmoko price for Freerunners */
unsigned long get_price(unsigned short no)
{
  unsigned long price=0;

  while (no%10)
  {
      price += 399;
      no--;
  }
  while (no)
  {
      price += 9*399;
      no -= 10;
  }
  return price;
}
-- 
Please don't send me Word or PowerPoint attachments.
See http://www.gnu.org/philosophy/no-word-attachments.html

Join the FSF as an Associate Member at:
<URL:http://www.fsf.org/register_form?referrer=5774>

Free your mind - Open(moko) your phone




More information about the community mailing list