{
  "id": 202178,
  "title": "Running C++ in notebooks",
  "url": "/competitions/riiid-test-answer-prediction/discussion/202178",
  "author_name": "",
  "post_date": "2020-12-08T18:33:50.037212300Z",
  "votes": 8,
  "comment_count": 2,
  "views": 0,
  "content": "<p>You can run a C++ program inside a Python notebook like this:</p>\n<pre><code>f = open('program.cpp','w')\nf.write('''some C++ program''')\nf.close()\nos.system(\"g++ program.cpp &amp;&amp; ./a.out\")\n</code></pre>\n<p>I've made a notebook with a working example here: <a href=\"https://www.kaggle.com/anjum48/running-c-in-notebooks\" target=\"_blank\">https://www.kaggle.com/anjum48/running-c-in-notebooks</a></p>\n<p>It might be useful in case you're hitting the time restrictions during submission.</p>\n<p>Hat tip to this discussion by <a href=\"https://www.kaggle.com/icecuber\" target=\"_blank\">@icecuber</a> <a href=\"https://www.kaggle.com/c/abstraction-and-reasoning-challenge/discussion/131230\" target=\"_blank\">https://www.kaggle.com/c/abstraction-and-reasoning-challenge/discussion/131230</a></p>",
  "messages": [
    {
      "id": "1106359",
      "postDate": "12/08/2020 18:33:50",
      "content": "<p>You can run a C++ program inside a Python notebook like this:</p>\n<pre><code>f = open('program.cpp','w')\nf.write('''some C++ program''')\nf.close()\nos.system(\"g++ program.cpp &amp;&amp; ./a.out\")\n</code></pre>\n<p>I've made a notebook with a working example here: <a href=\"https://www.kaggle.com/anjum48/running-c-in-notebooks\" target=\"_blank\">https://www.kaggle.com/anjum48/running-c-in-notebooks</a></p>\n<p>It might be useful in case you're hitting the time restrictions during submission.</p>\n<p>Hat tip to this discussion by <a href=\"https://www.kaggle.com/icecuber\" target=\"_blank\">@icecuber</a> <a href=\"https://www.kaggle.com/c/abstraction-and-reasoning-challenge/discussion/131230\" target=\"_blank\">https://www.kaggle.com/c/abstraction-and-reasoning-challenge/discussion/131230</a></p>",
      "rawMarkdown": "You can run a C++ program inside a Python notebook like this:\n```\nf = open('program.cpp','w')\nf.write('''some C++ program''')\nf.close()\nos.system(\"g++ program.cpp && ./a.out\")\n```\n\nI've made a notebook with a working example here: https://www.kaggle.com/anjum48/running-c-in-notebooks\n\nIt might be useful in case you're hitting the time restrictions during submission.\n\nHat tip to this discussion by @icecuber https://www.kaggle.com/c/abstraction-and-reasoning-challenge/discussion/131230",
      "votes": null
    },
    {
      "id": "1106370",
      "postDate": "12/08/2020 18:45:06",
      "content": "<p>This is at a complete different level! Ty for sharing! ❤️</p>",
      "rawMarkdown": "This is at a complete different level! Ty for sharing! ❤️",
      "votes": null
    },
    {
      "id": "1106577",
      "postDate": "12/08/2020 23:41:41",
      "content": "<p>Hi <a href=\"https://www.kaggle.com/datasaurus\" target=\"_blank\">@datasaurus</a> I have never thought of the possibility of running c++ program from inside a python notebook. Thanks so much for sharing this insightful 4 lines of code. Well done !!!</p>",
      "rawMarkdown": "Hi @datasaurus I have never thought of the possibility of running c++ program from inside a python notebook. Thanks so much for sharing this insightful 4 lines of code. Well done !!!",
      "votes": null
    }
  ],
  "comments": [
    {
      "id": 1106370,
      "author_name": "adityaecdrid",
      "author_url": "",
      "post_date": "12/08/2020 18:45:06",
      "content": "<p>This is at a complete different level! Ty for sharing! ❤️</p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 1106577,
      "author_name": "puzuwe",
      "author_url": "",
      "post_date": "12/08/2020 23:41:41",
      "content": "<p>Hi <a href=\"https://www.kaggle.com/datasaurus\" target=\"_blank\">@datasaurus</a> I have never thought of the possibility of running c++ program from inside a python notebook. Thanks so much for sharing this insightful 4 lines of code. Well done !!!</p>",
      "votes": null,
      "replies": []
    }
  ],
  "raw_markdown_by_id": {
    "1106359": "You can run a C++ program inside a Python notebook like this:\n```\nf = open('program.cpp','w')\nf.write('''some C++ program''')\nf.close()\nos.system(\"g++ program.cpp && ./a.out\")\n```\n\nI've made a notebook with a working example here: https://www.kaggle.com/anjum48/running-c-in-notebooks\n\nIt might be useful in case you're hitting the time restrictions during submission.\n\nHat tip to this discussion by @icecuber https://www.kaggle.com/c/abstraction-and-reasoning-challenge/discussion/131230",
    "1106370": "This is at a complete different level! Ty for sharing! ❤️",
    "1106577": "Hi @datasaurus I have never thought of the possibility of running c++ program from inside a python notebook. Thanks so much for sharing this insightful 4 lines of code. Well done !!!"
  },
  "source": "meta"
}