# 500 Ways to Print 1 to 10

Show 40 post(s) from this thread on one page
Page 6 of 6 First ... 456
• December 10th, 2013, 19:42
Bethany Ferrell
Re: 500 Ways to Print 1 to 10
How to count to ten in Yan Tan Tethera

Java this time, counting to ten in the Derbyshire variant of the old sheep-counting language based on ancient vigesimal, or base-20, Celtic number names. If you've read Terry Pratchett's stories about the adventures of young witch Tiffany Aching and the Nac Mac Feegle (the roughest, most criminally inclined fairies of all time), you'll recognize these as the ones used by shepherds on the Chalk in Discworld. Tiffany, being her twentieth grandchild, is called "little jiggit" by her sheep-herding grandmother.

Since these number names include pairs of rhyming words, it seemed a good choice for a non-obvious (silly, even) implementation. Five and ten are unique words, so the "prefixes" array contains their translations in full. All other numbers from one to ten are composed of an initial letter followed by one of just three suffixes (or blank for five and ten). To get a full name, combine a prefix with matching suffix. To avoid duplicating suffixes, we iterate through an array of indices into the suffixes array, rather than the suffixes array itself.

Code java:

```public class YanTanTethera { public static void main(String[] args) { String[] prefixes = {"y", "t", "t", "m", "pip", "s", "l", "h", "d", "dick"}; String[] suffixes = {"an", "ethera", "overa", ""}; int[] suffix_for_num = {0, 0, 1, 1, 3, 1, 1, 2, 2, 3}; for (int i = 1; i<=10; i++) { System.out.println(prefixes[i-1]+suffixes[suffix_for_num[i-1]]); } } }```

Output:
yan
tan
tethera
methera
pip
sethera
lethera
hovera
dovera
dick

This is just one dialect of yan tan tethera. There are many more, some quite similar, others more varied. Anyone sufficiently intrigued can try adapting the above to other dialects. Much more information can be found at:

Yan tan tethera - Wikipedia, the free encyclopedia
• December 23rd, 2013, 08:28
circleline
Re: 500 Ways to Print 1 to 10
[java]Hello[/java]

--- Update ---

Hope I didn't copy anyone. Hah!

Code :

``` class kevi{   public static void main(String args[]){   int onetoten;   for(onetoten=0;onetoten<=100;onetoten+=10){   System.out.print("\t" +onetoten/10);   }   }     }```

Output:

Quote:

0 1 2 3 4 5 6 7 8 9 10
• January 14th, 2014, 02:36
philip12
Re: 500 Ways to Print 1 to 10
Hope this one counts..

Code :

```public static void main(String[] args) { int number = 0; recursion(number); }   public static void recursion(int number) { if (number <= 10) { System.out.println(number); number++; recursion(number); } }```
• January 22nd, 2014, 04:48
verilocos
Re: 500 Ways to Print 1 to 10
Quote:

Originally Posted by helloworld922
don't know if this counts.

6. Java
Code :

```public class OneToTen { public static void main(String[] args) { System.out.println("1 2 3 4 5 6 7 8 9 10"); } }```

The ultimate neat solution ever, IMHO.
• April 14th, 2014, 05:18
Niels van Ee
System.out.println("1")
System.out.println("2")
Etc.

This easy it is...

But im going to make a harder one at home.
• June 2nd, 2014, 03:20
Re: 500 Ways to Print 1 to 10
Not sure if this method have been attempted:

Code :

```package mycounting.pkg; public class MainClass { public static void main(String[] args) { Counter count = new Counter(1); count.printNumbers();   } }   // other .class file -===========- package mycounting.pkg; import javax.swing.JOptionPane;   public class Counter { private int number;   public Counter(int defNumber) { if ((defNumber <= 0) || (defNumber > 1)) number = defNumber;   number = defNumber; }   public void printNumbers() { int loop = 1;   do { JOptionPane.showMessageDialog(null, this.number); ++loop; } while (loop <= 10);   } }```

Cryptic way of doing it using the ADA language:

Code :

``` -- program to add 1 to a declared local variable X procedure print_test -- first procedure begin Text_IO.Put_Line( "This will print the numbers 1 through 10" ); int_value : Integer = X;   While_Loop : while X <= 10 loop Put_Line( & AddOne(X) ); end loop While_Loop; end print_test; -- terminate first procedure   -- method to add one to the passed parameter argument X -- then return it to the calling function X is not a Pointer function AddOne( X : integer ) return integer is begin return X+1; end AddOne;```

Forgive me if the syntax isn't 100% - I haven't used the
ADA language science 1995's revision of it. It's probably
changed since then too. Anyways - just my two cents.

• June 3rd, 2014, 16:12
Re: 500 Ways to Print 1 to 10
Here is why I am glad to not be working with pointers anymore:

Code :

```#include <stdio.h>   int main() { int *ptr = NULL; int temp = 1; ptr = &temp; int x; // C99   for (x = 1; x <= 10; ++x) { printf("%d ", *ptr); ++(*ptr); } }```

Sorry I had to make a double post - the "edit" button was craning Fire fox for some reason.

• August 1st, 2014, 06:47
Harmone
Re: 500 Ways to Print 1 to 10
Python.
Code Python:

```x = [1, 2,...10]; print(x);```
(Unfortunately, it doesn't seem to display 'Python', even though I've 'Highlight=Python'.)
• March 4th, 2015, 07:39
yko
Re: 500 Ways to Print 1 to 10
shell

Code shell:

```#!/bin/sh   NUM=1 while [ \$NUM -ne 11 ] do echo "\$NUM" NUM=\$((\$NUM+1)) done```
• March 4th, 2015, 09:33
Re: 500 Ways to Print 1 to 10
Quote:

Originally Posted by yko
shell

Code shell:

```#!/bin/sh   NUM=1 while [ \$NUM -ne 11 ] do echo "\$NUM" NUM=\$((\$NUM+1)) done```

Clever. Is that assembly language? I know 'echo' is a terminal print command ;)

• August 10th, 2015, 04:45
Frigidus
Re: 500 Ways to Print 1 to 10
Code java:

```public class Print { public static void main(String[]args){ Print(); } static void Print(){ System.out.print("1\n" + "2\n" + "3\n" + "4\n" + "5\n" + "6\n" + "7\n" + "8\n" + "9\n" + "10\n"); } }```
• October 23rd, 2015, 03:25
Re: 500 Ways to Print 1 to 10
Another C version.

Code :

```#include <stdio.h> #include <string.h>   int main() { char arr[11] = {10, ,9, 8, 7, 6, 5, 4, 3, 2, 1}; strrev(arr); printf(" %c", arr); }```

```class onetoten{   public static void number(int number){ System.out.print(number+" "); }   public static void main(String[] args) { for(int i = 1; i <= 10; i++) { number(i); } } }```