Buch Cover Buch Cover Buch Cover Buch Cover

Web-Code: - Webcode Help

Domino (Schleifen)

Schreiben Sie ein Programm, das alle möglichen Dominosteine (0|0), (0|1), …, (6|6) erzeugt. Dabei dürfen keine Duplikate auftreten: Wenn (3|5) schon erschienen ist, darf also (5|3) nicht mehr auftreten.

0 Kommentare

Bitte melde dich an um einen Kommentar abzugeben

39 Lösung(en)

/**
 * Erzeuge alle Dominosteine
 * @author Philipp Gressly (phi AT gressly DOT ch)
 */
public class Domino {
     public static void main(String[] args) {
        new Domino().start();
    }
 
    private void start() {
       int obereZahl, untereZahl;
       obereZahl = 0;
       while(obereZahl <= 6) {
           untereZahl = obereZahl; // keine Duplikate
           while(untereZahl <= 6 ) {
               System.out.println("("+ obereZahl + "|" + untereZahl+ ")");
               untereZahl = untereZahl + 1;
           }
           obereZahl = obereZahl + 1;
       }
    }
 
}  // end of class Domino

                        
                
$obereZahl = 0;
while($obereZahl <= 6) {
  $untereZahl = $obereZahl; // keine Duplikate
  while($untereZahl <= 6) {
    echo "(" . $obereZahl . "|" . $untereZahl . ") ";
    $untereZahl = $untereZahl + 1;
  }
  $obereZahl = $obereZahl + 1;
}
                
'lisp
(progn
  (set 'result "")
  (set 'obereZahl 0)
  (while (<= obereZahl 6)
    (progn
      (set 'untereZahl obereZahl) ; keine Duplikate 
      (while (<= untereZahl 6)
        (progn
          (set 'result
            (format "%s (%d|%d)"
                          result obereZahl untereZahl))
            (set 'untereZahl (+ untereZahl 1))))
      (set 'obereZahl (+ obereZahl 1))))
  result)
                
resultat  = ""
obereZahl =  0
while(obereZahl <= 6) {
  untereZahl = obereZahl // keine Duplikate
  while(untereZahl <= 6) {
    resultat   = resultat + " (" + obereZahl + "| " +
    untereZahl + "), "
    untereZahl = untereZahl + 1  }
  obereZahl = obereZahl + 1  }
window.alert(resultat)
                
obereZahl = 0
while (obereZahl <= 6)
  untereZahl = obereZahl # keine Duplikate
  while(untereZahl <= 6)
    print "(#{obereZahl}|#{untereZahl}), "
    untereZahl = untereZahl + 1
  end
  obereZahl = obereZahl + 1
end
                
# Domino
obereZahl = 0
while (obereZahl <= 6):
  untereZahl = obereZahl # keine Duplikate
  while(untereZahl <= 6):
    print "(", obereZahl, "|", untereZahl, "), "
    untereZahl = untereZahl + 1
  obereZahl = obereZahl + 1
                

Lösung von: Martin Guggisberg (Universität Basel / PH FHNW)

!/bin/bash

obereZahl=0
while [ ${obereZahl} -le 6 ]
do
  untereZahl=${obereZahl} #keine_Duplikate
  while [ ${untereZahl} -le 6 ]
  do
    echo "(${obereZahl}|${untereZahl})";
    untereZahl=`expr ${untereZahl} + 1`
  done
  obereZahl=`expr ${obereZahl} + 1`
done
                
 /* Programmiersprache: PL/I */
/* Autor: Bruno Keller */

 dcl i        bin fixed(31);
 dcl j        bin fixed(31);

 do i = 0 to 6;
    do j = i to 6;
       put skip edit('(',i,'|',j,')')(a,p'9',a,p'9',a);
    end;
 end;

                

Lösung von: Bruno Keller (Santis Training AG)

# dominosteiene 
# python3

steine = set()                    # eine Menge als Kontainer
for a in range(1,7):              # obere Zahl
    for b in range(a,7):          # untere Zahl ohne Duplikate
        steine.add((a,b))         # jeder Stein wird als Tuple gespeichert

for j in steine:
    print(j[0],j[1])
                

Lösung von: Frank Schneider ()

'Solution for VBA:

Sub Domino()
Dim i As Byte, j As Byte

For i = 0 To 6
    For j = i To 6
        Debug.Print i & "|" & j & vbCrLf
    Next j
Next i

End Sub
                

Lösung von: Felix Reinhold ()

/* Autor: ph. gressly */
/* Datum: 17. Mai 2011 */
/* Domino: Programmieraufgaben.ch. */

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

main() {
  int unten, oben;
  for(unten = 0; unten < 7; unten++) {
    for(oben = unten; oben < 7; oben++) {
      printf("(%d|%d)", unten, oben);
      if((6 > unten) || (6 > oben)) {
        printf(", ");
      }
    }
  }
}
                

Lösung von: Philipp G. Freimann (BBW (Berufsbildungsschule Winterthur) https://www.bbw.ch)

// Haskell / List comprehensions

[(x, y) | x <- [0..6], y <- [x..6]]
                

Lösung von: Reto Hablützel (www.rethab.ch)

class cGenerateDomino {
    
    /**
     * 
     * Für die Speicherung der Dominosteine
     * @var string enthält die Dominos
     */
    private $dominos;
    
    /**
     * 
     * Erstelle die Dominosteine
     * @return	string 	$dominos
     */
    public function _getDominos() {
        
        /**
         * Wiederhole solange wie $x kleiner gleich 6 ist
         */
        for ( $x=0; $x <= 6; $x++ ) {
            
            /**
             * Wiederhole solange wie $y kleiner gleich 6 ist
             */
            for ( $y=$x; $y <= 6; $y++ ) {
            
                 $this->dominos .= '(' . $x . '|' . $y . ')' . '<br />';
                 
            }
        }

        return $this->dominos;

    }

}

$objDom = new cGenerateDomino();
echo $objDom->_getDominos();
                

Lösung von: Name nicht veröffentlicht

*&---------------------------------------------------------------------*
*& Report  Z_DOMINO_STONES
*&
*&---------------------------------------------------------------------*
*&
*& ABAP KANN MAN LEIDER BISHER NICHT WÄHLEN
*& DARUM HAB ICH EINFACH GENERIC ANGECLICKT
*& IS ABER ABAP :-)
*&---------------------------------------------------------------------*

REPORT  Z_DOMINO_STONES.

TYPES:

BEGIN OF str_domst,
  x type c,
  y type c,
end of str_domst.

DATA: gt_stones TYPE STANDARD TABLE OF str_domst,
      ll_stones LIKE LINE OF gt_stones,
      ll_check LIKE ll_stones.

DATA: count1 TYPE i,
      count2 TYPE i.

DO 7 TIMES.
  DO 7 TIMES.


    ll_stones-x = count1.
    ll_stones-y = count2.

    READ TABLE gt_stones WITH TABLE KEY x = count2 y = count1 INTO ll_check.

    IF ll_check IS INITIAL.
      APPEND ll_stones TO gt_stones.
      WRITE: / count1,'/',count2.
    ENDIF.
   CLEAR ll_check.
   ADD 1 to count2.
  ENDDO.
  count2 = 0.
  ADD 1 to count1.
  CLEAR ll_check.
ENDDO.
                

Lösung von: Benjamin Kluszynski (( Coder :-) ))

# python list comprehension
print [ (i,j) for i in range(7) for j in range(7) if i <= j ]
                

Lösung von: dietmar berger ()

// Autor:				Andy Großhennig
// Solution for task:	Domino (Schleifen)

#include <iostream>

using namespace std;

void domino()
{
	for(short shFirst = 0;shFirst <= 6;shFirst++)
	{
		for(short shSecond = shFirst;shSecond <= 6;shSecond++)
		{
			cout << "[" << shFirst << "|" << shSecond << "]" << endl;
		}
	}
}

int main()
{
	domino();
	
	cout << "\n\n";
	system("Pause");
	return 0;
}
                

Lösung von: Andy Großhennig (Bundeswehr)

$a=0;
while($a < 7){
        $b=$a;
        while($b < 7){
                print "($a|$b)\n";
                $b++;
        }
        $a++;
}

                

Lösung von: Name nicht veröffentlicht

package ch.programmieraufgaben.iteration.domino;

// uses
// http://www.santis-training.ch/java/downloads/hilfsklassen/Sequencer.java
import static eu.gressly.util.Sequencer.card;
import static eu.gressly.util.Sequencer.range;

/**
 * Erzeuge alle Dominosteine
 * @author Philipp Gressly (phi AT gressly DOT eu)
 */
public class Domino {
  public static void main(String[] args) {
    new Domino().start();
  }

  private void start() {
    for(int obereZahl : card(6)) {
      for(int untereZahl : range(obereZahl, 6)) {
        System.out.println("( "+ obereZahl + " | " + untereZahl+ " )");
      }
    }
  }

}  // end of class Domino
                

Lösung von: Philipp G. Freimann (BBW (Berufsbildungsschule Winterthur) https://www.bbw.ch)

typeset -i i=0 j=0 nr=1
string=""

while ((i <= 6))
do
	while ((j <= 6))
	do
		string="("${i}"|"${j}") "${nr}
		echo $string	
		nr=nr+1
		j=j+1
	done
	i=i+1
	j=i
done
                

Lösung von: Benny H. ()

/**
 * Domino 
 */
public class Domino {
	public static void main(String[] args) {
		new Domino().top ();
	}

	void top() {
		for (int i = 0; i <=6; i++) {
			for (int j = i; j <= 6; j++) {
				System.out.println("(" + i + "|" + j + ")");
			}
		}
	} 

} // end of class Domino
                

Lösung von: Bruno Keller (Santis Training AG)

// Programmiersrpache: Go

package main

import "fmt"

func main() {
        for i := 0; i < 7; i++ {
                for j := i; j < 7; j++ {
                        fmt.Println("(", i, "|", j, ")")
                }
        }
}
                

Lösung von: Matthias Sayler (Bosch)

stones = []
(0..6).each do |i|
  (0..6).each do |j|
    if !(stones.include?("#{i}|#{j}".reverse))
      stones << "#{i}|#{j}"
    end
  end
end
                

Lösung von: Name nicht veröffentlicht

/**** REXX ************************************************************/
/*    EXEC zum Ausgeben aller Dominosteine                            */
/**********************************************************************/

obereZahl  = 0
untereZahl = 0

do while obereZahl <= 6
   untereZahl = obereZahl
   do while untereZahl <= 6
      say '(' || obereZahl || '|' || untereZahl || ')'
      untereZahl = untereZahl + 1
   end
   obereZahl = obereZahl + 1
end
                

Lösung von: Name nicht veröffentlicht

//F# 

let domino = 
    [for i in [0..6] 
        -> [for j in [i..6] -> (i, j)]]

domino
                

Lösung von: Vural Acar ()

var pips = [0, 1, 2, 3, 4, 5, 6],
    deck = [],
    i;

while (pips.length > 0) {
   for (i = 0; i < pips.length; i++)
      deck.push("(" + pips[0] + "|" + pips[i] + ")");
   pips.shift();
}
   
console.log(deck.join(", "));
                

Lösung von: Lisa Salander (Heidi-Klum-Gymnasium Bottrop)

{Erzeugt eine endliche Menge Dominosteine ohne Dublikate}
program Domino (input, output);
var

  ObereZahl,
  UntereZahl: integer;

begin

ObereZahl := 0;


  while ObereZahl <= 6 do
    begin
    UntereZahl := ObereZahl;
      while UntereZahl <= 6 do
        begin
          writeln(ObereZahl, '|', UntereZahl);
          UntereZahl := UntereZahl + 1;
        end;
    ObereZahl := ObereZahl + 1;
    end;
end.{Domino}

                

Lösung von: Name nicht veröffentlicht

{$R+}
{$B+}
{Syntax entspricht Programmierstil der FernUni in Hagen}

program Domino (input, output);
{ erzeugt sämtliche Dominosteine ohne Duplikate }

  var
  i,
  j: integer;
   
begin
  for i:= 0 to 6 do
    for j := i to 6 do
      writeln ('(',i,'|',j,')')
end. { Domino }

                

Lösung von: Name nicht veröffentlicht

#include <stdio.h>

/*
Schreiben Sie ein Programm, das alle möglichen Dominosteine (0|0), (0|1), …, (6|6) erzeugt. Dabei dürfen keine Duplikate auftreten: Wenn (3|5) schon erschienen ist, darf also (5|3) nicht mehr auftreten.
*/

int main(void)
{
    int firstIndex, secondIndex;
    for(firstIndex = 0; firstIndex < 7; firstIndex++)
        for(secondIndex = 6; secondIndex > -1; secondIndex--)
            if(secondIndex >= firstIndex)
                printf("[%i|%i]\n", firstIndex, secondIndex);   
    getchar();
    return 0;
}

                

Lösung von: Name nicht veröffentlicht

private static void domino()
{
    for (int i = 0; i < 7; i++)
        for (int j = 0; j < i + 1; j++)
            Console.WriteLine("{0}|{1}", j, i);
}
                

Lösung von: Remo Spichtig ()

for (var j = 0; j < 7; j++) { 
    console.log("(0|" + j + ")");
    } 
for (var j = 1; j < 7; j++) { 
    console.log("(1|" + j + ")");
    } 
for (var j = 2; j < 7; j++) { 
    console.log("(2|" + j + ")");
    } 
for (var j = 3; j < 7; j++) { 
    console.log("(3|" + j + ")");
    } 
for (var j = 4; j < 7; j++) { 
    console.log("(4|" + j + ")");
    } 
for (var j = 5; j < 7; j++) { 
    console.log("(5|" + j + ")");
    } 
for (var j = 5; j < 7; j++) { 
    console.log("(6|" + j + ")");
    } 
                

Lösung von: Irene Strauß (Liceo Scientifico, Bruneck)

public class Main {

    public static void main(String[] args) {
        List<String> isAvailable = new ArrayList<>();

        for(int i = 0, current = 0; i <= 6; i++) {
            for(int j = 0; j <= 6; j++) {
                if(!isAvailable.contains(i + ":" + j)) {
                    System.out.println(++current + ". " + "(" + i + "|" + j +")");
                    isAvailable.add(i + ":" + j);
                    isAvailable.add(j + ":" + i);
                }
            }
        }
    }
}
                

Lösung von: Name nicht veröffentlicht

for (var b = 0; b < 7; b++) {
for (var a = 0; a < 7; a++) {
if (a >= b) {
console.log("(" + b + " | " + a + ")");
}}}

                

Lösung von: Irene Strauß (Liceo Scientifico, Bruneck)

    class Program
    {
        static void Main(string[] args)
        {
            List<Domino> dominos = new List<Domino>();

            for (int a = 0; a <= 6; a++)
            {
                for (int b = 0; b < a + 1; b++)
                    dominos.Add(new Domino(a, b));
            }
        }
    }

    /// <summary>
    /// Beschreibt eine Objekt das einem Dominostein entspricht.
    /// </summary>
    public class Domino
    {
        public int TopNumber { get; private set; }
        public int BottomNumber { get; private set; }

        public Domino(int topNumber, int bottomNumber)
        {
            if(topNumber < 0 || topNumber > 6)
                throw new ArgumentException("The TopNumber can't be lower then 0 oder higher then 6.", nameof(topNumber));

            if(bottomNumber < 0 || bottomNumber > 6)
                throw new ArgumentException("The TopNumber can't be lower then 0 oder higher then 6.", nameof(topNumber));

            TopNumber = topNumber;
            BottomNumber = bottomNumber;
        }
    }
                

Lösung von: Name nicht veröffentlicht

# Autor:      Remo Spichtig
# Task:       Domino (Schleifen)

for i in range(0,7):
    for j in range(0,7):
        print("({0}|{1})".format(i,j))
                

Lösung von: remo spichtig (BBW)

#include "stdafx.h"
#include <iostream>

using namespace std;
int main()
{
	for (int i = 0; i <= 6; i++)
	{
		for (int j = 0; j <= 6; j++)
		{
			cout << "( " << i << " | " << j << " )";
		}
		cout << endl;
}
	system("PAUSE");
}
                

Lösung von: Name nicht veröffentlicht

L = []

for i in range(0, 7):
     for j in range(0, 7):
         if (i, j) not in L and (j, i) not in L:
             L.append((i, j))

print(L)
print("Steine: ", len(L))
                

Lösung von: Peter Pan (Home Office)

//Programmiersprache: RUST 

fn main() {
    let mut count: u8 = 1;

    for a in 0..=6 {
        for b in 0..=6 {
            if a >= b {
                println!("{}. ({}|{})", count, a, b);
                count += 1;
            }
        }
    }
}

                

Lösung von: Name nicht veröffentlicht

// NET 6.x | C# 10.x | VS-2022

// Lösung auch mittels O(n) möglich:

var m = 7;
var c = 4;

for (int i = 0; i < m; i++)
{
    Console.Write(string.Join("|", $"{i:00}".ToCharArray())+" ");
    if (i == m - 1)
    {
        m = i + 11;
        i += c++;
    }
}
                

Lösung von: Jens Kelm (@JKooP)

// C++20 | VS-2022
// 'MSVC std:c++20' only!

#include <iostream>
#include <vector>
#include <format>

struct domino {
    int lhs, rhs;
};

const auto get_dominos() {
	std::vector<domino>out;
	for (auto i{ 0 }; i < 7; ++i)
		for (auto k{ i }; k < 7; ++k)
			out.push_back({ i, k });
	return out;
}

const std::ostream& operator<<(std::ostream& os_, const domino& dom_) {
	os_ << std::string(9, '-') << "\n";
	os_ << std::format("| {} | {} |\n", dom_.lhs, dom_.rhs);
	os_ << std::string(9, '-') << "\n";
	return os_;
}

int main() {
	const auto dominos{ get_dominos() };
	std::cout << std::format("Anzahl Steine: {}\n\n", dominos.size());
	for(const auto& domino : dominos)
		std::cout << domino;
}
                

Lösung von: Jens Kelm (@JKooP)

Verifikation/Checksumme:

Das Programm liefert 28 verschiedene Teile.

Aktionen

Bewertung

Durchschnittliche Bewertung:

Eigene Bewertung:
Bitte zuerst anmelden

Meta

Zeit: 0.5
Schwierigkeit: k.A.
Webcode: 3ika-8b3t
Autor: Philipp G. Freimann (BBW (Berufsbildungsschule Winterthur) https://www.bbw.ch)

Zu Aufgabenblatt hinzufügen