Add "etcgit" and "euler-problem-1" snippets
This commit is contained in:
parent
3b87bda0e5
commit
cef98d73fc
3 changed files with 305 additions and 1 deletions
|
@ -28,9 +28,15 @@
|
|||
|
||||
* Projects
|
||||
|
||||
[[file:projects/dispass.el.org][dispass.el]] [[file:projects/dvdroid.org][DVDroid]] [[file:projects/eye-on-manga.org][eye-on-manga]] [[file:projects/git-auto-commit-mode.org][git-auto-commit-mode]] [[file:projects/gitto.org][gitto]]
|
||||
[[file:projects/dispass.el.org][dispass.el]]
|
||||
[[file:projects/dvdroid.org][DVDroid]]
|
||||
[[file:projects/eye-on-manga.org][eye-on-manga]]
|
||||
[[file:projects/git-auto-commit-mode.org][git-auto-commit-mode]]
|
||||
[[file:projects/gitto.org][gitto]]
|
||||
[[file:projects/yoshi-theme.org][yoshi-theme]]
|
||||
|
||||
* Snippets
|
||||
|
||||
[[file:snippets/etcgit.org][etcgit]]
|
||||
[[file:snippets/euler-problem-1.org][euler-problem-1]]
|
||||
[[file:snippets/org-export.org][org-export]]
|
||||
|
|
12
site/snippets/etcgit.org
Normal file
12
site/snippets/etcgit.org
Normal file
|
@ -0,0 +1,12 @@
|
|||
#+TITLE: etcgit
|
||||
#+OPTIONS: toc:nil
|
||||
|
||||
* etcgit
|
||||
|
||||
A tiny wrapper around git to help it make managing my ~/etc/~
|
||||
directory a little easier
|
||||
|
||||
#+BEGIN_SRC sh :tangle etcgit
|
||||
#!/usr/bin/env rc
|
||||
git --git-dir /home/slash/projects/etcfiles --work-tree /etc/ $*
|
||||
#+END_SRC
|
286
site/snippets/euler-problem-1.org
Normal file
286
site/snippets/euler-problem-1.org
Normal file
|
@ -0,0 +1,286 @@
|
|||
#+TITLE: euler-problem-1
|
||||
|
||||
* euler-problem-1
|
||||
|
||||
Here is my solution to the Project Euler problem #1 in as many
|
||||
languages as I could write it.
|
||||
|
||||
Each section will first show the commands to run the program and
|
||||
then the source for it.
|
||||
|
||||
I should still add:
|
||||
|
||||
- C# (Mono)
|
||||
|
||||
Maybe, someday soon I'll also add:
|
||||
|
||||
- Ruby
|
||||
- Io
|
||||
- Prolog
|
||||
- Scala
|
||||
- Erlang
|
||||
- Haskell
|
||||
|
||||
** Bash
|
||||
|
||||
#+BEGIN_EXAMPLE
|
||||
./euler-problem-1.sh
|
||||
#+END_EXAMPLE
|
||||
|
||||
#+BEGIN_SRC shell-script :tangle yes
|
||||
#!/bin/sh
|
||||
TOTAL=0
|
||||
I=0
|
||||
|
||||
while [ $I -lt 1000 ]; do
|
||||
if [ $[ $I % 3 ] -eq 0 -o $[ $I % 5 ] -eq 0 ]; then
|
||||
let TOTAL=TOTAL+I
|
||||
fi
|
||||
let I=I+1
|
||||
done
|
||||
|
||||
echo $TOTAL
|
||||
#+END_SRC
|
||||
|
||||
** C
|
||||
|
||||
#+BEGIN_EXAMPLE
|
||||
gcc euler-problem-1.c && ./a.out
|
||||
#+END_EXAMPLE
|
||||
|
||||
#+BEGIN_SRC c :tangle yes
|
||||
#include <stdio.h>
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
int i, total = 0;
|
||||
|
||||
for (i = 0; i < 1000; i++)
|
||||
if (i % 3 == 0 || i % 5 == 0)
|
||||
total += i;
|
||||
|
||||
printf("%d\n", total);
|
||||
|
||||
return 0;
|
||||
}
|
||||
#+END_SRC
|
||||
|
||||
** Clojure
|
||||
|
||||
#+BEGIN_EXAMPLE
|
||||
clj euler-problem-1.clj
|
||||
#+END_EXAMPLE
|
||||
|
||||
#+BEGIN_SRC clojure :tangle yes
|
||||
(def total 0)
|
||||
|
||||
(dotimes [i 1000]
|
||||
(when (or (zero? (mod i 3)) (zero? (mod i 5)))
|
||||
(def total (+ total i))))
|
||||
(println total)
|
||||
#+END_SRC
|
||||
|
||||
** Emacs lisp
|
||||
|
||||
#+BEGIN_EXAMPLE
|
||||
emacs -script euler-problem-1.el
|
||||
#+END_EXAMPLE
|
||||
|
||||
#+BEGIN_SRC emacs-lisp :tangle yes
|
||||
(let ((i 0)
|
||||
(total 0))
|
||||
(while (< i 1000)
|
||||
(when (or (zerop (mod i 3)) (zerop (mod i 5)))
|
||||
(setq total (+ total i)))
|
||||
(setq i (1+ i)))
|
||||
(message "%d" total))
|
||||
#+END_SRC
|
||||
|
||||
** Go
|
||||
|
||||
#+BEGIN_EXAMPLE
|
||||
go run euler-problem-1.go
|
||||
#+END_EXAMPLE
|
||||
|
||||
#+BEGIN_SRC go :tangle yes
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
)
|
||||
|
||||
func main() {
|
||||
total := 0
|
||||
|
||||
for i := 0; i < 1000; i++ {
|
||||
if i % 3 == 0 || i % 5 == 0 {
|
||||
total += i
|
||||
}
|
||||
}
|
||||
|
||||
fmt.Printf("%d\n", total)
|
||||
}
|
||||
#+END_SRC
|
||||
|
||||
** Java
|
||||
|
||||
#+BEGIN_EXAMPLE
|
||||
javac euler-problem-1.java && java Problem
|
||||
#+END_EXAMPLE
|
||||
|
||||
#+BEGIN_SRC java :tangle yes
|
||||
class Problem
|
||||
{
|
||||
public static void main(String args[])
|
||||
{
|
||||
int total = 0;
|
||||
int i;
|
||||
|
||||
for (i = 0; i < 1000; i++)
|
||||
if (i % 3 == 0 || i % 5 == 0)
|
||||
total += i;
|
||||
|
||||
System.out.println(total);
|
||||
}
|
||||
}
|
||||
#+END_SRC
|
||||
|
||||
** JavaScript
|
||||
|
||||
#+BEGIN_EXAMPLE
|
||||
js euler-problem-1.js
|
||||
#+END_EXAMPLE
|
||||
|
||||
#+BEGIN_SRC javascript :tangle yes
|
||||
var total = 0;
|
||||
|
||||
for (i = 0; i < 1000; i++)
|
||||
if (i % 3 == 0 || i % 5 == 0)
|
||||
total += i;
|
||||
|
||||
print(total);
|
||||
#+END_SRC
|
||||
|
||||
** Common Lisp
|
||||
|
||||
#+BEGIN_EXAMPLE
|
||||
sbcl --script euler-problem-1.lisp
|
||||
#+END_EXAMPLE
|
||||
|
||||
#+BEGIN_SRC lisp :tangle yes
|
||||
(loop for i from 0 to 999
|
||||
when (or (zerop (mod i 3)) (zerop (mod i 5))) sum i into total
|
||||
finally (format t "~d~%" total))
|
||||
#+END_SRC
|
||||
|
||||
** PHP
|
||||
|
||||
#+BEGIN_EXAMPLE
|
||||
php euler-problem-1.php
|
||||
#+END_EXAMPLE
|
||||
|
||||
#+BEGIN_SRC php :tangle yes
|
||||
<?php
|
||||
$total = 0;
|
||||
|
||||
for ($i = 0; $i < 1000; $i++)
|
||||
if ($i % 3 == 0 || $i % 5 == 0)
|
||||
$total += $i;
|
||||
|
||||
echo $total . "\n";
|
||||
?>
|
||||
#+END_SRC
|
||||
|
||||
** Python
|
||||
|
||||
#+BEGIN_EXAMPLE
|
||||
python euler-problem-1.py
|
||||
#+END_EXAMPLE
|
||||
|
||||
#+BEGIN_SRC python :tangle yes
|
||||
TOTAL = 0
|
||||
|
||||
for i in range(1000):
|
||||
if i % 3 == 0 or i % 5 == 0:
|
||||
TOTAL += i
|
||||
|
||||
print(TOTAL)
|
||||
#+END_SRC
|
||||
|
||||
** Rep
|
||||
|
||||
#+BEGIN_EXAMPLE
|
||||
rep euler-problem-1.java
|
||||
#+END_EXAMPLE
|
||||
|
||||
#+BEGIN_SRC sawfish :tangle yes
|
||||
(do ((i 0 (1+ i))
|
||||
(total 0))
|
||||
((>= i 1000)
|
||||
(format standard-output "%d\n" total))
|
||||
(when (or (zerop (mod i 3)) (zerop (mod i 5)))
|
||||
(setq total (+ total i))))
|
||||
#+END_SRC
|
||||
|
||||
** Rust
|
||||
|
||||
#+BEGIN_EXAMPLE
|
||||
rustc euler-problem-1.rs && ./euler-problem-1
|
||||
#+END_EXAMPLE
|
||||
|
||||
#+BEGIN_SRC rust :tangle yes
|
||||
fn main() {
|
||||
let mut total = 0;
|
||||
let mut i = 0;
|
||||
|
||||
while i < 1000 {
|
||||
if i % 3 == 0 || i % 5 == 0 {
|
||||
total += i;
|
||||
}
|
||||
|
||||
i += 1;
|
||||
}
|
||||
|
||||
io::print(fmt!("%d\n", total));
|
||||
}
|
||||
#+END_SRC
|
||||
|
||||
** Scheme
|
||||
|
||||
#+BEGIN_EXAMPLE
|
||||
guile euler-problem-1.scm
|
||||
#+END_EXAMPLE
|
||||
|
||||
#+BEGIN_SRC scheme :tangle yes
|
||||
(use-modules ((rnrs base)))
|
||||
|
||||
(do ((i 0 (1+ i))
|
||||
(total 0))
|
||||
((>= i 1000)
|
||||
(display total)
|
||||
(newline))
|
||||
(when (or (zero? (mod i 3)) (zero? (mod i 5)))
|
||||
(set! total (+ total i))))
|
||||
#+END_SRC
|
||||
|
||||
** Vala
|
||||
|
||||
#+BEGIN_EXAMPLE
|
||||
valac euler-problem-1.vala && ./euler-problem-1
|
||||
#+END_EXAMPLE
|
||||
|
||||
#+BEGIN_SRC vala :tangle yes
|
||||
class Euler.Problem1 : GLib.Object {
|
||||
public static int main(string[] args) {
|
||||
int total = 0;
|
||||
|
||||
for (int i = 0; i < 1000; i++)
|
||||
if (i % 3 == 0 || i % 5 == 0)
|
||||
total += i;
|
||||
|
||||
stdout.printf("%d\n", total);
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
#+END_SRC
|
Loading…
Reference in a new issue