User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the Software Developers' Lounge section within the Software Development category of DaniWeb, a massive community of 391,905 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,563 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our Software Developers' Lounge advertiser:
Views: 12236 | Replies: 81
Reply
Join Date: May 2006
Location: Ontario, Canada
Posts: 18
Reputation: Jessehk is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 2
Jessehk's Avatar
Jessehk Jessehk is offline Offline
Newbie Poster

Re: 500 ways to print [1..10]!

  #41  
Aug 4th, 2006
I just started teaching myself O'Caml

let rec range s f =
    if s > f then []
    else s :: range (s + 1) f ;;

let count s f = 
    List.iter (fun i -> Printf.printf "%d " i) (range s f)  ;;

count 1 10 ;;
Last edited by Jessehk : Aug 4th, 2006 at 11:01 pm.
--Jessehk
Reply With Quote  
Join Date: Jul 2006
Location: Deptford, London
Posts: 936
Reputation: MattEvans has a spectacular aura about MattEvans has a spectacular aura about 
Rep Power: 5
Solved Threads: 47
Moderator
Featured Poster
MattEvans's Avatar
MattEvans MattEvans is offline Offline
Posting Shark

Re: 500 ways to print [1..10]!

  #42  
Sep 1st, 2006
XML/XSLT

I guess XML isn't a language, and XSLT doesn't have to be, but this is certainly programmatic. It requires an input XML file and produces an HTML output file with the numbers one to ten separated by line breaks. The elements in the XML input file are irrelevant, as long as the root element is called "lots", and every "lots" element contains one more "lots" element than its parent. Until you get to ten of course.

Here's the input file (lots.xml)

<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="countem.xsl"?>
<lots>
  <lots><lots><lots>
  <lots><lots><lots>
  <lots><lots><lots>
  <right /><what /><we /><are /><going /><to />
  <do /><here /><is  /><create /></lots><of />
  <elements /><infact /><they /><are /><xml />
  <elements /><and /></lots><of /><them /><are />
  <in /><this /><file /><yes /></lots><of /><em />
  <doesnt /><matter /><whats /><in /></lots><of />
  <them /><because /><most /><infact /></lots><of />
  <them /><are /><just /></lots><and /><thats />
  <got /></lots><of /><importance /></lots><and />
  </lots>
</lots>

And heres the XSLT stylesheet:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
 
    <xsl:template match="/">
        <html>
            <head><title>Count to ten!</title></head>
            <body>
                <xsl:apply-templates select="lots"/>
            </body>
        </html>
    </xsl:template>
 
    <xsl:template match="lots">
        <xsl:value-of select="count(*)"/>
        <br />
        <xsl:apply-templates select="lots"/>
    </xsl:template>
</xsl:stylesheet>

Matt
Last edited by MattEvans : Sep 1st, 2006 at 3:20 am.
If it only works in Internet Explorer; it doesn't work.
Reply With Quote  
Join Date: Jul 2006
Location: Deptford, London
Posts: 936
Reputation: MattEvans has a spectacular aura about MattEvans has a spectacular aura about 
Rep Power: 5
Solved Threads: 47
Moderator
Featured Poster
MattEvans's Avatar
MattEvans MattEvans is offline Offline
Posting Shark

Re: 500 ways to print [1..10]!

  #43  
Sep 1st, 2006
By programming myBrain (in real-time) to use the "handwriting" library : system requirements included "pencil" and "paper" : tested in the "my kitchen" environment only.

Yep that's right, I wrote down the numbers 1 to 10 on a piece of paper. It had a very short implementation time, and I even drew a squiggly line around the numbers when I'd finished.

I unfortunately can't provide any evidence to support this feat - you'll just have to trust me.

Matt
If it only works in Internet Explorer; it doesn't work.
Reply With Quote  
Join Date: Jun 2005
Location: Novi Sad, Serbia
Posts: 273
Reputation: andor has a spectacular aura about andor has a spectacular aura about andor has a spectacular aura about 
Rep Power: 6
Solved Threads: 29
andor's Avatar
andor andor is offline Offline
Posting Whiz in Training

Re: 500 ways to print [1..10]!

  #44  
Sep 1st, 2006
MIPS assembler. Using SPIM simulator
.data
str1: .asciiz "1 2 3 4 5 6 7 8 9 10"
.globl main                            
.text                                  
                                       
main:
   la $a0, str1                   # load string address into $a0 and I/O code into $v0     
   li $v0, 4            
   syscall                          # execute the syscall to perform input/output 
                                      # via the console
                                    
   li $v0, 10                      # syscall code 10 for terminating the program
   syscall
If you want to win, you must not loose (Alan Ford)
Reply With Quote  
Join Date: Feb 2006
Location: UK
Posts: 468
Reputation: Bench has a spectacular aura about Bench has a spectacular aura about Bench has a spectacular aura about 
Rep Power: 5
Solved Threads: 42
Bench's Avatar
Bench Bench is offline Offline
Posting Pro in Training

Re: 500 ways to print [1..10]!

  #45  
Sep 4th, 2006
Just been playing about with C++ Templates, and thought of this thread
(By the way, only 44 posts?! we can do better than that...! )
#include <iostream>

template<int i> void count()
{
    std::cout << i << std::endl;
    count<i+1>();
}

template<> void count<10>()
{
    std::cout << 10 << std::endl;
}

int main()
{
    count<1>();
} 
Last edited by Bench : Sep 4th, 2006 at 5:56 pm.
¿umop apisdn upside down?
Reply With Quote  
Join Date: May 2006
Location: Ontario, Canada
Posts: 18
Reputation: Jessehk is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 2
Jessehk's Avatar
Jessehk Jessehk is offline Offline
Newbie Poster

Re: 500 ways to print [1..10]!

  #46  
Sep 4th, 2006
Originally Posted by Bench View Post
(By the way, only 44 posts?! we can do better than that...! )


That we can. On the forum where I stole this idea, we got to 500.

#include <iostream>

template <int n>
class Counter {
    public:
        Counter() {
            Counter<n - 1> count;
            std::cout << n << std::endl;
        }
};

template <>
class Counter<0> {
    public:
        Counter() {}
};

int main() {
    Counter<10> count;
}

EDIT: I'm in shock! I'm sorry that my code is so similar to yours. It was a complete coincidence. :eek:
Last edited by Jessehk : Sep 4th, 2006 at 9:33 pm.
--Jessehk
Reply With Quote  
Join Date: Feb 2006
Location: UK
Posts: 468
Reputation: Bench has a spectacular aura about Bench has a spectacular aura about Bench has a spectacular aura about 
Rep Power: 5
Solved Threads: 42
Bench's Avatar
Bench Bench is offline Offline
Posting Pro in Training

Re: 500 ways to print [1..10]!

  #47  
Sep 6th, 2006
Originally Posted by Jessehk View Post
EDIT: I'm in shock! I'm sorry that my code is so similar to yours. It was a complete coincidence. :eek:
heh, I think you can claim that yours is a more OO version
¿umop apisdn upside down?
Reply With Quote  
Join Date: Sep 2006
Posts: 5
Reputation: srinivasdama is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
srinivasdama srinivasdama is offline Offline
Newbie Poster

Re: 500 ways to print [1..10]!

  #48  
Sep 6th, 2006
#include<stdio.h>
void main(){
static
Reply With Quote  
Join Date: Jun 2005
Location: Novi Sad, Serbia
Posts: 273
Reputation: andor has a spectacular aura about andor has a spectacular aura about andor has a spectacular aura about 
Rep Power: 6
Solved Threads: 29
andor's Avatar
andor andor is offline Offline
Posting Whiz in Training

Re: 500 ways to print [1..10]!

  #49  
Sep 6th, 2006
Originally Posted by srinivasdama View Post
#include<stdio.h>
void main(){
static

I think you should edit this
If you want to win, you must not loose (Alan Ford)
Reply With Quote  
Join Date: Sep 2006
Posts: 5
Reputation: srinivasdama is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
srinivasdama srinivasdama is offline Offline
Newbie Poster

Re: 500 ways to print [1..10]!

  #50  
Sep 6th, 2006
#include<stdio.h>
void main(){
static int i =0;
while(++i<=10){
printf("%d\n",i);
main();
}
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

DaniWeb Software Developers' Lounge Marketplace
Thread Tools Display Modes

Other Threads in the Software Developers' Lounge Forum

All times are GMT -4. The time now is 7:37 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC