File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ #include < boost/ut.hpp>
2+
3+ #include < filesystem>
4+
5+ #include < Ark/Ark.hpp>
6+ #include < TestsHelper.hpp>
7+
8+ using namespace boost ;
9+
10+ ut::suite<" Ungolfed" > ungolfed_suite = [] {
11+ using namespace ut ;
12+
13+ " [run arkscript ungolfed golf code solutions]" _test = [] {
14+ iterTestFiles (
15+ " UngolfedSuite" ,
16+ [](TestData&& data) {
17+ Ark::State state ({ lib_path });
18+
19+ should (" compile " + data.stem ) = [&] {
20+ try
21+ {
22+ const bool ok = mut (state).doFile (data.path );
23+ expect (ok) << fatal << " compilation failed" ;
24+ }
25+ catch (const Ark::CodeError&)
26+ {
27+ expect (false ) << fatal << " encountered an exception while compiling" ;
28+ }
29+ };
30+
31+ Ark::VM vm (state);
32+ should (" run " + data.stem + " without errors (exit code 0)" ) = [&] {
33+ expect (mut (vm).run () == 0 );
34+ };
35+ });
36+ };
37+ };
Original file line number Diff line number Diff line change 1+ (import std.List)
2+ (import std.Math)
3+
4+ (list:map
5+ (list:iota 1 1000)
6+ (fun (n)
7+ (if (> (list:sum (pop (math:divs n) -1)) n)
8+ n)))
Original file line number Diff line number Diff line change 1+ (import std.List)
2+ (import std.Math)
3+
4+ (list:map
5+ (list:iota 1 1000)
6+ (fun (n) {
7+ (let d (math:divs n))
8+ (if (math:integer? (/ (list:sum d) (len d)))
9+ n) }))
Original file line number Diff line number Diff line change 1+ (import std.String)
2+ (import std.List)
3+
4+ (list:map
5+ (list:iota 3 7)
6+ (fun (s) {
7+ (let d (+ " {:^" (toString (- (* 2 s) 1)) "}"))
8+ (list:map (list:iota 1 s) (fun (x) (print (format d (string:repeat "*" (- (* 2 x) 1))))))
9+ (print (format d "*") "\n") }))
Original file line number Diff line number Diff line change 1+ (import std.List)
2+ (import std.String)
3+
4+ (list:map
5+ (list:iota 1 9)
6+ (fun (x) {
7+ (list:map
8+ (list:iota 1 (- (let m (* 2 x)) 1))
9+ (fun (y)
10+ ((fun (x) {
11+ (let d (list:iota 1 x))
12+ (let r (list:reverse (pop d -1)))
13+ (print (format "{:>10}{}" (string:join d "") (string:join r ""))) })
14+ (if (<= y x)
15+ y
16+ (- m y)))))
17+ (print "") }))
Original file line number Diff line number Diff line change 1+ (import std.List)
2+
3+ (mut N 1009)
4+ (mut a (concat [0] (list:fill N 1)))
5+ (mut x 0)
6+
7+ (while (< 9 N) {
8+ (mut n
9+ (set N (- N 1)))
10+
11+ (while n {
12+ (@= a n (mod x n))
13+ (set x (+ (* (@ a (- n 1)) 10) (/ (- x (@ a n)) n)))
14+ (set n (- n 1)) })
15+
16+ (puts
17+ (if (= 17 x)
18+ "2.7"
19+ x)) })
Original file line number Diff line number Diff line change 1+ (import std.Prelude)
2+
3+ (mut sols [])
4+
5+ (let f (fun (n) {
6+ (let x (toNumber (string:reverse (toString n))))
7+ (if (and (math:prime? n) (math:prime? x))
8+ (append! sols n))
9+
10+ (if (< n 1000)
11+ (f (+ 1 n))) }))
12+
13+ (f 1)
Original file line number Diff line number Diff line change 1+ (import std.List)
2+ (import std.String)
3+
4+ (let l [0 3 6 9 12 15 19 22 -33 0])
5+ (let data [
6+ "44466833 777 337777806667 33660 22266688 5553"
7+ "58877778 0999933 777666087772444660666733 660 4884443 33 555 44466 33 0933"
8+ "8870 6 6667777802555 5550333 339 022 88 80833555 5550 7777 4466688 555 3" ])
9+
10+ (list:map
11+ (list:map data (fun (s) (string:split s " ")))
12+ (fun (e) {
13+ (list:map
14+ (list:flatMap
15+ e
16+ (fun ((mut p)) {
17+ (mut o [])
18+ (mut i 0)
19+ (let l (len p))
20+ (while (< i l) {
21+ (append! o (list:takeWhile p (fun (c) (= c (head p)))))
22+ (set p (list:drop p (len (@ o -1))))
23+ (set i (+ (len (@ o -1)) i)) })
24+ (if (= p [])
25+ o
26+ (append o p)) }))
27+ (fun (p) (puts (string:chr (+ 64 (len p) (@ l (- (toNumber (head p)) 2)))))))
28+ (print "") }))
Original file line number Diff line number Diff line change 1+ (import std.List)
2+
3+ (mut nums [0])
4+
5+ (list:map
6+ (list:iota 0 250)
7+ (fun (n) {
8+ (let r (- (@ nums -1) n))
9+ (append!
10+ nums
11+ (if (and (> r 0) (< (list:find nums r) 0))
12+ r
13+ (+ (@ nums -1) n)))
14+ (@ nums -1) }))
Original file line number Diff line number Diff line change 1+ (import std.String)
2+ (import std.List)
3+
4+ (let f (fun (c) {
5+ (mut n (string:ord c))
6+
7+ (if (and (< 96 n) (< n 123))
8+ (string:chr (+ (mod (- n 97 -13) 26) 97))
9+ (if (and (< 64 n) (< n 91))
10+ (string:chr (+ (mod (- n 65 -13) 26) 65))
11+ c)) }))
12+
13+ (let data [
14+ "JhU |jIU_[$7DlFxP3[f@P$G3:+hb?*;}PN7k:SdksO0ts^tM"
15+ "6^HMLB4*PvJ/&/daJ[6_$>T4| '<d8I0?BNvb!,eAaF3aT#)|OLBtx[Kg`ohK-]i$:;e7W9?j3U}cBE)ub36pQ/DV6=~h"
16+ "r01vhc|3mead^=emB~Q OL' Lg~@'3H3A6eu9/7 rg-7}U Q':XLqQ+@EE:IeEUs 2.I&-co``#Sb:C0vTR<iH2S2WtpwR%o>Y" ])
17+
18+ (list:map data (fun (a) (print (string:join (list:map a f) ""))))
You can’t perform that action at this time.
0 commit comments