www.vorhilfe.de
Vorhilfe

Kostenlose Kommunikationsplattform für gegenseitige Hilfestellungen.
Hallo Gast!einloggen | registrieren ]
Startseite · Forum · Wissen · Kurse · Mitglieder · Team · Impressum
Forenbaum
^ Forenbaum
Status Vorhilfe
  Status Geisteswiss.
    Status Erdkunde
    Status Geschichte
    Status Jura
    Status Musik/Kunst
    Status Pädagogik
    Status Philosophie
    Status Politik/Wirtschaft
    Status Psychologie
    Status Religion
    Status Sozialwissenschaften
  Status Informatik
    Status Schule
    Status Hochschule
    Status Info-Training
    Status Wettbewerbe
    Status Praxis
    Status Internes IR
  Status Ingenieurwiss.
    Status Bauingenieurwesen
    Status Elektrotechnik
    Status Maschinenbau
    Status Materialwissenschaft
    Status Regelungstechnik
    Status Signaltheorie
    Status Sonstiges
    Status Technik
  Status Mathe
    Status Schulmathe
    Status Hochschulmathe
    Status Mathe-Vorkurse
    Status Mathe-Software
  Status Naturwiss.
    Status Astronomie
    Status Biologie
    Status Chemie
    Status Geowissenschaften
    Status Medizin
    Status Physik
    Status Sport
  Status Sonstiges / Diverses
  Status Sprachen
    Status Deutsch
    Status Englisch
    Status Französisch
    Status Griechisch
    Status Latein
    Status Russisch
    Status Spanisch
    Status Vorkurse
    Status Sonstiges (Sprachen)
  Status Neuerdings
  Status Internes VH
    Status Café VH
    Status Verbesserungen
    Status Benutzerbetreuung
    Status Plenum
    Status Datenbank-Forum
    Status Test-Forum
    Status Fragwürdige Inhalte
    Status VH e.V.

Gezeigt werden alle Foren bis zur Tiefe 2

Navigation
 Startseite...
 Neuerdings beta neu
 Forum...
 vorwissen...
 vorkurse...
 Werkzeuge...
 Nachhilfevermittlung beta...
 Online-Spiele beta
 Suchen
 Verein...
 Impressum
Das Projekt
Server und Internetanbindung werden durch Spenden finanziert.
Organisiert wird das Projekt von unserem Koordinatorenteam.
Hunderte Mitglieder helfen ehrenamtlich in unseren moderierten Foren.
Anbieter der Seite ist der gemeinnützige Verein "Vorhilfe.de e.V.".
Partnerseiten
Dt. Schulen im Ausland: Mathe-Seiten:

Open Source FunktionenplotterFunkyPlot: Kostenloser und quelloffener Funktionenplotter für Linux und andere Betriebssysteme
Forum "Mathematica" - c++ code in mathematica?
c++ code in mathematica? < Mathematica < Mathe-Software < Mathe < Vorhilfe
Ansicht: [ geschachtelt ] | ^ Forum "Mathematica"  | ^^ Alle Foren  | ^ Forenbaum  | Materialien

c++ code in mathematica?: Frage (beantwortet)
Status: (Frage) beantwortet Status 
Datum: 19:54 Di 11.12.2007
Autor: skalar

Aufgabe
c++ in mathematica

ich möchte diesen C++ code in wolframs mathematica zum laufen bringen

wer kann mir helfen?

----------------------
#include <iostream>
using namespace std;
    
int start[9][9] =
{
   { 0, 0, 6, 9, 0, 4, 7, 0, 1 },
   { 3, 1, 9, 0, 2, 0, 0, 0, 0 },
   { 0, 0, 0, 1, 5, 0, 0, 6, 2 },
   { 2, 0, 4, 0, 0, 0, 5, 0, 9 },
   { 7, 6, 0, 4, 0, 0, 0, 2, 0 },
   { 0, 0, 0, 0, 0, 0, 0, 0, 4 },
   { 0, 8, 0, 0, 0, 7, 0, 4, 0 },
   { 0, 0, 0, 0, 0, 8, 0, 9, 5 },
   { 0, 0, 2, 0, 0, 0, 3, 0, 0 }
};
    
bool isfine(int feld[9][9], int x, int y)
{
   // doppelte Zahl in Zeile oder Spalte?
   for (int yi = 0; yi < 9; yi++)
       if (yi != y && feld[x][yi] == feld[x][y])
           return false;
   for (int xi = 0; xi < 9; xi++)
       if (xi != x && feld[xi][y] == feld[x][y])
           return false;
  
   // Neuner-Kästchen-Test
   int x1 = (x / 3) * 3;
   int y1 = (y / 3) * 3;
   for (int xk = x1; xk < x1 + 3; xk++)
       for (int yk = y1; yk < y1 + 3; yk++)
           if ((xk != x || yk != y) && feld[xk][yk] == feld[x][y])
               return false;
  
   return true;
}
    
bool nextone(int feld[9][9], int x, int y)
{
   if (y == 9) { y = 0; x++; };
   if (x == 9) return true;
  
   if (feld[x][y] > 0)
   {
        if (!isfine(feld, x, y)) return false;
       return nextone(feld, x, y + 1);
   }
   else for (feld[x][y] = 1; feld[x][y] <= 9; feld[x][y]++)
   {
       if (!isfine(feld, x, y)) continue;
       if (nextone(feld, x, y + 1)) return true;
   }
   feld[x][y] = 0;
   return false;
};
    
int main(int argc, char **argv)
{
   if (nextone(start, 0, 0))
   {
        for (int x = 0; x < 9; x++)
        {
        for (int y = 0; y < 9; y++)
                cout << start[x][y];
        cout << endl;
        }
   }
   else
        cout << "Dieses Rätsel ist nicht lösbar!" << endl;
      
   getchar();
   return 0;
}

        
Bezug
c++ code in mathematica?: mit RunThrough geht's
Status: (Antwort) fertig Status 
Datum: 11:21 Mi 19.12.2007
Autor: Peter_Pein

Hallo Sebastian,

mit der folgenden Änderung an der Funktion main() kann man das Programm sowohl für die Konsole, als auch (über Pipe) zur Verwendung aus Mathematica heraus übersetzen:

1: int main(int argc, char **argv) 
2: {
3: int mma;
4:
5: if(argc==1) mma= 0; else mma =(argv[1][0] == 'm');
6:
7:     if (nextone(start, 0, 0)) 
8:    { 
9: if (mma) cout << "{";
10:         for (int x = 0; x < 9; x++) 
11:         { 
12:         for (int y = 0; y < 9; y++)
13:                 cout << start[x][y] << (mma ? "," : " ");
14: if (! mma) cout << endl;
15: }
16:     if (mma) cout << "0}\n"; 
17:     
18:    } 
19:    else 
20:         cout << "Dieses Rätsel ist nicht lösbar!" << endl; 
21:        
22: //   getchar(); 
23:    return 0; 
24: }


In Mathematica rufen z.B. die folgenden Zeilen das Program auf, interpretieren das Ergebnis und zeigen es an:

1: ergebnis=RunThrough["E:\\Quelltexte\\sudoku.exe m",0];
2: If[Head[ergebnis]===String,ergebnis,MatrixForm[Partition[ergebnis,9]]]


Den Pfad zum Programm musst Du natürlich anpassen

Peter

P.S.: Ein übersetzen nach Mathematica halte ich nicht für sinnvoll (wenn man schon ein funktionierendes schnelles Programm hat....)
[Dateianhang nicht öffentlich]


Dateianhänge:
Anhang Nr. 1 (Typ: png) [nicht öffentlich]
Bezug
                
Bezug
c++ code in mathematica?: Mitteilung
Status: (Mitteilung) Reaktion unnötig Status 
Datum: 23:32 Sa 22.12.2007
Autor: Peter_Pein

Falls Du deinen Code doch in Mma umwandeln möchtest, hinterlasse hier eine Notiz oder mail mir direkt an petsie@dordos.net.

Eventuell hilft auch []dieser Link ein wenig.

Ich bin jedoch erst ab dem 29. oder 30. Dezember wieder "ansprechbar"


Ein gesegnetes Fest wünscht

Peter


Bezug
                        
Bezug
c++ code in mathematica?: Mitteilung
Status: (Mitteilung) Reaktion unnötig Status 
Datum: 13:08 Mo 04.02.2008
Autor: Bobby_1983

Hallo, bin gerade durch "Google" auf diesen Beitrag aufmerksam geworden. Ich suche zufälligerweise genau die gleiche Lösung des Sudokus für Mathematica mit der selben Matrix. Wäre super wenn ich hier noch einige Tips bezüglich der Lösung bekommen könnte. Lieben Gruß Bobby

Bezug
Ansicht: [ geschachtelt ] | ^ Forum "Mathematica"  | ^^ Alle Foren  | ^ Forenbaum  | Materialien


^ Seitenanfang ^
www.vorhilfe.de