task_url
stringlengths
30
116
task_name
stringlengths
2
86
task_description
stringlengths
0
14.4k
language_url
stringlengths
2
53
language_name
stringlengths
1
52
code
stringlengths
0
61.9k
http://rosettacode.org/wiki/Word_wrap
Word wrap
Even today, with proportional fonts and complex layouts, there are still cases where you need to wrap text at a specified column. Basic task The basic task is to wrap a paragraph of text in a simple way in your language. If there is a way to do this that is built-in, trivial, or provided in a standard library, sho...
#Mathematica.2FWolfram_Language
Mathematica/Wolfram Language
string="In olden times when wishing still helped one, there lived a king whose daughters were all beautiful, but the youngest was so beautiful that the sun itself, which has seen so much, was astonished whenever it shone in her face. Close by the king's castle lay a great dark forest, and under an old lime-tree in the...
http://rosettacode.org/wiki/XML/Output
XML/Output
Create a function that takes a list of character names and a list of corresponding remarks and returns an XML document of <Character> elements each with a name attributes and each enclosing its remarks. All <Character> elements are to be enclosed in turn, in an outer <CharacterRemarks> element. As an example, calling ...
#Wren
Wren
var escapes = [ ["&" , "&amp;"], // must do this one first ["\"", "&quot;"], ["'" , "&apos;"], ["<" , "&lt;"], [">" , "&gt;"] ]   var xmlEscape = Fn.new { |s| for (esc in escapes) s = s.replace(esc[0], esc[1]) return s }   var xmlDoc = Fn.new { |names, remarks| var xml = "<CharacterRe...
http://rosettacode.org/wiki/XML/Input
XML/Input
Given the following XML fragment, extract the list of student names using whatever means desired. If the only viable method is to use XPath, refer the reader to the task XML and XPath. <Students> <Student Name="April" Gender="F" DateOfBirth="1989-01-02" /> <Student Name="Bob" Gender="M" DateOfBirth="1990-03-04" /...
#Raku
Raku
use XML;   my $xml = from-xml '<Students> <Student Name="April" Gender="F" DateOfBirth="1989-01-02" /> <Student Name="Bob" Gender="M" DateOfBirth="1990-03-04" /> <Student Name="Chad" Gender="M" DateOfBirth="1991-05-06" /> <Student Name="Dave" Gender="M" DateOfBirth="1992-07-08"> <Pet Type="dog" Name="Rov...
http://rosettacode.org/wiki/100_doors
100 doors
There are 100 doors in a row that are all initially closed. You make 100 passes by the doors. The first time through, visit every door and  toggle  the door  (if the door is closed,  open it;   if it is open,  close it). The second time, only visit every 2nd door   (door #2, #4, #6, ...),   and toggle it. The third...
#Perl
Perl
my @doors; for my $pass (1 .. 100) { for (1 .. 100) { if (0 == $_ % $pass) { $doors[$_] = not $doors[$_]; }; }; };   print "Door $_ is ", $doors[$_] ? "open" : "closed", "\n" for 1 .. 100;
http://rosettacode.org/wiki/Weird_numbers
Weird numbers
In number theory, a weird number is a natural number that is abundant but not semiperfect (and therefore not perfect either). In other words, the sum of the proper divisors of the number (divisors including 1 but not itself) is greater than the number itself (the number is abundant), but no subset of those divisors su...
#Vlang
Vlang
fn divisors(n int) []int { mut divs := [1] mut divs2 := []int{} for i := 2; i*i <= n; i++ { if n%i == 0 { j := n / i divs << i if i != j { divs2 << j } } } for i := divs.len - 1; i >= 0; i-- { divs2 << divs[i] ...
http://rosettacode.org/wiki/Weird_numbers
Weird numbers
In number theory, a weird number is a natural number that is abundant but not semiperfect (and therefore not perfect either). In other words, the sum of the proper divisors of the number (divisors including 1 but not itself) is greater than the number itself (the number is abundant), but no subset of those divisors su...
#Wren
Wren
import "/math" for Int, Nums import "/trait" for Stepped   var semiperfect // recursive semiperfect = Fn.new { |n, divs| var le = divs.count if (le == 0) return false var h = divs[0] if (n == h) return true if (le == 1) return false var t = divs[1..-1] if (n < h) return semiperfect.call(n, t...
http://rosettacode.org/wiki/Write_language_name_in_3D_ASCII
Write language name in 3D ASCII
Task Write/display a language's name in 3D ASCII. (We can leave the definition of "3D ASCII" fuzzy, so long as the result is interesting or amusing, not a cheap hack to satisfy the task.) Related tasks draw a sphere draw a cuboid draw a rotating cube draw a Deathstar
#UNIX_Shell
UNIX Shell
#!/usr/bin/env bash mapfile -t name <<EOF Aimhacks EOF   main() { banner3d_1 "${name[@]}" echo banner3d_2 "${name[@]}" echo banner3d_3 "${name[@]}" }   space() { local -i n i (( n=$1 )) || n=1 if (( n < 1 )); then n=1; fi for ((i=0; i<n; ++i)); do printf ' ' done printf '\n' }   banner3d_1() {...
http://rosettacode.org/wiki/Web_scraping
Web scraping
Task Create a program that downloads the time from this URL:   http://tycho.usno.navy.mil/cgi-bin/timer.pl   and then prints the current UTC time by extracting just the UTC time from the web page's HTML. Alternatively, if the above url is not working, grab the first date/time off this page's talk page. If possible,...
#Julia
Julia
using Requests, Printf   function getusnotime() const url = "http://tycho.usno.navy.mil/timer.pl" s = try get(url) catch err @sprintf "get(%s)\n => %s" url err end isa(s, Requests.Response) || return (s, false) t = match(r"(?<=<BR>)(.*?UTC)", readstring(s)) isa(t, Regex...
http://rosettacode.org/wiki/Web_scraping
Web scraping
Task Create a program that downloads the time from this URL:   http://tycho.usno.navy.mil/cgi-bin/timer.pl   and then prints the current UTC time by extracting just the UTC time from the web page's HTML. Alternatively, if the above url is not working, grab the first date/time off this page's talk page. If possible,...
#Kotlin
Kotlin
// version 1.1.3   import java.net.URL import java.io.InputStreamReader import java.util.Scanner   fun main(args: Array<String>) { val url = URL("http://tycho.usno.navy.mil/cgi-bin/timer.pl") val isr = InputStreamReader(url.openStream()) val sc = Scanner(isr) while (sc.hasNextLine()) { val line ...
http://rosettacode.org/wiki/Word_frequency
Word frequency
Task Given a text file and an integer   n,   print/display the   n   most common words in the file   (and the number of their occurrences)   in decreasing frequency. For the purposes of this task:   A word is a sequence of one or more contiguous letters.   You are free to define what a   letter   is.   Undersc...
#KAP
KAP
∇ stats (file) { content ← "[\\h,.\"'\n-]+" regex:split unicode:toLower io:readFile file sorted ← (⍋⊇⊢) content selection ← 1,2≢/sorted words ← selection / sorted {⍵[10↑⍒⍵[;1];]} words ,[0.5] ≢¨ sorted ⊂⍨ +\selection }
http://rosettacode.org/wiki/Word_frequency
Word frequency
Task Given a text file and an integer   n,   print/display the   n   most common words in the file   (and the number of their occurrences)   in decreasing frequency. For the purposes of this task:   A word is a sequence of one or more contiguous letters.   You are free to define what a   letter   is.   Undersc...
#Kotlin
Kotlin
// version 1.1.3   import java.io.File   fun main(args: Array<String>) { val text = File("135-0.txt").readText().toLowerCase() val r = Regex("""\p{javaLowerCase}+""") val matches = r.findAll(text) val wordGroups = matches.map { it.value } .groupBy { it } .map { Pa...
http://rosettacode.org/wiki/Wireworld
Wireworld
Wireworld Conway's Game of Life It is capable of doing sophisticated computations with appropriate programs (it is actually Turing complete), and is much simpler to program for. A Wireworld arena consists of a Cartesian grid of cells, each of which can be in one of four states. All cell transitions happen simultaneous...
#Oz
Oz
declare Rules = [rule(& & ) rule(&H &t) rule(&t &.) rule(&. &H when:fun {$ Neighbours} fun {IsHead X} X == &H end Hs = {Filter Neighbours IsHead} Len = {Length Hs} in Len == 1 orelse Len == 2 ...
http://rosettacode.org/wiki/Window_creation
Window creation
Display a GUI window. The window need not have any contents, but should respond to requests to be closed.
#Prolog
Prolog
?- new(D, window('Prolog Window')), send(D, open).
http://rosettacode.org/wiki/Window_creation
Window creation
Display a GUI window. The window need not have any contents, but should respond to requests to be closed.
#PureBasic
PureBasic
Define MyWin.i, Event.i   MyWin = OpenWindow(#PB_Any, 412, 172, 402, 94, "PureBasic")   ; Event loop Repeat Event = WaitWindowEvent() Select Event Case #PB_Event_Gadget ; Handle any gadget events here Case #PB_Event_CloseWindow Break EndSelect ForEver
http://rosettacode.org/wiki/Window_creation
Window creation
Display a GUI window. The window need not have any contents, but should respond to requests to be closed.
#Python
Python
import Tkinter   w = Tkinter.Tk() w.mainloop()
http://rosettacode.org/wiki/Word_wrap
Word wrap
Even today, with proportional fonts and complex layouts, there are still cases where you need to wrap text at a specified column. Basic task The basic task is to wrap a paragraph of text in a simple way in your language. If there is a way to do this that is built-in, trivial, or provided in a standard library, sho...
#MiniScript
MiniScript
str = "one two three four five six seven eight nine ten eleven!" width = 15 words = str.split pos = 0 line = "" for word in words pos = pos + word.len + 1 if pos <= width then line = line + word + " " else print line[:-1] line = word + " " pos = word.len end if end for pr...
http://rosettacode.org/wiki/Word_wrap
Word wrap
Even today, with proportional fonts and complex layouts, there are still cases where you need to wrap text at a specified column. Basic task The basic task is to wrap a paragraph of text in a simple way in your language. If there is a way to do this that is built-in, trivial, or provided in a standard library, sho...
#NetRexx
NetRexx
/* NetRexx */ options replace format comments java crossref symbols   runSample(arg) return   -- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ /* @see http://en.wikipedia.org/wiki/Word_wrap#Minimum_length   SpaceLeft := LineWidth for each Word in Text if (Width(Word) + Sp...
http://rosettacode.org/wiki/XML/Output
XML/Output
Create a function that takes a list of character names and a list of corresponding remarks and returns an XML document of <Character> elements each with a name attributes and each enclosing its remarks. All <Character> elements are to be enclosed in turn, in an outer <CharacterRemarks> element. As an example, calling ...
#XPL0
XPL0
code ChOut=8, CrLf=9, Text=12; string 0; \use zero-terminated strings   proc XmlOut(S); \Output string in XML format char S; repeat case S(0) of \character entity substitutions ^<: Text(0, "&lt;"); ^>: Text(0, "&gt;"); ^&: Text(0, "&amp;"); ^": Text(0, "...
http://rosettacode.org/wiki/XML/Output
XML/Output
Create a function that takes a list of character names and a list of corresponding remarks and returns an XML document of <Character> elements each with a name attributes and each enclosing its remarks. All <Character> elements are to be enclosed in turn, in an outer <CharacterRemarks> element. As an example, calling ...
#XQuery
XQuery
  let $names := ("April","Tam O'Shanter","Emily") let $remarks := ("Bubbly: I'm > Tam and <= Emily", 'Burns: "When chapman billies leave the street ..."',"Short &amp; shrift") return element CharacterRemarks { for $name at $count in $names return eleme...
http://rosettacode.org/wiki/XML/Input
XML/Input
Given the following XML fragment, extract the list of student names using whatever means desired. If the only viable method is to use XPath, refer the reader to the task XML and XPath. <Students> <Student Name="April" Gender="F" DateOfBirth="1989-01-02" /> <Student Name="Bob" Gender="M" DateOfBirth="1990-03-04" /...
#Rascal
Rascal
import lang::xml::DOM;   public void getNames(loc a){ D = parseXMLDOM(readFile(a)); visit(D){ case element(_,"Student",[_*,attribute(_,"Name", x),_*]): println(x); }; }
http://rosettacode.org/wiki/XML/Input
XML/Input
Given the following XML fragment, extract the list of student names using whatever means desired. If the only viable method is to use XPath, refer the reader to the task XML and XPath. <Students> <Student Name="April" Gender="F" DateOfBirth="1989-01-02" /> <Student Name="Bob" Gender="M" DateOfBirth="1990-03-04" /...
#REBOL
REBOL
rebol [ Title: "XML Reading" URL: http://rosettacode.org/wiki/XML_Reading ]   xml: { <Students> <Student Name="April" Gender="F" DateOfBirth="1989-01-02" /> <Student Name="Bob" Gender="M" DateOfBirth="1990-03-04" /> <Student Name="Chad" Gender="M" DateOfBirth="1991-05-06" /> <Student Name="Dave" Gender="M" ...
http://rosettacode.org/wiki/100_doors
100 doors
There are 100 doors in a row that are all initially closed. You make 100 passes by the doors. The first time through, visit every door and  toggle  the door  (if the door is closed,  open it;   if it is open,  close it). The second time, only visit every 2nd door   (door #2, #4, #6, ...),   and toggle it. The third...
#Perl5i
Perl5i
  use perl5i::2;   package doors {   use perl5i::2; use Const::Fast;   const my $OPEN => 1; const my $CLOSED => 0;   # ---------------------------------------- # Constructor: door->new( @args ); # input: N - how many doors? # returns: door object # method new($class: @args ) { my $self = bless...
http://rosettacode.org/wiki/Weird_numbers
Weird numbers
In number theory, a weird number is a natural number that is abundant but not semiperfect (and therefore not perfect either). In other words, the sum of the proper divisors of the number (divisors including 1 but not itself) is greater than the number itself (the number is abundant), but no subset of those divisors su...
#zkl
zkl
fcn properDivs(n){ if(n==1) return(T); ( pd:=[1..(n).toFloat().sqrt()].filter('wrap(x){ n%x==0 }) ) .pump(pd,'wrap(pd){ if(pd!=1 and (y:=n/pd)!=pd ) y else Void.Skip }) } fcn abundant(n,divs){ divs.sum(0) > n } fcn semiperfect(n,divs){ if(divs){ h,t := divs[0], divs[1,*]; if(n<h) return(semiper...
http://rosettacode.org/wiki/Write_language_name_in_3D_ASCII
Write language name in 3D ASCII
Task Write/display a language's name in 3D ASCII. (We can leave the definition of "3D ASCII" fuzzy, so long as the result is interesting or amusing, not a cheap hack to satisfy the task.) Related tasks draw a sphere draw a cuboid draw a rotating cube draw a Deathstar
#Visual_Basic_.NET
Visual Basic .NET
Module Module1   Sub Main() Console.WriteLine(" ___ ___ ___ ________ ___ ___ ________ ___ ________ ________ ________ ___ ________ ________ _______ _________ |\ \ / /|\ \|\ ____\|\ \|\ \|\ __ \|\ \ |\ __ \|\ __ \|\ ____\|\ \|\ _...
http://rosettacode.org/wiki/Write_language_name_in_3D_ASCII
Write language name in 3D ASCII
Task Write/display a language's name in 3D ASCII. (We can leave the definition of "3D ASCII" fuzzy, so long as the result is interesting or amusing, not a cheap hack to satisfy the task.) Related tasks draw a sphere draw a cuboid draw a rotating cube draw a Deathstar
#Wren
Wren
var w = """ ____ ____ ____ |\ \ |\ \ |\ \ | \ \ | \ \ | \ \ \ \ \\ / \\ / /| \ \ \V \V / | \ \ /\ / / \ \____/ \____/ / \ | | /| | / \|____|/ |____|/ """.split("\n")   var r = """ _______ ____ |\__ \ / \...
http://rosettacode.org/wiki/Web_scraping
Web scraping
Task Create a program that downloads the time from this URL:   http://tycho.usno.navy.mil/cgi-bin/timer.pl   and then prints the current UTC time by extracting just the UTC time from the web page's HTML. Alternatively, if the above url is not working, grab the first date/time off this page's talk page. If possible,...
#Lasso
Lasso
/* have to be used local(raw_htmlstring = '<TITLE>What time is it?</TITLE> <H2> US Naval Observatory Master Clock Time</H2> <H3><PRE> <BR>Jul. 27, 22:57:22 UTC Universal Time <BR>Jul. 27, 06:57:22 PM EDT Eastern Time <BR>Jul. 27, 05:57:22 PM CDT Central Time <BR>Jul. 27, 04:57:22 PM MDT Mountain Time <BR>Jul. 27, ...
http://rosettacode.org/wiki/Web_scraping
Web scraping
Task Create a program that downloads the time from this URL:   http://tycho.usno.navy.mil/cgi-bin/timer.pl   and then prints the current UTC time by extracting just the UTC time from the web page's HTML. Alternatively, if the above url is not working, grab the first date/time off this page's talk page. If possible,...
#Liberty_BASIC
Liberty BASIC
if DownloadToFile("http://tycho.usno.navy.mil/cgi-bin/timer.pl", DefaultDir$ + "\timer.htm") = 0 then open DefaultDir$ + "\timer.htm" for input as #f html$ = lower$(input$(#f, LOF(#f))) close #f   a= instr( html$, "utc" )-1 print "UTC";mid$( html$, a-9,9)   end if   e...
http://rosettacode.org/wiki/Word_frequency
Word frequency
Task Given a text file and an integer   n,   print/display the   n   most common words in the file   (and the number of their occurrences)   in decreasing frequency. For the purposes of this task:   A word is a sequence of one or more contiguous letters.   You are free to define what a   letter   is.   Undersc...
#Liberty_BASIC
Liberty BASIC
dim words$(100000,2)'words$(a,1)=the word, words$(a,2)=the count dim lines$(150000) open "135-0.txt" for input as #txt while EOF(#txt)=0 and total < 150000 input #txt, lines$(total) total=total+1 wend for a = 1 to total token$ = "?" index=0 new=0 while token$ <> "" new=0 index = ...
http://rosettacode.org/wiki/Wireworld
Wireworld
Wireworld Conway's Game of Life It is capable of doing sophisticated computations with appropriate programs (it is actually Turing complete), and is much simpler to program for. A Wireworld arena consists of a Cartesian grid of cells, each of which can be in one of four states. All cell transitions happen simultaneous...
#PARI.2FGP
PARI/GP
\\ 0 = conductor, 1 = tail, 2 = head, 3 = empty wireworldStep(M)={ my(sz=matsize(M),t); matrix(sz[1],sz[2],x,y, t=M[x,y]; if(t, [0,1,3][t] , t=sum(i=max(x-1,1),min(x+1,sz[1]), sum(j=max(y-1,1),min(y+1,sz[2]), M[i,j]==2 ) ); if(t==1|t==2,2,3) ) ) }; animate(M)={ while(1,display(M=wir...
http://rosettacode.org/wiki/Window_creation
Window creation
Display a GUI window. The window need not have any contents, but should respond to requests to be closed.
#R
R
  win <- tktoplevel()  
http://rosettacode.org/wiki/Window_creation
Window creation
Display a GUI window. The window need not have any contents, but should respond to requests to be closed.
#Racket
Racket
  #lang racket/gui (send (new frame% [label "New Window"] [width 100] [height 100]) show #t)  
http://rosettacode.org/wiki/Window_creation
Window creation
Display a GUI window. The window need not have any contents, but should respond to requests to be closed.
#Raku
Raku
use GTK::Simple; use GTK::Simple::App;   my GTK::Simple::App $app .= new(title => 'Simple GTK Window');   $app.size-request(250, 100);   $app.set-content( GTK::Simple::VBox.new( my $button = GTK::Simple::Button.new(label => 'Exit'), ) );   $app.border-width = 40;   $button.clicked.tap: { $app.exit }   $...
http://rosettacode.org/wiki/Word_wrap
Word wrap
Even today, with proportional fonts and complex layouts, there are still cases where you need to wrap text at a specified column. Basic task The basic task is to wrap a paragraph of text in a simple way in your language. If there is a way to do this that is built-in, trivial, or provided in a standard library, sho...
#Nim
Nim
import std/wordwrap   let txt = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec a diam lectus. Sed sit amet ipsum mauris. Maecenas congue ligula ac quam viverra nec consectetur ante hendrerit. Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue e...
http://rosettacode.org/wiki/Word_wrap
Word wrap
Even today, with proportional fonts and complex layouts, there are still cases where you need to wrap text at a specified column. Basic task The basic task is to wrap a paragraph of text in a simple way in your language. If there is a way to do this that is built-in, trivial, or provided in a standard library, sho...
#OCaml
OCaml
#load "str.cma"   let txt = "In olden times when wishing still helped one, there lived a king whose daughters were all beautiful, but the youngest was so beautiful that the sun itself, which has seen so much, was astonished whenever it shone in her face. Close by the king's castle lay a great dark forest, and under an...
http://rosettacode.org/wiki/XML/Output
XML/Output
Create a function that takes a list of character names and a list of corresponding remarks and returns an XML document of <Character> elements each with a name attributes and each enclosing its remarks. All <Character> elements are to be enclosed in turn, in an outer <CharacterRemarks> element. As an example, calling ...
#Yabasic
Yabasic
sign$ = "<,&lt;,>,&gt;,&,&amp;" dim sign$(1) long = token(sign$, sign$(), ",")   sub substitute_all$(s$) local i   for i = 1 to long step 2 if s$ = sign$(i) return sign$(i + 1) next i return s$ end sub   sub xmlquote_all$(s$) local i, res$   for i = 1 to len(s$) res$ = res$ + sub...
http://rosettacode.org/wiki/XML/Output
XML/Output
Create a function that takes a list of character names and a list of corresponding remarks and returns an XML document of <Character> elements each with a name attributes and each enclosing its remarks. All <Character> elements are to be enclosed in turn, in an outer <CharacterRemarks> element. As an example, calling ...
#zkl
zkl
fcn xmlEscape(text){ text.replace(" &"," &amp;") .replace(" \""," &quot;") .replace(" '"," &apos;") .replace(" <"," &lt;") .replace(" >"," &gt;") } fcn toXML(as,bs){ xml:=Sink("<CharacterRemarks>\n"); as.zipWith('wrap(a,b){ xml.write(" <Character name=\"",xmlEscape(a),"\">", xmlEscape(b),"</C...
http://rosettacode.org/wiki/XML/Input
XML/Input
Given the following XML fragment, extract the list of student names using whatever means desired. If the only viable method is to use XPath, refer the reader to the task XML and XPath. <Students> <Student Name="April" Gender="F" DateOfBirth="1989-01-02" /> <Student Name="Bob" Gender="M" DateOfBirth="1990-03-04" /...
#REXX
REXX
/*REXX program extracts student names from an XML string(s). */ g.= g.1 = '<Students> ' g.2 = ' <Student Name="April" Gender="F" DateOfBirth="1989-01-02" /> ' g.3 = ' <Student Name="Bob" Gender="M" DateOfBirth="1990-03-04"...
http://rosettacode.org/wiki/100_doors
100 doors
There are 100 doors in a row that are all initially closed. You make 100 passes by the doors. The first time through, visit every door and  toggle  the door  (if the door is closed,  open it;   if it is open,  close it). The second time, only visit every 2nd door   (door #2, #4, #6, ...),   and toggle it. The third...
#Phix
Phix
sequence doors = repeat(false,100) for i=1 to 100 do for j=i to 100 by i do doors[j] = not doors[j] end for end for for i=1 to 100 do if doors[i] == true then printf(1,"Door #%d is open.\n", i) end if end for
http://rosettacode.org/wiki/Write_language_name_in_3D_ASCII
Write language name in 3D ASCII
Task Write/display a language's name in 3D ASCII. (We can leave the definition of "3D ASCII" fuzzy, so long as the result is interesting or amusing, not a cheap hack to satisfy the task.) Related tasks draw a sphere draw a cuboid draw a rotating cube draw a Deathstar
#XPL0
XPL0
include c:\cxpl\codes;   proc DrawBlock(X, Y); int X, Y; [Cursor(X+1, Y); Text(0, "///\"); Cursor(X, Y+1); Text(0,"/// \"); Cursor(X, Y+2); Text(0,"\\\ /"); Cursor(X+1, Y+3); Text(0, "\\\/"); ];   int Data, D, X, Y; [ChOut(0, $C); \form feed, clears screen Data:= [%1000100011110000100000001110...
http://rosettacode.org/wiki/Write_language_name_in_3D_ASCII
Write language name in 3D ASCII
Task Write/display a language's name in 3D ASCII. (We can leave the definition of "3D ASCII" fuzzy, so long as the result is interesting or amusing, not a cheap hack to satisfy the task.) Related tasks draw a sphere draw a cuboid draw a rotating cube draw a Deathstar
#Yabasic
Yabasic
  // Method 1 // r$ = system$("explorer \"http://www.network-science.de/ascii/ascii.php?TEXT=${delegate}&x=23&y=10&FONT=block&RICH=no&FORM=left&STRE=no&WIDT=80&TEXT=Yabasic\"")   // Method 2 // print // print " _| _| _| _| " // print " _| _| _|_|_| _|_|_| ...
http://rosettacode.org/wiki/Web_scraping
Web scraping
Task Create a program that downloads the time from this URL:   http://tycho.usno.navy.mil/cgi-bin/timer.pl   and then prints the current UTC time by extracting just the UTC time from the web page's HTML. Alternatively, if the above url is not working, grab the first date/time off this page's talk page. If possible,...
#Lua
Lua
  local http = require("socket.http") -- Debian package is 'lua-socket'   function scrapeTime (pageAddress, timeZone) local page = http.request(pageAddress) if not page then return "Cannot connect" end for line in page:gmatch("[^<BR>]*") do if line:match(timeZone) then return line:mat...
http://rosettacode.org/wiki/Word_frequency
Word frequency
Task Given a text file and an integer   n,   print/display the   n   most common words in the file   (and the number of their occurrences)   in decreasing frequency. For the purposes of this task:   A word is a sequence of one or more contiguous letters.   You are free to define what a   letter   is.   Undersc...
#Lua
Lua
  -- This program takes two optional command line arguments. The first (arg[1]) -- specifies the input file, or defaults to standard input. The second -- (arg[2]) specifies the number of results to show, or defaults to 10.   -- in freq, each key is a word and each value is its count local freq = {} for line in io.lin...
http://rosettacode.org/wiki/Wireworld
Wireworld
Wireworld Conway's Game of Life It is capable of doing sophisticated computations with appropriate programs (it is actually Turing complete), and is much simpler to program for. A Wireworld arena consists of a Cartesian grid of cells, each of which can be in one of four states. All cell transitions happen simultaneous...
#Perl
Perl
my @f = ([],(map {chomp;['',( split // ),'']} <>),[]);   for (1 .. 10) { print join "", map {"@$_\n"} @f; my @a = ([]); for my $y (1 .. $#f-1) { my $r = $f[$y]; my $rr = ['']; for my $x (1 .. $#$r-1) { my $c = $r->[$x]; push @$rr, $c eq 'H' ? 't' : $c eq 't' ? '.' : $c eq '.' ? (join('', map ...
http://rosettacode.org/wiki/Window_creation
Window creation
Display a GUI window. The window need not have any contents, but should respond to requests to be closed.
#RapidQ
RapidQ
create form as qform center width=500 height=400 end create form.showModal
http://rosettacode.org/wiki/Window_creation
Window creation
Display a GUI window. The window need not have any contents, but should respond to requests to be closed.
#REBOL
REBOL
  view layout [size 100x100]  
http://rosettacode.org/wiki/Window_creation
Window creation
Display a GUI window. The window need not have any contents, but should respond to requests to be closed.
#Red
Red
>>view []  
http://rosettacode.org/wiki/Word_wrap
Word wrap
Even today, with proportional fonts and complex layouts, there are still cases where you need to wrap text at a specified column. Basic task The basic task is to wrap a paragraph of text in a simple way in your language. If there is a way to do this that is built-in, trivial, or provided in a standard library, sho...
#Ol
Ol
  (define (get-one-word start) (let loop ((chars #null) (end start)) (let ((char (car end))) (if (has? (list #\space #\newline) char) (values (reverse chars) (force (cdr end))) (loop (cons char chars) (force (cdr end)))))))   (define (get-all-words string) (let loop ((words #null) (start (str...
http://rosettacode.org/wiki/XML/Input
XML/Input
Given the following XML fragment, extract the list of student names using whatever means desired. If the only viable method is to use XPath, refer the reader to the task XML and XPath. <Students> <Student Name="April" Gender="F" DateOfBirth="1989-01-02" /> <Student Name="Bob" Gender="M" DateOfBirth="1990-03-04" /...
#Ruby
Ruby
require 'rexml/document' include REXML   doc = Document.new(File.new("sample.xml")) # or # doc = Document.new(xml_string)   # without using xpath doc.each_recursive do |node| puts node.attributes["Name"] if node.name == "Student" end   # using xpath doc.each_element("*/Student") {|node| puts node.attributes["Name"]}
http://rosettacode.org/wiki/100_doors
100 doors
There are 100 doors in a row that are all initially closed. You make 100 passes by the doors. The first time through, visit every door and  toggle  the door  (if the door is closed,  open it;   if it is open,  close it). The second time, only visit every 2nd door   (door #2, #4, #6, ...),   and toggle it. The third...
#Phixmonti
Phixmonti
101 var l 0 l repeat   l for var s s l s 3 tolist for var i i get not i set endfor endfor   l for var i i get if i print " " print endif endfor
http://rosettacode.org/wiki/Write_language_name_in_3D_ASCII
Write language name in 3D ASCII
Task Write/display a language's name in 3D ASCII. (We can leave the definition of "3D ASCII" fuzzy, so long as the result is interesting or amusing, not a cheap hack to satisfy the task.) Related tasks draw a sphere draw a cuboid draw a rotating cube draw a Deathstar
#zkl
zkl
#<<< " xxxxxx x x x x x x x x x x x x x x x xxxxx x x xxxx " #<<<< .replace(" "," ").replace("x","_/").println();
http://rosettacode.org/wiki/Web_scraping
Web scraping
Task Create a program that downloads the time from this URL:   http://tycho.usno.navy.mil/cgi-bin/timer.pl   and then prints the current UTC time by extracting just the UTC time from the web page's HTML. Alternatively, if the above url is not working, grab the first date/time off this page's talk page. If possible,...
#M2000_Interpreter
M2000 Interpreter
  Module Web_scraping { Print "Web scraping" function GetTime$(a$, what$="UTC") { document a$ ' change string to document find a$, what$ ' place data to stack Read find_pos if find_pos>0 then read par_order, par_pos b$=paragraph$(a$, par_order) k=instr(b$,">") if k>0 then if k<par_pos then b$=mid...
http://rosettacode.org/wiki/Web_scraping
Web scraping
Task Create a program that downloads the time from this URL:   http://tycho.usno.navy.mil/cgi-bin/timer.pl   and then prints the current UTC time by extracting just the UTC time from the web page's HTML. Alternatively, if the above url is not working, grab the first date/time off this page's talk page. If possible,...
#Maple
Maple
text := URL:-Get("http://tycho.usno.navy.mil/cgi-bin/timer.pl"): printf(StringTools:-StringSplit(text,"<BR>")[2]);
http://rosettacode.org/wiki/Word_frequency
Word frequency
Task Given a text file and an integer   n,   print/display the   n   most common words in the file   (and the number of their occurrences)   in decreasing frequency. For the purposes of this task:   A word is a sequence of one or more contiguous letters.   You are free to define what a   letter   is.   Undersc...
#Mathematica_.2F_Wolfram_Language
Mathematica / Wolfram Language
TakeLargest[10]@WordCounts[Import["https://www.gutenberg.org/files/135/135-0.txt"], IgnoreCase->True]//Dataset
http://rosettacode.org/wiki/Word_frequency
Word frequency
Task Given a text file and an integer   n,   print/display the   n   most common words in the file   (and the number of their occurrences)   in decreasing frequency. For the purposes of this task:   A word is a sequence of one or more contiguous letters.   You are free to define what a   letter   is.   Undersc...
#MATLAB_.2F_Octave
MATLAB / Octave
  function [result,count] = word_frequency() URL='https://www.gutenberg.org/files/135/135-0.txt'; text=webread(URL); DELIMITER={' ', ',', ';', ':', '.', '/', '*', '!', '?', '<', '>', '(', ')', '[', ']','{', '}', '&','$','§','"','”','“','-','—','‘','\t','\n','\r'}; words = sort(strsplit(lower(text),DELIMITER)); flag ...
http://rosettacode.org/wiki/Wireworld
Wireworld
Wireworld Conway's Game of Life It is capable of doing sophisticated computations with appropriate programs (it is actually Turing complete), and is much simpler to program for. A Wireworld arena consists of a Cartesian grid of cells, each of which can be in one of four states. All cell transitions happen simultaneous...
#Phix
Phix
-- -- demo\rosetta\Wireworld.exw -- ========================== -- -- Invoke with file to read, or let it read the one below (if compiled assumes source is in the same directory) -- -- Note that tabs in description files are not supported - where necessary spaces can be replaced with _ chars. -- (tab chars in text fi...
http://rosettacode.org/wiki/Window_creation
Window creation
Display a GUI window. The window need not have any contents, but should respond to requests to be closed.
#Ring
Ring
  Load "guilib.ring"   MyApp = New qApp { win1 = new qWidget() { setwindowtitle("Hello World") setGeometry(100,100,370,250) show()} exec()}  
http://rosettacode.org/wiki/Window_creation
Window creation
Display a GUI window. The window need not have any contents, but should respond to requests to be closed.
#Ruby
Ruby
require 'tk'   window = TkRoot::new() window::mainloop()
http://rosettacode.org/wiki/Window_creation
Window creation
Display a GUI window. The window need not have any contents, but should respond to requests to be closed.
#Run_BASIC
Run BASIC
html "Close me!" button #c, "Close Me", [doExit] wait   ' ----------------------------------------------------------------------------------- ' Get outta here. depending on how may layers you are into the window (history level) ' If you are at the top level then close the window ' --------------------------------------...
http://rosettacode.org/wiki/Word_wrap
Word wrap
Even today, with proportional fonts and complex layouts, there are still cases where you need to wrap text at a specified column. Basic task The basic task is to wrap a paragraph of text in a simple way in your language. If there is a way to do this that is built-in, trivial, or provided in a standard library, sho...
#PARI.2FGP
PARI/GP
wrap(s,len)={ my(t="",cur); s=Vec(s); for(i=1,#s, if(s[i]==" ", if(cur>#t, print1(" "t); cur-=#t+1 , print1("\n"t); cur=len-#t ); t="" , t=concat(t,s[i]) ) ); if(cur>#t, print1(" "t) , print1("\n"t) ) }; King="And so let fre...
http://rosettacode.org/wiki/XML/Input
XML/Input
Given the following XML fragment, extract the list of student names using whatever means desired. If the only viable method is to use XPath, refer the reader to the task XML and XPath. <Students> <Student Name="April" Gender="F" DateOfBirth="1989-01-02" /> <Student Name="Bob" Gender="M" DateOfBirth="1990-03-04" /...
#Run_BASIC
Run BASIC
' ------------------------------------------------------------------------ 'XMLPARSER methods   '#handle ELEMENTCOUNT() - Return the number of child XML elements '#handle KEY$() - Return the key as a string from an XML expression like <key>value</key> '#handle VALUE$() - Return the value as a string from an XML expre...
http://rosettacode.org/wiki/100_doors
100 doors
There are 100 doors in a row that are all initially closed. You make 100 passes by the doors. The first time through, visit every door and  toggle  the door  (if the door is closed,  open it;   if it is open,  close it). The second time, only visit every 2nd door   (door #2, #4, #6, ...),   and toggle it. The third...
#PHL
PHL
module doors;   extern printf;   @Integer main [ @Array<@Boolean> doors = new @Array<@Boolean>.init(100); var i = 1; while (i <= 100) { var j = i-1; while (j < 100) { doors.set(j, doors.get(j)::not); j = j + i; } i = i::inc; } i = 0; while (i < 100) { printf("%i %s\n", i+1, iif(doors.get(i), "open...
http://rosettacode.org/wiki/Web_scraping
Web scraping
Task Create a program that downloads the time from this URL:   http://tycho.usno.navy.mil/cgi-bin/timer.pl   and then prints the current UTC time by extracting just the UTC time from the web page's HTML. Alternatively, if the above url is not working, grab the first date/time off this page's talk page. If possible,...
#Mathematica.2FWolfram_Language
Mathematica/Wolfram Language
test = StringSplit[Import["http://tycho.usno.navy.mil/cgi-bin/timer.pl"], "\n"]; Extract[test, Flatten@Position[StringFreeQ[test, "UTC"], False]]
http://rosettacode.org/wiki/Web_scraping
Web scraping
Task Create a program that downloads the time from this URL:   http://tycho.usno.navy.mil/cgi-bin/timer.pl   and then prints the current UTC time by extracting just the UTC time from the web page's HTML. Alternatively, if the above url is not working, grab the first date/time off this page's talk page. If possible,...
#MATLAB_.2F_Octave
MATLAB / Octave
s = urlread('http://tycho.usno.navy.mil/cgi-bin/timer.pl'); ix = [findstr(s,'<BR>'), length(s)+1]; for k = 2:length(ix) tok = s(ix(k-1)+4:ix(k)-1); if findstr(tok,'UTC') disp(tok); end; end;
http://rosettacode.org/wiki/Word_frequency
Word frequency
Task Given a text file and an integer   n,   print/display the   n   most common words in the file   (and the number of their occurrences)   in decreasing frequency. For the purposes of this task:   A word is a sequence of one or more contiguous letters.   You are free to define what a   letter   is.   Undersc...
#Nim
Nim
import tables, strutils, sequtils, httpclient   proc take[T](s: openArray[T], n: int): seq[T] = s[0 ..< min(n, s.len)]   var client = newHttpClient() var text = client.getContent("https://www.gutenberg.org/files/135/135-0.txt")   var wordFrequencies = text.toLowerAscii.splitWhitespace.toCountTable wordFrequencies.sort ...
http://rosettacode.org/wiki/Wireworld
Wireworld
Wireworld Conway's Game of Life It is capable of doing sophisticated computations with appropriate programs (it is actually Turing complete), and is much simpler to program for. A Wireworld arena consists of a Cartesian grid of cells, each of which can be in one of four states. All cell transitions happen simultaneous...
#PHP
PHP
  $desc = 'tH......... . . ........ . . Ht.. ......   .. tH.... ....... ..   .. tH..... ...... ..';   $steps = 30;   //fill in the world with the cells $world = array(array()); $row = 0; $col = 0; foreach(str_split($desc) as $i){ switch($i){ case "\n": $row++; ...
http://rosettacode.org/wiki/Window_creation
Window creation
Display a GUI window. The window need not have any contents, but should respond to requests to be closed.
#Rust
Rust
use winit::event::{Event, WindowEvent}; // winit 0.24 use winit::event_loop::{ControlFlow, EventLoop}; use winit::window::WindowBuilder;   fn main() { let event_loop = EventLoop::new(); let _win = WindowBuilder::new() .with_title("Window") .build(&event_loop).unwrap();   event_loop.run(move...
http://rosettacode.org/wiki/Window_creation
Window creation
Display a GUI window. The window need not have any contents, but should respond to requests to be closed.
#Scala
Scala
import javax.swing.JFrame   object ShowWindow{ def main(args: Array[String]){ var jf = new JFrame("Hello!")   jf.setSize(800, 600) jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE) jf.setVisible(true) } }
http://rosettacode.org/wiki/Window_creation
Window creation
Display a GUI window. The window need not have any contents, but should respond to requests to be closed.
#Scheme
Scheme
  #!r6rs   ;; PS-TK example: display simple frame   (import (rnrs) (lib pstk main) ; change this to refer to your installation of PS/Tk )   (define tk (tk-start)) (tk/wm 'title tk "PS-Tk Example: Frame")   (tk-event-loop tk)  
http://rosettacode.org/wiki/Word_wrap
Word wrap
Even today, with proportional fonts and complex layouts, there are still cases where you need to wrap text at a specified column. Basic task The basic task is to wrap a paragraph of text in a simple way in your language. If there is a way to do this that is built-in, trivial, or provided in a standard library, sho...
#Perl
Perl
my $s = "In olden times when wishing still helped one, there lived a king whose daughters were all beautiful, but the youngest was so beautiful that the sun itself, which has seen so much, was astonished whenever it shone in her face. Close-by-the-king's-castle-lay-a-great-dark forest, and under an old lime-tree in th...
http://rosettacode.org/wiki/XML/Input
XML/Input
Given the following XML fragment, extract the list of student names using whatever means desired. If the only viable method is to use XPath, refer the reader to the task XML and XPath. <Students> <Student Name="April" Gender="F" DateOfBirth="1989-01-02" /> <Student Name="Bob" Gender="M" DateOfBirth="1990-03-04" /...
#Rust
Rust
extern crate xml; // provided by the xml-rs crate use xml::{name::OwnedName, reader::EventReader, reader::XmlEvent};   const DOCUMENT: &str = r#" <Students> <Student Name="April" Gender="F" DateOfBirth="1989-01-02" /> <Student Name="Bob" Gender="M" DateOfBirth="1990-03-04" /> <Student Name="Chad" Gender="M" Dat...
http://rosettacode.org/wiki/XML/Input
XML/Input
Given the following XML fragment, extract the list of student names using whatever means desired. If the only viable method is to use XPath, refer the reader to the task XML and XPath. <Students> <Student Name="April" Gender="F" DateOfBirth="1989-01-02" /> <Student Name="Bob" Gender="M" DateOfBirth="1990-03-04" /...
#Scala
Scala
val students = <Students> <Student Name="April" Gender="F" DateOfBirth="1989-01-02" /> <Student Name="Bob" Gender="M" DateOfBirth="1990-03-04" /> <Student Name="Chad" Gender="M" DateOfBirth="1991-05-06" /> <Student Name="Dave" Gender="M" DateOfBirth="1992-07-08"> <Pet Type="dog" Name="Rover" ...
http://rosettacode.org/wiki/100_doors
100 doors
There are 100 doors in a row that are all initially closed. You make 100 passes by the doors. The first time through, visit every door and  toggle  the door  (if the door is closed,  open it;   if it is open,  close it). The second time, only visit every 2nd door   (door #2, #4, #6, ...),   and toggle it. The third...
#PHP
PHP
<?php for ($i = 1; $i <= 100; $i++) { $root = sqrt($i); $state = ($root == ceil($root)) ? 'open' : 'closed'; echo "Door {$i}: {$state}\n"; } ?>
http://rosettacode.org/wiki/Web_scraping
Web scraping
Task Create a program that downloads the time from this URL:   http://tycho.usno.navy.mil/cgi-bin/timer.pl   and then prints the current UTC time by extracting just the UTC time from the web page's HTML. Alternatively, if the above url is not working, grab the first date/time off this page's talk page. If possible,...
#Microsoft_Small_Basic
Microsoft Small Basic
  'Entered by AykayayCiti -- Earl L. Montgomery url_name = "http://tycho.usno.navy.mil/cgi-bin/timer.pl" url_data = Network.GetWebPageContents(url_name) find = "UTC" ' the length from the UTC to the time is -18 so we need ' to subtract from the UTC position pos = Text.GetIndexOf(url_data,find)-18 result = Text.GetSubT...
http://rosettacode.org/wiki/Web_scraping
Web scraping
Task Create a program that downloads the time from this URL:   http://tycho.usno.navy.mil/cgi-bin/timer.pl   and then prints the current UTC time by extracting just the UTC time from the web page's HTML. Alternatively, if the above url is not working, grab the first date/time off this page's talk page. If possible,...
#mIRC_Scripting_Language
mIRC Scripting Language
alias utc { sockclose UTC sockopen UTC tycho.usno.navy.mil 80 }   on *:SOCKOPEN:UTC: { sockwrite -n UTC GET /cgi-bin/timer.pl HTTP/1.1 sockwrite -n UTC Host: tycho.usno.navy.mil sockwrite UTC $crlf }   on *:SOCKREAD:UTC: { sockread %UTC while ($sockbr) { if (<BR>*Universal Time iswm %UTC) { echo...
http://rosettacode.org/wiki/Word_frequency
Word frequency
Task Given a text file and an integer   n,   print/display the   n   most common words in the file   (and the number of their occurrences)   in decreasing frequency. For the purposes of this task:   A word is a sequence of one or more contiguous letters.   You are free to define what a   letter   is.   Undersc...
#Objeck
Objeck
use System.IO.File; use Collection; use RegEx;   class Rosetta { function : Main(args : String[]) ~ Nil { if(args->Size() <> 1) { return; };   input := FileReader->ReadFile(args[0]); filter := RegEx->New("\\w+"); words := filter->Find(input);   word_counts := StringMap->New(); each(i...
http://rosettacode.org/wiki/Wireworld
Wireworld
Wireworld Conway's Game of Life It is capable of doing sophisticated computations with appropriate programs (it is actually Turing complete), and is much simpler to program for. A Wireworld arena consists of a Cartesian grid of cells, each of which can be in one of four states. All cell transitions happen simultaneous...
#PicoLisp
PicoLisp
(load "@lib/simul.l")   (let (Data (in "wire.data" (make (while (line) (link @)))) Grid (grid (length (car Data)) (length Data)) ) (mapc '((G D) (mapc put G '(val .) D)) Grid (apply mapcar (flip Data) list) ) (loop (disp Grid T '((This) (pack " " (: val) " ")) ) (wa...
http://rosettacode.org/wiki/Wireworld
Wireworld
Wireworld Conway's Game of Life It is capable of doing sophisticated computations with appropriate programs (it is actually Turing complete), and is much simpler to program for. A Wireworld arena consists of a Cartesian grid of cells, each of which can be in one of four states. All cell transitions happen simultaneous...
#PureBasic
PureBasic
Enumeration #Empty #Electron_head #Electron_tail #Conductor EndEnumeration   #Delay=100 #XSize=23 #YSize=12   Procedure Limit(n, min, max) If n<min n=min ElseIf n>max n=max EndIf ProcedureReturn n EndProcedure   Procedure Moore_neighborhood(Array World(2),x,y) Protected cnt=0, i, j ...
http://rosettacode.org/wiki/Window_creation
Window creation
Display a GUI window. The window need not have any contents, but should respond to requests to be closed.
#Seed7
Seed7
$ include "seed7_05.s7i"; include "draw.s7i"; include "keybd.s7i";   const proc: main is func begin screen(200, 200); KEYBOARD := GRAPH_KEYBOARD; ignore(getc(KEYBOARD)); end func;
http://rosettacode.org/wiki/Window_creation
Window creation
Display a GUI window. The window need not have any contents, but should respond to requests to be closed.
#Sidef
Sidef
var tk = require('Tk'); %s'MainWindow'.new; tk.MainLoop;
http://rosettacode.org/wiki/Window_creation
Window creation
Display a GUI window. The window need not have any contents, but should respond to requests to be closed.
#Smalltalk
Smalltalk
SystemWindow new openInWorld.
http://rosettacode.org/wiki/Word_wrap
Word wrap
Even today, with proportional fonts and complex layouts, there are still cases where you need to wrap text at a specified column. Basic task The basic task is to wrap a paragraph of text in a simple way in your language. If there is a way to do this that is built-in, trivial, or provided in a standard library, sho...
#Phix
Phix
string s = substitute("""In olden times when wishing still helped one, there lived a king whose daughters were all beautiful, but the youngest was so beautiful that the sun itself, which has seen so much, was astonished whenever it shone in her face. Close by the king's castle lay a great dark forest, and under an old ...
http://rosettacode.org/wiki/XML/Input
XML/Input
Given the following XML fragment, extract the list of student names using whatever means desired. If the only viable method is to use XPath, refer the reader to the task XML and XPath. <Students> <Student Name="April" Gender="F" DateOfBirth="1989-01-02" /> <Student Name="Bob" Gender="M" DateOfBirth="1990-03-04" /...
#Sidef
Sidef
require('XML::Simple');   var ref = %S'XML::Simple'.XMLin('<Students> <Student Name="April" Gender="F" DateOfBirth="1989-01-02" /> <Student Name="Bob" Gender="M" DateOfBirth="1990-03-04" /> <Student Name="Chad" Gender="M" DateOfBirth="1991-05-06" /> <Student Name="Dave" Gender="M" DateOfBirth="1992-07-08"> ...
http://rosettacode.org/wiki/100_doors
100 doors
There are 100 doors in a row that are all initially closed. You make 100 passes by the doors. The first time through, visit every door and  toggle  the door  (if the door is closed,  open it;   if it is open,  close it). The second time, only visit every 2nd door   (door #2, #4, #6, ...),   and toggle it. The third...
#Picat
Picat
doors(N) => Doors = new_array(N), foreach(I in 1..N) Doors[I] := 0 end, foreach(I in 1..N) foreach(J in I..I..N) Doors[J] := 1^Doors[J] end, if N <= 10 then print_open(Doors) end end, println(Doors), print_open(Doors), nl.   print_open(Doors) => println([I : I i...
http://rosettacode.org/wiki/Web_scraping
Web scraping
Task Create a program that downloads the time from this URL:   http://tycho.usno.navy.mil/cgi-bin/timer.pl   and then prints the current UTC time by extracting just the UTC time from the web page's HTML. Alternatively, if the above url is not working, grab the first date/time off this page's talk page. If possible,...
#NetRexx
NetRexx
/* NetRexx */ options replace format comments java crossref symbols binary   parse arg full_short . if 'FULL'.abbrev(full_short.upper(), 1) then dateFull = isTrue() else dateFull = isFalse() do timeURL = java.net.URL('http://tycho.usno.navy.mil/cgi-bin/timer.pl') conn = timeURL.openConnection() ibr = Buffered...
http://rosettacode.org/wiki/Word_frequency
Word frequency
Task Given a text file and an integer   n,   print/display the   n   most common words in the file   (and the number of their occurrences)   in decreasing frequency. For the purposes of this task:   A word is a sequence of one or more contiguous letters.   You are free to define what a   letter   is.   Undersc...
#OCaml
OCaml
let () = let n = try int_of_string Sys.argv.(1) with _ -> 10 in let ic = open_in "135-0.txt" in let h = Hashtbl.create 97 in let w = Str.regexp "[^A-Za-zéèàêâôîûœ]+" in try while true do let line = input_line ic in let words = Str.split w line in List.iter (fun word -> ...
http://rosettacode.org/wiki/Wireworld
Wireworld
Wireworld Conway's Game of Life It is capable of doing sophisticated computations with appropriate programs (it is actually Turing complete), and is much simpler to program for. A Wireworld arena consists of a Cartesian grid of cells, each of which can be in one of four states. All cell transitions happen simultaneous...
#Python
Python
''' Wireworld implementation. '''   from io import StringIO from collections import namedtuple from pprint import pprint as pp import copy   WW = namedtuple('WW', 'world, w, h') head, tail, conductor, empty = allstates = 'Ht. '     infile = StringIO('''\ tH......... . . ... . . Ht.. ......\ ''')   def readfile(f...
http://rosettacode.org/wiki/Window_creation
Window creation
Display a GUI window. The window need not have any contents, but should respond to requests to be closed.
#Standard_ML
Standard ML
  open XWindows ; open Motif ;   val showWindow = fn () =>   let val shell = XtAppInitialise "" "demo" "top" [] [XmNwidth 400, XmNheight 300 ] ; val main = XmCreateMainWindow shell "main" [XmNmappedWhenManaged true ] ; val buttn = XmCreateDrawnButton main "stop" [ XmNlabelString "Exit"] ; val quit = fn...
http://rosettacode.org/wiki/Window_creation
Window creation
Display a GUI window. The window need not have any contents, but should respond to requests to be closed.
#Tcl
Tcl
package require Tk
http://rosettacode.org/wiki/Window_creation
Window creation
Display a GUI window. The window need not have any contents, but should respond to requests to be closed.
#TI-89_BASIC
TI-89 BASIC
:Text "Rosetta Code"
http://rosettacode.org/wiki/Word_wrap
Word wrap
Even today, with proportional fonts and complex layouts, there are still cases where you need to wrap text at a specified column. Basic task The basic task is to wrap a paragraph of text in a simple way in your language. If there is a way to do this that is built-in, trivial, or provided in a standard library, sho...
#Phixmonti
Phixmonti
include ..\Utilitys.pmt   72 var long 0 >ps   "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Maecenas varius sapien vel purus hendrerit vehicula. Integer hendrerit viverra turpis, ac sagittis arcu pharetra id. Sed dapibus enim non dui posuere sit amet rhoncus tellus consectetur. Proin blandit lacus vitae nib...
http://rosettacode.org/wiki/Word_wrap
Word wrap
Even today, with proportional fonts and complex layouts, there are still cases where you need to wrap text at a specified column. Basic task The basic task is to wrap a paragraph of text in a simple way in your language. If there is a way to do this that is built-in, trivial, or provided in a standard library, sho...
#PHP
PHP
<?php   $text = <<<ENDTXT If there's anything you need All you have to do is say You know you satisfy everything in me We shouldn't waste a single day   So don't stop me falling It's destiny calling A power I just can't deny It's never changing Can't you hear me, I'm saying I want you for the rest of my life   Together...
http://rosettacode.org/wiki/XML/Input
XML/Input
Given the following XML fragment, extract the list of student names using whatever means desired. If the only viable method is to use XPath, refer the reader to the task XML and XPath. <Students> <Student Name="April" Gender="F" DateOfBirth="1989-01-02" /> <Student Name="Bob" Gender="M" DateOfBirth="1990-03-04" /...
#Slate
Slate
slate[1]> [ |tree|   tree: (Xml SimpleParser newOn: '<Students> <Student Name="April" Gender="F" DateOfBirth="1989-01-02" /> <Student Name="Bob" Gender="M" DateOfBirth="1990-03-04" /> <Student Name="Chad" Gender="M" DateOfBirth="1991-05-06" /> <Student Name="Dave" Gender="M" DateOfBirth="1992-07-08...
http://rosettacode.org/wiki/100_doors
100 doors
There are 100 doors in a row that are all initially closed. You make 100 passes by the doors. The first time through, visit every door and  toggle  the door  (if the door is closed,  open it;   if it is open,  close it). The second time, only visit every 2nd door   (door #2, #4, #6, ...),   and toggle it. The third...
#PicoLisp
PicoLisp
(let Doors (need 100) (for I 100 (for (D (nth Doors I) D (cdr (nth D I))) (set D (not (car D))) ) ) (println Doors) )
http://rosettacode.org/wiki/Web_scraping
Web scraping
Task Create a program that downloads the time from this URL:   http://tycho.usno.navy.mil/cgi-bin/timer.pl   and then prints the current UTC time by extracting just the UTC time from the web page's HTML. Alternatively, if the above url is not working, grab the first date/time off this page's talk page. If possible,...
#Nim
Nim
import httpclient, strutils   var client = newHttpClient()   var res: string for line in client.getContent("https://rosettacode.org/wiki/Talk:Web_scraping").splitLines: let k = line.find("UTC") if k >= 0: res = line[0..(k - 3)] let k = res.rfind("</a>") res = res[(k + 6)..^1] break echo if res.len >...
http://rosettacode.org/wiki/Web_scraping
Web scraping
Task Create a program that downloads the time from this URL:   http://tycho.usno.navy.mil/cgi-bin/timer.pl   and then prints the current UTC time by extracting just the UTC time from the web page's HTML. Alternatively, if the above url is not working, grab the first date/time off this page's talk page. If possible,...
#Objeck
Objeck
  use Net; use IO; use Structure;   bundle Default { class Scrape { function : Main(args : String[]) ~ Nil { client := HttpClient->New(); lines := client->Get("http://tycho.usno.navy.mil/cgi-bin/timer.pl", 80);   i := 0; found := false; while(found <> true & i < lines->Size()) { ...
http://rosettacode.org/wiki/Word_frequency
Word frequency
Task Given a text file and an integer   n,   print/display the   n   most common words in the file   (and the number of their occurrences)   in decreasing frequency. For the purposes of this task:   A word is a sequence of one or more contiguous letters.   You are free to define what a   letter   is.   Undersc...
#Perl
Perl
$top = 10;   open $fh, "<", '135-0.txt'; ($text = join '', <$fh>) =~ tr/A-Z/a-z/ or die "Can't open '135-0.txt': $!\n";   @matcher = ( qr/[a-z]+/, # simple 7-bit ASCII qr/\w+/, # word characters with underscore qr/[a-z0-9]+/, # word characters without underscore );   for $reg (@matcher) { ...
http://rosettacode.org/wiki/Wireworld
Wireworld
Wireworld Conway's Game of Life It is capable of doing sophisticated computations with appropriate programs (it is actually Turing complete), and is much simpler to program for. A Wireworld arena consists of a Cartesian grid of cells, each of which can be in one of four states. All cell transitions happen simultaneous...
#Racket
Racket
  #lang racket (require 2htdp/universe) (require 2htdp/image) (require racket/fixnum)   ; see the forest fire task, from which this is derived... (define-struct wire-world (width height cells) #:prefab)   (define state:_ 0) (define state:. 1) (define state:H 2) (define state:t 3)   (define (char->state c) (case c ...
http://rosettacode.org/wiki/Window_creation
Window creation
Display a GUI window. The window need not have any contents, but should respond to requests to be closed.
#Toka
Toka
needs sdl 800 600 sdl_setup
http://rosettacode.org/wiki/Window_creation
Window creation
Display a GUI window. The window need not have any contents, but should respond to requests to be closed.
#TorqueScript
TorqueScript
  new GuiControl(GuiName) { profile = "GuiDefaultProfile"; horizSizing = "right"; vertSizing = "bottom"; position = "0 0"; extent = "640 480"; minExtent = "8 2"; enabled = 1; visible = 1; clipToParent = 1;   new GuiWindowCtrl() { profile = "GuiWindowProfile"; horizSizing = "right"; vertSizing = "bottom...
http://rosettacode.org/wiki/Window_creation
Window creation
Display a GUI window. The window need not have any contents, but should respond to requests to be closed.
#TXR
TXR
(defvarl SDL_INIT_VIDEO #x00000020) (defvarl SDL_SWSURFACE #x00000000) (defvarl SDL_HWPALETTE #x20000000)   (typedef SDL_Surface (cptr SDL_Surface))   (typedef SDL_EventType (enumed uint8 SDL_EventType (SDL_KEYUP 3) (SDL_QUIT 12)))   (typedef SDL_Event (union SD_Event...